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 ce4ba27..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/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' ); -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( '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 ( 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( '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 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( '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 b66a8e5..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/string-format": "^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(); -});