diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743ff..00000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f302863..00000000 --- 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 1c88e69c..00000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 19409124..00000000 --- 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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fed..00000000 --- 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 b5291db6..00000000 --- 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 12efb650..00000000 --- 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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 29849010..00000000 --- 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 45847307..00000000 --- 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: '9 21 * * 3' - - # 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 f4575e92..00000000 --- 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 + + + + diff --git a/take/README.md b/take/README.md deleted file mode 100644 index dcf22b2a..00000000 --- a/take/README.md +++ /dev/null @@ -1,155 +0,0 @@ - - -# take - -> Take elements from an array. - -
- -## Usage - -```javascript -var take = require( '@stdlib/array/take' ); -``` - -#### take( x, indices\[, options] ) - -Takes elements from an array. - -```javascript -var x = [ 1, 2, 3, 4 ]; - -var y = take( x, [ 1, 3 ] ); -// returns [ 2, 4 ] -``` - -The function supports the following parameters: - -- **x**: input array. -- **indices**: list of indices. -- **options**: function options. - -The function supports the following options: - -- **mode**: index [mode][@stdlib/ndarray/base/ind]. Default: `'normalize'`. - -By default, the function normalizes negative integer indices to positive integer index equivalents. - -```javascript -var x = [ 1, 2, 3, 4 ]; - -var y = take( x, [ -3, -1 ] ); -// returns [ 2, 4 ] -``` - -To specify an alternative index [mode][@stdlib/ndarray/base/ind], provide a `mode` option. - -```javascript -var x = [ 1, 2, 3, 4 ]; - -var y = take( x, [ -10, 10 ], { - 'mode': 'clamp' -}); -// returns [ 1, 4 ] -``` - -
- - - -
- -## Notes - -- If `indices` is an empty array, the function returns an empty array. - - ```javascript - var x = [ 1, 2, 3, 4 ]; - - var y = take( x, [] ); - // returns [] - ``` - -- If provided an input array having a recognized [data type][@stdlib/array/dtypes], the function returns an array having the same [data type][@stdlib/array/dtypes] as the input array. Otherwise, the function **always** returns a "generic" array. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var linspace = require( '@stdlib/array/linspace' ); -var take = require( '@stdlib/array/take' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var indices = discreteUniform( 10, 0, x.length-1 ); -console.log( indices ); - -// Take a random sample of elements from `x`: -var y = take( x, indices ); -console.log( y ); -``` - -
- - - - - - - - - - - - - - diff --git a/take/benchmark/benchmark.js b/take/benchmark/benchmark.js deleted file mode 100644 index 8975c75d..00000000 --- a/take/benchmark/benchmark.js +++ /dev/null @@ -1,52 +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' ); -var isArray = require( '@stdlib/assert/is-array' ); -var zeroTo = require( './../../base/zero-to' ); -var pkg = require( './../package.json' ).name; -var take = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::copy:len=100', function benchmark( b ) { - var x; - var i; - var v; - - x = zeroTo( 100 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = take( x, x ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/take/benchmark/benchmark.length.js b/take/benchmark/benchmark.length.js deleted file mode 100644 index f81872fd..00000000 --- a/take/benchmark/benchmark.length.js +++ /dev/null @@ -1,98 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var take = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var idx = discreteUniform( len, 0, 3 ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var x; - var v; - var i; - - x = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = take( x, idx ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/take/docs/repl.txt b/take/docs/repl.txt deleted file mode 100644 index eb4e87aa..00000000 --- a/take/docs/repl.txt +++ /dev/null @@ -1,40 +0,0 @@ - -{{alias}}( x, indices[, options] ) - Takes elements from an array. - - If `indices` is an empty array, the function returns an empty array. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - indices: ArrayLikeObject - List of element indices. - - options: Object (optional) - Function options. - - options.mode: string (optional) - Specifies how to handle an index outside the interval [0, max], where - `max` is the maximum possible array index. If equal to 'throw', the - function throws an error. If equal to 'normalize', the function throws - an error if provided an out-of-bounds normalized index. If equal to - 'wrap', the function wraps around an index using modulo arithmetic. If - equal to 'clamp', the function sets an index to either 0 (minimum index) - or the maximum index. Default: 'normalize'. - - Returns - ------- - out: Array|TypedArray - Output array. - - Examples - -------- - > var x = [ 1, 2, 3, 4 ]; - > var y = {{alias}}( x, [ 1, 3 ] ) - [ 2, 4 ] - - See Also - -------- - diff --git a/take/docs/types/index.d.ts b/take/docs/types/index.d.ts deleted file mode 100644 index fcf1547f..00000000 --- a/take/docs/types/index.d.ts +++ /dev/null @@ -1,247 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, AccessorArrayLike, Complex128Array, Complex64Array } from '@stdlib/types/array'; -import { Mode } from '@stdlib/types/ndarray'; - -/** -* Index array. -*/ -type IndexArray = Collection | AccessorArrayLike; - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Index mode. - */ - mode?: Mode; -} - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'float64' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2.0, 4.0 ] -*/ -declare function take( x: Float64Array, indices: IndexArray, options?: Options ): Float64Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'float32' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2.0, 4.0 ] -*/ -declare function take( x: Float32Array, indices: IndexArray, options?: Options ): Float32Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'int32' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Int32Array, indices: IndexArray, options?: Options ): Int32Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'int16' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Int16Array, indices: IndexArray, options?: Options ): Int16Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'int8' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Int8Array, indices: IndexArray, options?: Options ): Int8Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'uint32' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Uint32Array, indices: IndexArray, options?: Options ): Uint32Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'uint16' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Uint16Array, indices: IndexArray, options?: Options ): Uint16Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'uint8' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Uint8Array, indices: IndexArray, options?: Options ): Uint8Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'uint8c' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Uint8ClampedArray, indices: IndexArray, options?: Options ): Uint8ClampedArray; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'complex128' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2.0, 0.0, 4.0, 0.0 ] -*/ -declare function take( x: Complex128Array, indices: IndexArray, options?: Options ): Complex128Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var x = zeroTo( 4, 'complex64' ); -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2.0, 0.0, 4.0, 0.0 ] -*/ -declare function take( x: Complex64Array, indices: IndexArray, options?: Options ): Complex64Array; - -/** -* Takes elements from an array. -* -* @param x - input array -* @param indices - list of element indices -* @param options - function options -* @returns output array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var y = take( x, [ 1, 3 ] ); -* // returns [ 2, 4 ] -*/ -declare function take( x: Collection | AccessorArrayLike, indices: IndexArray, options?: Options ): Array; - - -// EXPORTS // - -export = take; diff --git a/take/docs/types/test.ts b/take/docs/types/test.ts deleted file mode 100644 index 0fe1ea80..00000000 --- a/take/docs/types/test.ts +++ /dev/null @@ -1,94 +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. -*/ - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); -import take = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - take( [ 1, 2, 3, 4 ], [ 1, 3 ] ); // $ExpectType number[] - take( [ 1, 2, 3, 4 ], [ 1, 3 ] ); // $ExpectType any[] - take( [ 1, 2, 3, 4 ], [ 1, 3 ] ); // $ExpectType number[] - take( [ '1', '2', '3', '4' ], [ 1, 3 ] ); // $ExpectType string[] - - take( new Float64Array( 10 ), [ 1, 3 ] ); // $ExpectType Float64Array - take( new Float32Array( 10 ), [ 1, 3 ] ); // $ExpectType Float32Array - take( new Int32Array( 10 ), [ 1, 3 ] ); // $ExpectType Int32Array - take( new Int16Array( 10 ), [ 1, 3 ] ); // $ExpectType Int16Array - take( new Int8Array( 10 ), [ 1, 3 ] ); // $ExpectType Int8Array - take( new Uint32Array( 10 ), [ 1, 3 ] ); // $ExpectType Uint32Array - take( new Uint16Array( 10 ), [ 1, 3 ] ); // $ExpectType Uint16Array - take( new Uint8Array( 10 ), [ 1, 3 ] ); // $ExpectType Uint8Array - take( new Uint8ClampedArray( 10 ), [ 1, 3 ] ); // $ExpectType Uint8ClampedArray - take( new Complex128Array( 10 ), [ 1, 3 ] ); // $ExpectType Complex128Array - take( new Complex64Array( 10 ), [ 1, 3 ] ); // $ExpectType Complex64Array -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object... -{ - take( 1, [ 1, 3 ] ); // $ExpectError - take( true, [ 1, 3 ] ); // $ExpectError - take( false, [ 1, 3 ] ); // $ExpectError - take( null, [ 1, 3 ] ); // $ExpectError - take( void 0, [ 1, 3 ] ); // $ExpectError - take( {}, [ 1, 3 ] ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - take( [], 1 ); // $ExpectError - take( [], true ); // $ExpectError - take( [], false ); // $ExpectError - take( [], null ); // $ExpectError - take( [], void 0 ); // $ExpectError - take( [], {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - take( [], [ 1, 3 ], '1' ); // $ExpectError - take( [], [ 1, 3 ], 1 ); // $ExpectError - take( [], [ 1, 3 ], true ); // $ExpectError - take( [], [ 1, 3 ], false ); // $ExpectError - take( [], [ 1, 3 ], null ); // $ExpectError - take( [], [ 1, 3 ], [] ); // $ExpectError - take( [], [ 1, 3 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a valid index mode... -{ - take( [], [ 1, 3 ], { 'mode': '1' } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': 1 } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': true } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': false } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': null } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': {} } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': [] } ); // $ExpectError - take( [], [ 1, 3 ], { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - take(); // $ExpectError - take( [] ); // $ExpectError - take( [], [], {}, {} ); // $ExpectError -} diff --git a/take/examples/index.js b/take/examples/index.js deleted file mode 100644 index 49fd565a..00000000 --- a/take/examples/index.js +++ /dev/null @@ -1,35 +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'; - -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var linspace = require( './../../linspace' ); -var take = require( './../lib' ); - -// Generate a linearly spaced array: -var x = linspace( 0, 100, 11 ); -console.log( x ); - -// Generate an array of random indices: -var indices = discreteUniform( 10, 0, x.length-1 ); -console.log( indices ); - -// Take a random sample of elements from `x`: -var y = take( x, indices ); -console.log( y ); diff --git a/take/lib/defaults.js b/take/lib/defaults.js deleted file mode 100644 index ea262044..00000000 --- a/take/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'mode': 'normalize' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/take/lib/index.js b/take/lib/index.js deleted file mode 100644 index ae09036b..00000000 --- a/take/lib/index.js +++ /dev/null @@ -1,43 +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'; - -/** -* Take elements from an array. -* -* @module @stdlib/array/take -* -* @example -* var take = require( '@stdlib/array/take' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var indices = [ 0, 0, 1, 1, 3, 3 ]; -* var y = take( x, indices ); -* // returns [ 1, 1, 2, 2, 4, 4 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/take/lib/main.js b/take/lib/main.js deleted file mode 100644 index 0ebfff78..00000000 --- a/take/lib/main.js +++ /dev/null @@ -1,81 +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 isCollection = require( '@stdlib/assert/is-collection' ); -var base = require( './../../base/take' ); -var zeros = require( './../../zeros' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Takes elements from an array. -* -* @param {Collection} x - input array -* @param {IntegerArray} indices - list of indices -* @param {Options} [options] - function options -* @param {string} [options.mode='normalize'] - index mode -* @throws {TypeError} first argument must be a collection -* @throws {TypeError} second argument must be a collection -* @throws {TypeError} options argument must be an object -* @throws {Error} must provide valid options -* @returns {Collection} output array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* var indices = [ 3, 1, 2, 0 ]; -* -* var y = take( x, indices ); -* // returns [ 4, 2, 3, 1 ] -*/ -function take( x, indices ) { - var opts; - var err; - var dt; - if ( !isCollection( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); - } - if ( !isCollection( indices ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', indices ) ); - } - opts = defaults(); - if ( arguments.length > 2 ) { - err = validate( opts, arguments[ 2 ] ); - if ( err ) { - throw err; - } - } - dt = dtype( x ); - if ( dt === 'generic' || dt === null ) { - return base( x, indices, opts.mode ); - } - return base.assign( x, indices, opts.mode, zeros( indices.length, dt ), 1, 0 ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = take; diff --git a/take/lib/validate.js b/take/lib/validate.js deleted file mode 100644 index 24e7153e..00000000 --- a/take/lib/validate.js +++ /dev/null @@ -1,67 +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 isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isIndexMode = require( '@stdlib/ndarray/base/assert/is-index-mode' ); -var modes = require( '@stdlib/ndarray/index-modes' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {string} [options.mode] - index mode -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'normalize' -* }; -* 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, 'mode' ) ) { - opts.mode = options.mode; - if ( !isIndexMode( opts.mode ) ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'mode', modes().join( '", "' ), opts.mode ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/take/package.json b/take/package.json deleted file mode 100644 index 208f4f03..00000000 --- a/take/package.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "name": "@stdlib/array/take", - "version": "0.0.0", - "description": "Take elements from an array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "utilities", - "utils", - "generic", - "array", - "take", - "extract", - "copy", - "index" - ] -} diff --git a/take/test/test.js b/take/test/test.js deleted file mode 100644 index 0c6e453c..00000000 --- a/take/test/test.js +++ /dev/null @@ -1,419 +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 tape = require( 'tape' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var isArray = require( '@stdlib/assert/is-array' ); -var take = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof take, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not a collection', 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() { - take( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a collection (options)', 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() { - take( value, [], {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a collection', 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() { - take( [], value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a collection (options)', 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() { - take( [], value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', 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() { - take( [], [], value ); - }; - } -}); - -tape( 'the function throws an error if provided a `mode` option which is not a valid index mode', 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() { - take( [], [], { - 'mode': value - }); - }; - } -}); - -tape( 'the function takes elements from an array (generic)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ 1, 3 ]; - actual = take( x, indices ); - - expected = [ 2, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 1, 1, 3, 3 ]; - actual = take( x, indices ); - - expected = [ 2, 2, 4, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 3, 2, 1, 0 ]; - actual = take( x, indices ); - - expected = [ 4, 3, 2, 1 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]; - actual = take( x, indices ); - - expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function takes elements from an array (accessor)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = toAccessorArray( [ 1, 2, 3, 4 ] ); - - indices = toAccessorArray( [ 1, 3 ] ); - actual = take( x, indices ); - - expected = [ 2, 4 ]; - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = toAccessorArray( [ 1, 1, 3, 3 ] ); - actual = take( x, indices ); - - expected = [ 2, 2, 4, 4 ]; - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = toAccessorArray( [ 3, 2, 1, 0 ] ); - actual = take( x, indices ); - - expected = [ 4, 3, 2, 1 ]; - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - indices = toAccessorArray( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); - actual = take( x, indices ); - - expected = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; - t.strictEqual( isArray( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function takes elements from an array (complex typed)', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - indices = toAccessorArray( [ 1, 1, 3 ] ); - actual = take( x, indices ); - - expected = new Complex64Array( [ 3.0, 4.0, 3.0, 4.0, 7.0, 8.0 ] ); - t.notEqual( actual, x, 'returns different reference' ); - t.strictEqual( isSameComplex64Array( actual, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array if provided a second argument which is empty', function test( t ) { - var x = [ 1, 2, 3, 4 ]; - t.deepEqual( take( x, [] ), [], 'returns expected value' ); - t.end(); -}); - -tape( 'by default, the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = take( x, indices ); - expected = [ 4, 3, 2, 1 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - take( x, indices ); - } -}); - -tape( 'when the "mode" is "throw", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 4, 5, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - take( x, indices, { - 'mode': 'throw' - }); - } -}); - -tape( 'when the "mode" is "normalize", the function normalizes negative indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -1, -2, -3, -4 ]; - actual = take( x, indices, { - 'mode': 'normalize' - }); - expected = [ 4, 3, 2, 1 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "normalize", the function throws an error if provided an out-of-bounds index', function test( t ) { - var indices; - var x; - - x = [ 1, 2, 3, 4 ]; - indices = [ 2, 50, 1, 2 ]; - - t.throws( badValue, RangeError, 'throws an error' ); - t.end(); - - function badValue() { - take( x, indices, { - 'mode': 'normalize' - }); - } -}); - -tape( 'when the "mode" is "clamp", the function clamps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = take( x, indices, { - 'mode': 'clamp' - }); - expected = [ 1, 4, 1, 4 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when the "mode" is "wrap", the function wraps out-of-bounds indices', function test( t ) { - var expected; - var indices; - var actual; - var x; - - x = [ 1, 2, 3, 4 ]; - - indices = [ -10, 10, -5, 5 ]; - actual = take( x, indices, { - 'mode': 'wrap' - }); - expected = [ 3, 3, 4, 2 ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/take/test/test.validate.js b/take/test/test.validate.js deleted file mode 100644 index 5001a5e6..00000000 --- a/take/test/test.validate.js +++ /dev/null @@ -1,128 +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 tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `mode` option which is not a valid index mode', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'mode': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'mode': 'throw' - }; - opts = {}; - - expected = { - 'mode': 'throw' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 57cb5649..00000000 --- a/test/test.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var ns = require( './../lib' ); - - -// TESTS // - -tape( 'main export is an object', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ns, 'object', 'main export is an object' ); - t.end(); -}); - -tape( 'the exported object contains key-value pairs', function test( t ) { - var keys = objectKeys( ns ); - t.equal( keys.length > 0, true, 'has keys' ); - t.end(); -}); diff --git a/to-circular-iterator/README.md b/to-circular-iterator/README.md deleted file mode 100644 index b0131424..00000000 --- a/to-circular-iterator/README.md +++ /dev/null @@ -1,324 +0,0 @@ - - -# circarray2iterator - -> Create an iterator which repeatedly iterates over the elements of an array-like object. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var circarray2iterator = require( '@stdlib/array/to-circular-iterator' ); -``` - -#### circarray2iterator( src\[, options]\[, mapFcn\[, thisArg]] ) - -Returns an iterator which repeatedly iterates over each element in an array-like `object`. - -```javascript -var it = circarray2iterator( [ 1, 2, 3, 4 ] ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 4 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -The function accepts the following `options`: - -- **iter**: number of iterations. Default: `1e308`. -- **dir**: iteration direction. If set to `-1`, the iterator iterates over elements from right-to-left. Default: `1`. - -To limit the number of iterations, set the `iter` option. - -```javascript -var opts = { - 'iter': 5 -}; -var it = circarray2iterator( [ 1, 2, 3, 4 ], opts ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - -To iterate over elements from right to left, set the `dir` option to `-1`. - -```javascript -var opts = { - 'dir': -1 -}; -var it = circarray2iterator( [ 1, 2, 3, 4 ], opts ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -// ... -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = circarray2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -// ... -``` - -The invoked function is provided four arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **n**: iteration count. -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = circarray2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 9 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = circarray2iterator( [ 1, 2, 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom iterator. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var circarray2iterator = require( '@stdlib/array/to-circular-iterator' ); - -function scale( v, i, n ) { - return v * n; -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 10 ), randu ); - -// Create an iterator from the array which scales iterated values: -var opts = { - 'iter': arr.length * 10 -}; -var it = circarray2iterator( arr, opts, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-circular-iterator/benchmark/benchmark.js b/to-circular-iterator/benchmark/benchmark.js deleted file mode 100644 index 71c93103..00000000 --- a/to-circular-iterator/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var circarray2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = circarray2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = [ 1, 2, 3, 4 ]; - - iter = circarray2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = [ 1, 2, 3, 4 ]; - - iter = circarray2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return v * i; - } -}); diff --git a/to-circular-iterator/docs/repl.txt b/to-circular-iterator/docs/repl.txt deleted file mode 100644 index 717b8d7b..00000000 --- a/to-circular-iterator/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( src[, options][, mapFcn[, thisArg]] ) - Returns an iterator which repeatedly iterates over the elements of an array- - like object. - - When invoked, an input function is provided four arguments: - - - value: iterated value - - index: iterated value index - - n: iteration count - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - options: Object (optional) - Function options. - - options.iter: integer (optional) - Number of iterations. Default: 1e308. - - options.dir: integer (optional) - Iteration direction. If set to `-1`, an iterator iterates over elements - from right-to-left. Default: 1. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/to-circular-iterator/docs/types/index.d.ts b/to-circular-iterator/docs/types/index.d.ts deleted file mode 100644 index 56bdb3fd..00000000 --- a/to-circular-iterator/docs/types/index.d.ts +++ /dev/null @@ -1,158 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Number of iterations. - */ - iter?: number; - - /** - * Iteration direction (default: 1). - */ - dir?: number; -} - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, n: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count -* @param src - source array-like object -* @returns iterator value -*/ -type Quaternary = ( value: any, index: number, n: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary | Quaternary; - -/** -* Returns an iterator which repeatedly iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @throws must provide valid options -* @returns iterator -* -* @example -* var iter = circarray2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function circarray2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - -/** -* Returns an iterator which repeatedly iterates over each element in an array-like object. -* -* @param src - input value -* @param options - function options -* @param options.iter - number of iterations -* @param options.dir - iteration direction -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @throws must provide valid options -* @returns iterator -* -* @example -* var opts = { -* 'dir': -1 -* }; -* var it = circarray2iterator( [ 1, 2, 3, 4 ], opts ); -* // returns -* -* var v = it.next().value; -* // returns 4 -* -* v = it.next().value; -* // returns 3 -* -* v = it.next().value; -* // returns 2 -*/ -declare function circarray2iterator( src: ArrayLike, options: Options, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = circarray2iterator; diff --git a/to-circular-iterator/docs/types/test.ts b/to-circular-iterator/docs/types/test.ts deleted file mode 100644 index 8252de59..00000000 --- a/to-circular-iterator/docs/types/test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import circarray2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - circarray2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - circarray2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - circarray2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - circarray2iterator( 123 ); // $ExpectError - circarray2iterator( true ); // $ExpectError - circarray2iterator( false ); // $ExpectError - circarray2iterator( {} ); // $ExpectError - circarray2iterator( null ); // $ExpectError - circarray2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object or function... -{ - circarray2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dir` option which is not a number... -{ - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': 'abc' } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': true } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': false } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': null } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': [] } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': {} } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'dir': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `iter` option which is not a number... -{ - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': 'abc' } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': true } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': false } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': null } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': [] } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': {} } ); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], { 'iter': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - circarray2iterator(); // $ExpectError - circarray2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/to-circular-iterator/examples/index.js b/to-circular-iterator/examples/index.js deleted file mode 100644 index dc4a028c..00000000 --- a/to-circular-iterator/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var circarray2iterator = require( './../lib' ); - -function scale( v, i, n ) { - return v * n; -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 10 ), randu ); - -// Create an iterator from the array which scales iterated values: -var opts = { - 'iter': arr.length * 10 -}; -var it = circarray2iterator( arr, opts, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-circular-iterator/lib/index.js b/to-circular-iterator/lib/index.js deleted file mode 100644 index 741cfe31..00000000 --- a/to-circular-iterator/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which repeatedly iterates over the elements of an array-like object. -* -* @module @stdlib/array/to-circular-iterator -* -* @example -* var circarray2iterator = require( '@stdlib/array/to-circular-iterator' ); -* -* var iter = circarray2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-circular-iterator/lib/main.js b/to-circular-iterator/lib/main.js deleted file mode 100644 index 2cc40615..00000000 --- a/to-circular-iterator/lib/main.js +++ /dev/null @@ -1,273 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isObject = require( '@stdlib/assert/is-plain-object' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which repeatedly iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Options} [options] - function options -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @param {integer} [options.dir=1] - iteration direction -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} callback argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = circarray2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function circarray2iterator( src ) { - var thisArg; - var options; - var count; - var opts; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - opts = { - 'iter': 1e308, // ~infinity - 'dir': 1 // left to right iteration - }; - if ( arguments.length > 1 ) { - if ( isObject( arguments[ 1 ] ) ) { - options = arguments[ 1 ]; - if ( arguments.length > 2 ) { - fcn = arguments[ 2 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 3 ]; - } - if ( hasOwnProp( options, 'iter' ) ) { - opts.iter = options.iter; - if ( !isNonNegativeInteger( options.iter ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) ); - } - } - if ( hasOwnProp( options, 'dir' ) ) { - opts.dir = options.dir; - if ( options.dir !== 1 && options.dir !== -1 ) { - throw new TypeError( format( 'invalid option. `%s` option must be either `1` or `-1`. Option: `%s`.', 'dir', options.dir ) ); - } - } - } else { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be either a function or an options object. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - } - count = 0; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - if ( opts.dir === 1 ) { - i = -1; - setReadOnly( iter, 'next', next1a ); - } else { - i = src.length; - setReadOnly( iter, 'next', next1b ); - } - } else if ( opts.dir === 1 ) { - i = -1; - setReadOnly( iter, 'next', next2a ); - } else { - i = src.length; - setReadOnly( iter, 'next', next2b ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1a() { - i = (i+1) % src.length; - count += 1; - if ( FLG || count > opts.iter || src.length === 0 ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, count, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1b() { - i -= 1; - if ( i < 0 ) { - i += src.length; - } - count += 1; - if ( FLG || count > opts.iter || src.length === 0 ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, count, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2a() { - i = (i+1) % src.length; - count += 1; - if ( FLG || count > opts.iter || src.length === 0 ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2b() { - i -= 1; - if ( i < 0 ) { - i += src.length; - } - count += 1; - if ( FLG || count > opts.iter || src.length === 0 ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return circarray2iterator( src, opts, fcn, thisArg ); - } - return circarray2iterator( src, opts ); - } -} - - -// EXPORTS // - -module.exports = circarray2iterator; diff --git a/to-circular-iterator/package.json b/to-circular-iterator/package.json deleted file mode 100644 index 051f67bc..00000000 --- a/to-circular-iterator/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "@stdlib/array/to-circular-iterator", - "version": "0.0.0", - "description": "Create an iterator which repeatedly iterates over the elements of an array-like object.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert", - "circular", - "circ", - "infinite", - "loop", - "repeat" - ] -} diff --git a/to-circular-iterator/test/test.js b/to-circular-iterator/test/test.js deleted file mode 100644 index 84e21c0f..00000000 --- a/to-circular-iterator/test/test.js +++ /dev/null @@ -1,1067 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var circarray2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof circarray2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - circarray2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (options)', 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() { - circarray2iterator( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - circarray2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a callback argument which is not a function (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - circarray2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided a callback argument which is not a function (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - circarray2iterator( [ 1, 2, 3, 4 ], {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `iter` option which is not a nonnegative integer (no callback)', 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() { - circarray2iterator( [ 1, 2, 3, 4 ], { - 'iter': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an `iter` option which is not a nonnegative integer (callback)', 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() { - var opts = { - 'iter': value - }; - circarray2iterator( [ 1, 2, 3, 4 ], opts, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a `dir` option which is neither `1` nor `-1` (no callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 0, - -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() { - circarray2iterator( [ 1, 2, 3, 4 ], { - 'dir': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `dir` option which is neither `1` nor `-1` (callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 0, - -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() { - var opts = { - 'dir': value - }; - circarray2iterator( [ 1, 2, 3, 4 ], opts, noop ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which repeatedly iterates over elements of an array-like object (array)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - } - ]; - - it = circarray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length*2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which repeatedly iterates over elements of an array-like object (array; options)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - } - ]; - - it = circarray2iterator( values, {} ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length*2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which repeatedly iterates over the elements of an array-like object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - } - ]; - - it = circarray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length*2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which repeatedly iterates over elements of an array-like object (empty)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = []; - expected = [ - { - 'done': true - } - ]; - - it = circarray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = [ it.next() ]; - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = circarray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.done, false, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = circarray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.done, false, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (empty)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = []; - - it = circarray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = [ - { - 'done': true - } - ]; - actual = [ it.next() ]; - t.deepEqual( actual, expected, 'returns expected values' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - return v; - } -}); - -tape( 'the function supports limiting the number of iterations', function test( t ) { - var expected; - var actual; - var values; - var opts; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - opts = { - 'iter': 7 - }; - it = circarray2iterator( values, opts ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < opts.iter; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function supports limiting the number of iterations (callback)', function test( t ) { - var expected; - var actual; - var values; - var opts; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 9, - 'done': false - }, - { - 'value': 16, - 'done': false - }, - { - 'value': 5, - 'done': false - }, - { - 'value': 12, - 'done': false - }, - { - 'value': 21, - 'done': false - }, - { - 'done': true - } - ]; - - opts = { - 'iter': 7 - }; - it = circarray2iterator( values, opts, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < opts.iter; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); - - function scale( v, i, n ) { - return v * n; - } -}); - -tape( 'the function supports specifying the iteration direction', function test( t ) { - var expected; - var actual; - var values; - var opts; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - opts = { - 'iter': 7, - 'dir': -1 - }; - it = circarray2iterator( values, opts ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < opts.iter; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function supports specifying the iteration direction (callback)', function test( t ) { - var expected; - var actual; - var values; - var opts; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 6, - 'done': false - }, - { - 'value': 6, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 20, - 'done': false - }, - { - 'value': 18, - 'done': false - }, - { - 'value': 14, - 'done': false - }, - { - 'done': true - } - ]; - - opts = { - 'iter': 7, - 'dir': -1 - }; - it = circarray2iterator( values, opts, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < opts.iter; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); - - function scale( v, i, n ) { - return v * n; - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = circarray2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = circarray2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = circarray2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = circarray2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var circarray2iterator; - var values; - var it1; - var it2; - var i; - - circarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = circarray2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var circarray2iterator; - var values; - var it1; - var it2; - var i; - - circarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = circarray2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var circarray2iterator; - var it; - - circarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = circarray2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var circarray2iterator; - var it; - - circarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = circarray2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-fancy/README.md b/to-fancy/README.md deleted file mode 100644 index b1cf2c72..00000000 --- a/to-fancy/README.md +++ /dev/null @@ -1,619 +0,0 @@ - - -# array2fancy - -> Convert an array to an object supporting fancy indexing. - - - -
- -An array supporting **fancy indexing** is an array which supports slicing via indexing expressions for both retrieval and assignment. - -```javascript -var array2fancy = require( '@stdlib/array/to-fancy' ); - -// Create a plain array: -var x = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - -// Turn the plain array into a "fancy" array: -var y = array2fancy( x ); - -// Select the first 3 elements: -var v = y[ ':3' ]; -// returns [ 1, 2, 3 ] - -// Select every other element, starting from the second element: -v = y[ '1::2' ]; -// returns [ 2, 4, 6, 8 ] - -// Select every other element, in reverse order, starting with the least element: -v = y[ '::-2' ]; -// returns [ 8, 6, 4, 2 ] - -// Set all elements to the same value: -y[ ':' ] = 9; - -// Create a shallow copy by selecting all elements: -v = y[ ':' ]; -// returns [ 9, 9, 9, 9, 9, 9, 9, 9 ] -``` - -
- - - - - -
- -## Usage - -```javascript -var array2fancy = require( '@stdlib/array/to-fancy' ); -``` - -#### array2fancy( x\[, options] ) - -Converts an array to an object supporting fancy indexing. - -```javascript -var Slice = require( '@stdlib/slice/ctor' ); - -var x = [ 1, 2, 3, 4 ]; - -var y = array2fancy( x ); -// returns - -// Normal element access: -var v = y[ 0 ]; -// returns 1 - -v = y[ 1 ]; -// returns 2 - -// Using negative integers: -v = y[ -1 ]; -// returns 4 - -v = y[ -2 ]; -// returns 3 - -// Using subsequence expressions: -v = y[ '1::2' ]; -// returns [ 2, 4 ] - -// Using Slice objects: -v = y[ new Slice( 1, null, 2 ) ]; -// returns [ 2, 4 ] - -// Assignment: -y[ '1:3' ] = 5; -v = y[ ':' ]; -// returns [ 1, 5, 5, 4 ] -``` - -The function supports the following options: - -- **cache**: cache for resolving array index objects. Must have a `get` method which accepts a single argument: a string identifier associated with an array index. - - If an array index associated with a provided identifier exists, the `get` method should return an object having the following properties: - - - **data**: the underlying index array. - - **type**: the index type. Must be either `'mask'`, `'bool'`, or `'int'`. - - **dtype**: the [data type][@stdlib/array/dtypes] of the underlying array. - - If an array index is not associated with a provided identifier, the `get` method should return `null`. - - Default: [`ArrayIndex`][@stdlib/array/index]. - -- **strict**: boolean indicating whether to enforce strict bounds checking. Default: `false`. - -By default, the function returns a fancy array which does **not** enforce strict bounds checking. For example, - -```javascript -var y = array2fancy( [ 1, 2, 3, 4 ] ); - -var v = y[ 10 ]; -// returns undefined -``` - -To enforce strict bounds checking, set the `strict` option to `true`. - - - -```javascript -var y = array2fancy( [ 1, 2, 3, 4 ], { - 'strict': true -}); - -var v = y[ 10 ]; -// throws -``` - -#### array2fancy.factory( \[options] ) - -Returns a function for converting an array to an object supporting fancy indexing. - -```javascript -var fcn = array2fancy.factory(); - -var x = [ 1, 2, 3, 4 ]; - -var y = fcn( x ); -// returns - -var v = y[ ':' ]; -// returns [ 1, 2, 3, 4 ] -``` - -The function supports the following options: - -- **cache**: default cache for resolving array index objects. Must have a `get` method which accepts a single argument: a string identifier associated with an array index. - - If an array index associated with a provided identifier exists, the `get` method should return an object having the following properties: - - - **data**: the underlying index array. - - **type**: the index type. Must be either `'mask'`, `'bool'`, or `'int'`. - - **dtype**: the [data type][@stdlib/array/dtypes] of the underlying array. - - If an array index is not associated with a provided identifier, the `get` method should return `null`. - - Default: [`ArrayIndex`][@stdlib/array/index]. - -- **strict**: boolean indicating whether to enforce strict bounds checking by default. Default: `false`. - -By default, the function returns a function which, by default, does **not** enforce strict bounds checking. For example, - -```javascript -var fcn = array2fancy.factory(); - -var y = fcn( [ 1, 2, 3, 4 ] ); - -var v = y[ 10 ]; -// returns undefined -``` - -To enforce strict bounds checking by default, set the `strict` option to `true`. - - - -```javascript -var fcn = array2fancy.factory({ - 'strict': true -}); -var y = fcn( [ 1, 2, 3, 4 ] ); - -var v = y[ 10 ]; -// throws -``` - -The returned function supports the same options as above. When the returned function is provided option values, those values override the factory method defaults. - -#### array2fancy.idx( x\[, options] ) - -Wraps a provided array as an array index object. - -```javascript -var x = [ 1, 2, 3, 4 ]; - -var idx = array2fancy.idx( x ); -// returns -``` - -For documentation and usage, see [`ArrayIndex`][@stdlib/array/index]. - -
- - - - - -* * * - -
- -## Notes - -- A fancy array shares the **same** data as the provided input array. Hence, any mutations to the returned array will affect the underlying input array and vice versa. -- For operations returning a new array (e.g., when slicing or invoking an instance method), a fancy array returns a new fancy array having the same configuration as specified by `options`. -- A fancy array supports indexing using positive and negative integers (both numeric literals and strings), [`Slice`][@stdlib/slice/ctor] instances, [subsequence expressions][@stdlib/slice/seq2slice], and [index arrays][@stdlib/array/index] (boolean, mask, and integer). -- A fancy array supports all properties and methods of the input array, and, thus, a fancy array can be consumed by any API which supports array-like objects. -- Indexing expressions provide a convenient and powerful means for creating and operating on array views; however, their use does entail a performance cost. Indexing expressions are best suited for interactive use (e.g., in the [REPL][@stdlib/repl]) and scripting. For performance critical applications, prefer equivalent functional APIs supporting array-like objects. -- In older JavaScript environments which do **not** support [`Proxy`][@stdlib/proxy/ctor] objects, the use of indexing expressions is **not** supported. - -### Bounds Checking - -By default, fancy arrays do **not** enforce strict bounds checking across index expressions. The motivation for the default fancy array behavior stems from a desire to maintain parity with plain arrays; namely, the returning of `undefined` when accessing a single non-existent property. - -Accordingly, when `strict` is `false`, one may observe the following behaviors: - - - -```javascript -var x = array2fancy( [ 1, 2, 3, 4 ], { - 'strict': false -}); - -// Access a non-existent property: -var v = x[ 'foo' ]; -// returns undefined - -// Access an out-of-bounds index: -v = x[ 10 ]; -// returns undefined - -v = x[ -10 ]; -// returns undefined - -// Access an out-of-bounds slice: -v = x[ '10:' ]; -// returns [] - -// Access one or more out-of-bounds indices: -var i = array2fancy.idx( [ 10, 20 ] ); -v = x[ i ]; -// throws -``` - -When `strict` is `true`, fancy arrays normalize index behavior and consistently enforce strict bounds checking. - - - -```javascript -var x = array2fancy( [ 1, 2, 3, 4 ], { - 'strict': true -}); - -// Access a non-existent property: -var v = x[ 'foo' ]; -// returns undefined - -// Access an out-of-bounds index: -v = x[ 10 ]; -// throws - -v = x[ -10 ]; -// throws - -// Access an out-of-bounds slice: -v = x[ '10:' ]; -// throws - -// Access one or more out-of-bounds indices: -var i = array2fancy.idx( [ 10, 20 ] ); -v = x[ i ]; -// throws -``` - -### Broadcasting - -Fancy arrays support **broadcasting** in which assigned scalars and single-element arrays are repeated (without additional memory allocation) to match the length of a target array instance. - -```javascript -var y = array2fancy( [ 1, 2, 3, 4 ] ); - -// Broadcast a scalar: -y[ ':' ] = 5; -var v = y[ ':' ]; -// returns [ 5, 5, 5, 5 ] - -// Broadcast a single-element array: -y[ ':' ] = [ 6 ]; -v = y[ ':' ]; -// returns [ 6, 6, 6, 6 ] -``` - -Fancy array broadcasting follows the [same rules][@stdlib/ndarray/base/broadcast-shapes] as for [ndarrays][@stdlib/ndarray/ctor]. Consequently, when assigning arrays to slices, the array on the right-hand-side must be broadcast-compatible with number of elements in the slice. For example, each assignment expression in the following example follows broadcast rules and is thus valid. - -```javascript -var y = array2fancy( [ 1, 2, 3, 4 ] ); - -y[ ':' ] = [ 5, 6, 7, 8 ]; -var v = y[ ':' ]; -// returns [ 5, 6, 7, 8 ] - -y[ '1::2' ] = [ 9, 10 ]; -v = y[ ':' ]; -// returns [ 5, 9, 7, 10 ] - -y[ '1::2' ] = [ 11 ]; -v = y[ ':' ]; -// returns [ 5, 11, 7, 11 ] - -y[ '1::2' ] = 12; -v = y[ ':' ]; -// returns [ 5, 12, 7, 12 ] - -// Out-of-bounds slices (i.e., slices with zero elements): -y[ '10:20' ] = [ 13 ]; -v = y[ ':' ]; -// returns [ 5, 12, 7, 12 ] - -y[ '10:20' ] = 13; -v = y[ ':' ]; -// returns [ 5, 12, 7, 12 ] - -y[ '10:20' ] = []; -v = y[ ':' ]; -// returns [ 5, 12, 7, 12 ] -``` - -However, the following assignment expressions are not valid. - - - -```javascript -var y = array2fancy( [ 1, 2, 3, 4 ] ); - -y[ ':' ] = [ 5, 6 ]; -// throws - -// Out-of-bounds slice (i.e., a slice with zero elements): -y[ '10:20' ] = [ 8, 9, 10, 11 ]; -// throws -``` - -In order to broadcast a nested array element as one would a scalar, one must wrap the element in a single-element array. - -```javascript -var y = array2fancy( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Assign individual array elements: -y[ ':' ] = [ 5, 6 ]; -var v = y[ ':' ]; -// returns [ 5, 6 ] - -y = array2fancy( [ [ 1, 2 ], [ 3, 4 ] ] ); - -// Broadcast a nested array: -y[ ':' ] = [ [ 5, 6 ] ]; -v = y[ ':' ]; -// returns [ [ 5, 6 ], [ 5, 6 ] ] -``` - -### Casting - -Fancy arrays support [(mostly) safe casts][@stdlib/array/mostly-safe-casts] (i.e., any cast which can be performed without overflow or loss of precision, with the exception of floating-point arrays which are also allowed to downcast from higher precision to lower precision). - -```javascript -var Uint8Array = require( '@stdlib/array/uint8' ); -var Int32Array = require( '@stdlib/array/int32' ); - -var x = new Int32Array( [ 1, 2, 3, 4 ] ); -var y = array2fancy( x ); - -// 8-bit unsigned integer values can be safely cast to 32-bit signed integer values: -y[ ':' ] = new Uint8Array( [ 5, 6, 7, 8 ] ); -``` - -When attempting to perform an unsafe cast, fancy arrays will raise an exception. - - - -```javascript -var Uint8Array = require( '@stdlib/array/uint8' ); - -var x = new Uint8Array( [ 1, 2, 3, 4 ] ); -var y = array2fancy( x ); - -// Attempt to assign a non-integer value: -y[ ':' ] = 3.14; -// throws - -// Attempt to assign a negative value: -y[ ':' ] = -3; -// throws -``` - -When assigning a real-valued scalar to a complex number array (e.g., [`Complex128Array`][@stdlib/array/complex128] or [`Complex64Array`][@stdlib/array/complex64]), a fancy array will cast the real-valued scalar to a complex number argument having an imaginary component equal to zero. - -```javascript -var Complex128Array = require( '@stdlib/array/complex128' ); -var real = require( '@stdlib/complex/float64/real' ); -var imag = require( '@stdlib/complex/float64/imag' ); - -var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -var y = array2fancy( x ); - -// Retrieve the first element: -var v = y[ 0 ]; -// returns - -var re = real( v ); -// returns 1.0 - -var im = imag( v ); -// returns 2.0 - -// Assign a real-valued scalar to the first element: -y[ 0 ] = 9.0; - -v = y[ 0 ]; -// returns - -re = real( v ); -// returns 9.0 - -im = imag( v ); -// returns 0.0 -``` - -
- - - - - -* * * - -
- -## Examples - - - -```javascript -var Uint8Array = require( '@stdlib/array/uint8' ); -var Int32Array = require( '@stdlib/array/int32' ); -var BooleanArray = require( '@stdlib/array/bool' ); -var array2fancy = require( '@stdlib/array/to-fancy' ); - -var x = [ 1, 2, 3, 4, 5, 6 ]; -var y = array2fancy( x ); -// returns - -// Slice retrieval: -var z = y[ '1::2' ]; -// returns [ 2, 4, 6 ] - -z = y[ '-2::-2' ]; -// returns [ 5, 3, 1 ] - -z = y[ '1:4' ]; -// returns [ 2, 3, 4 ] - -// Slice assignment: -y[ '4:1:-1' ] = 10; -z = y[ ':' ]; -// returns [ 1, 2, 10, 10, 10, 6 ] - -y[ '2:5' ] = [ -10, -9, -8 ]; -z = y[ ':' ]; -// returns [ 1, 2, -10, -9, -8, 6 ] - -// Array index retrieval: -var idx = array2fancy.idx; - -var i = idx( [ 1, 3, 4 ] ); // integer index array -z = y[ i ]; -// returns [ 2, -9, -8 ] - -i = idx( [ true, false, false, true, true, true ] ); // boolean array -z = y[ i ]; -// returns [ 1, -9, -8, 6 ] - -i = idx( new BooleanArray( [ true, false, false, true, true, true ] ) ); // boolean array -z = y[ i ]; -// returns [ 1, -9, -8, 6 ] - -i = idx( new Uint8Array( [ 0, 0, 1, 0, 0, 1 ] ) ); // mask array -z = y[ i ]; -// returns [ 1, 2, -9, -8 ] - -i = idx( new Int32Array( [ 0, 0, 1, 1, 2, 2 ] ) ); // integer index array -z = y[ i ]; -// returns [ 1, 1, 2, 2, -10, -10 ] - -// Array index assignment: -x = [ 1, 2, 3, 4, 5, 6 ]; -y = array2fancy( x ); - -i = idx( [ true, false, true, false, true, false ] ); // boolean array -y[ i ] = 5; -z = y[ ':' ]; -// returns [ 5, 2, 5, 4, 5, 6 ] - -i = idx( new BooleanArray( [ true, false, true, false, true, false ] ) ); // boolean array -y[ i ] = 7; -z = y[ ':' ]; -// returns [ 7, 2, 7, 4, 7, 6 ] - -i = idx( new Uint8Array( [ 1, 1, 1, 0, 0, 0 ] ) ); // mask array -y[ i ] = 8; -z = y[ ':' ]; -// returns [ 7, 2, 7, 8, 8, 8 ] - -i = idx( new Int32Array( [ 5, 3, 2 ] ) ); // integer index array -y[ i ] = [ 9, 10, 11 ]; -z = y[ ':' ]; -// returns [ 7, 2, 11, 10, 8, 9 ] - -i = idx( [ 0, 1 ] ); // integer index array -y[ i ] = -1; -z = y[ ':' ]; -// returns [ -1, -1, 11, 10, 8, 9 ] -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-fancy/benchmark/benchmark.factory.js b/to-fancy/benchmark/benchmark.factory.js deleted file mode 100644 index d1dd1a91..00000000 --- a/to-fancy/benchmark/benchmark.factory.js +++ /dev/null @@ -1,48 +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' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var array2fancy = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = array2fancy.factory(); - if ( typeof v !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( v ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/to-fancy/benchmark/benchmark.get.js b/to-fancy/benchmark/benchmark.get.js deleted file mode 100644 index 412d65f4..00000000 --- a/to-fancy/benchmark/benchmark.get.js +++ /dev/null @@ -1,241 +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' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isnan = require( '@stdlib/assert/is-nan' ).isPrimitive; -var zeroTo = require( './../../zero-to' ); -var zeros = require( './../../zeros' ); -var filledarray = require( './../../filled' ); -var Slice = require( '@stdlib/slice/ctor' ); -var pkg = require( './../package.json' ).name; -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// MAIN // - -bench( pkg+'::get,positive_integers:len=1', function benchmark( b ) { - var x; - var v; - var i; - - x = array2fancy( zeroTo( 100, 'generic' ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ i%x.length ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,negative_integers:len=1', opts, function benchmark( b ) { - var x; - var v; - var i; - - x = array2fancy( zeroTo( 100, 'generic' ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ -(i%x.length) ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,slice:len=1', opts, function benchmark( b ) { - var values; - var x; - var v; - var i; - - x = array2fancy( zeroTo( 100, 'generic' ) ); - values = [ - new Slice( 0, 1 ), - new Slice( 1, 2 ), - new Slice( 2, 3 ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ values[ i%values.length ] ]; - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,subsequence:len=1', opts, function benchmark( b ) { - var values; - var x; - var v; - var i; - - x = array2fancy( zeroTo( 100, 'generic' ) ); - values = [ - ':1', - ':1:', - '0:1:1' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ values[ i%values.length ] ]; - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,integer_array:len=1', opts, function benchmark( b ) { - var values; - var opts; - var x; - var v; - var i; - - x = array2fancy( zeroTo( 100, 'generic' ) ); - - opts = { - 'persist': true - }; - values = [ - array2fancy.idx( [ 1 ], opts ), - array2fancy.idx( [ 2 ], opts ), - array2fancy.idx( [ 3 ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ values[ i%values.length ] ]; - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,mask_array:len=1', opts, function benchmark( b ) { - var values; - var opts; - var x; - var v; - var i; - - x = array2fancy( zeros( 100, 'uint8' ) ); - - opts = { - 'persist': true - }; - values = [ - array2fancy.idx( [ 1 ], opts ), - array2fancy.idx( [ 2 ], opts ), - array2fancy.idx( [ 3 ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ values[ i%values.length ] ]; - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get,boolean_array:len=1', opts, function benchmark( b ) { - var values; - var opts; - var x; - var v; - var i; - - x = array2fancy( filledarray( true, 100, 'generic' ) ); - - opts = { - 'persist': true - }; - values = [ - array2fancy.idx( [ 1 ], opts ), - array2fancy.idx( [ 2 ], opts ), - array2fancy.idx( [ 3 ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = x[ values[ i%values.length ] ]; - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/to-fancy/benchmark/benchmark.js b/to-fancy/benchmark/benchmark.js deleted file mode 100644 index ae5fc80e..00000000 --- a/to-fancy/benchmark/benchmark.js +++ /dev/null @@ -1,55 +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' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var pkg = require( './../package.json' ).name; -var array2fancy = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var v; - var i; - - values = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = array2fancy( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isCollection( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/to-fancy/benchmark/benchmark.set.js b/to-fancy/benchmark/benchmark.set.js deleted file mode 100644 index 0f3ef99f..00000000 --- a/to-fancy/benchmark/benchmark.set.js +++ /dev/null @@ -1,195 +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' ); -var isnan = require( '@stdlib/assert/is-nan' ).isPrimitive; -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var zeroTo = require( './../../zero-to' ); -var Slice = require( '@stdlib/slice/ctor' ); -var pkg = require( './../package.json' ).name; -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// MAIN // - -bench( pkg+'::set,positive_integers:len=1', function benchmark( b ) { - var base; - var x; - var v; - var i; - var j; - - base = zeroTo( 100, 'generic' ); - x = array2fancy( base ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = i % x.length; - x[ j ] = i * 2; - v = base[ j ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,negative_integers:len=1', opts, function benchmark( b ) { - var base; - var x; - var v; - var i; - var j; - - base = zeroTo( 100, 'generic' ); - x = array2fancy( base ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - j = -( i%x.length ) - 1; - x[ j ] = i * 2; - v = base[ base.length+j ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,slice:len=1', opts, function benchmark( b ) { - var values; - var base; - var x; - var s; - var v; - var i; - - base = zeroTo( 100, 'generic' ); - x = array2fancy( base ); - values = [ - new Slice( 0, 1 ), - new Slice( 1, 2 ), - new Slice( 2, 3 ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = values[ i%values.length ]; - x[ s ] = i * 2; - v = base[ s.start ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,subsequence:len=1', opts, function benchmark( b ) { - var values; - var base; - var x; - var v; - var i; - - base = zeroTo( 100, 'generic' ); - x = array2fancy( base ); - values = [ - ':1', - ':1:', - '0:1:1' - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x[ values[ i%values.length ] ] = i * 2; - v = base[ 0 ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,integer_array:len=1', opts, function benchmark( b ) { - var values; - var base; - var opts; - var idx; - var x; - var v; - var i; - - base = zeroTo( 100, 'generic' ); - x = array2fancy( base ); - - opts = { - 'persist': true - }; - values = [ - array2fancy.idx( [ 0 ], opts ), - array2fancy.idx( [ 1 ], opts ), - array2fancy.idx( [ 2 ], opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - idx = values[ i%values.length ]; - x[ idx ] = i * 2; - v = base[ i%3 ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/to-fancy/docs/repl.txt b/to-fancy/docs/repl.txt deleted file mode 100644 index ee34eda5..00000000 --- a/to-fancy/docs/repl.txt +++ /dev/null @@ -1,169 +0,0 @@ - -{{alias}}( x[, options] ) - Converts an array to an object supporting fancy indexing. - - An array supporting fancy indexing is an array which supports slicing via - indexing expressions for both retrieval and assignment. - - A fancy array shares the *same* data as the provided input array. Hence, any - mutations to the returned array will affect the underlying input array and - vice versa. - - For operations returning a new array (e.g., when slicing or invoking an - instance method), a fancy array returns a new fancy array having the same - configuration as specified by provided options. - - A fancy array supports indexing using positive and negative integers (both - numeric literals and strings), Slice instances, subsequence expressions, - mask arrays, boolean arrays, and integer arrays. - - A fancy array supports all properties and methods of the input array, and, - thus, a fancy array can be consumed by any API which supports array-like - objects. - - Indexing expressions provide a convenient and powerful means for creating - and operating on array views; however, their use does entail a performance - cost. Indexing expressions are best suited for interactive use (e.g., in the - REPL) and scripting. For performance critical applications, prefer - equivalent functional APIs supporting array-like objects. - - Fancy arrays support broadcasting in which assigned scalars and single- - element arrays are repeated (without additional memory allocation) to match - the length of a target array instance. - - Fancy array broadcasting follows the same rules as for ndarrays. - - Consequently, when assigning arrays to slices, the array on the right-hand- - side must be broadcast-compatible with number of elements in the slice. - - Fancy arrays support (mostly) safe casts (i.e., any cast which can be - performed without overflow or loss of precision, with the exception of - floating-point arrays which are also allowed to downcast from higher - precision to lower precision). - - When attempting to perform an unsafe cast, fancy arrays will raise an - exception. - - When assigning a real-valued scalar to a complex number array (e.g., - Complex128Array or Complex64Array), a fancy array will cast the real-valued - scalar to a complex number argument having an imaginary component equal to - zero. - - In older JavaScript environments which do not support Proxy objects, the use - of indexing expressions is not supported. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. Default: - false. - - options.cache: Object (optional) - Cache for resolving array index objects. Must have a 'get' method which - accepts a single argument: a string identifier associated with an array - index. If an array index associated with a provided identifier exists, - the 'get' method should return an object having the following - properties: - - - data: the underlying index array. - - type: the index type. Must be either 'mask', 'bool', or 'int'. - - dtype: the data type of the underlying array. - - If an array index is not associated with a provided identifier, the - 'get' method should return `null`. - - Default: `{{alias:@stdlib/array/index}}`. - - Returns - ------- - out: Array|TypedArray|Object - Output array supporting fancy indexing. - - Examples - -------- - > var y = {{alias}}( [ 1, 2, 3, 4 ] ); - > y[ '1::2' ] - [ 2, 4 ] - > y[ '::-1' ] - [ 4, 3, 2, 1 ] - - -{{alias}}.factory( [options] ) - Returns a function for converting an array to an object supporting fancy - indexing. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking by default. - Default: false. - - options.cache: Object (optional) - Cache for resolving array index objects. Must have a 'get' method which - accepts a single argument: a string identifier associated with an array - index. If an array index associated with a provided identifier exists, - the 'get' method should return an object having the following - properties: - - - data: the underlying index array. - - type: the index type. Must be either 'mask', 'bool', or 'int'. - - dtype: the data type of the underlying array. - - If an array index is not associated with a provided identifier, the - 'get' method should return `null`. - - Default: `{{alias:@stdlib/array/index}}`. - - Returns - ------- - fcn: Function - Function for converting an array to an object supporting fancy indexing. - - Examples - -------- - > var f = {{alias}}.factory(); - > var y = f( [ 1, 2, 3, 4 ] ); - > y[ '1::2' ] - [ 2, 4 ] - > y[ '::-1' ] - [ 4, 3, 2, 1 ] - - -{{alias}}.idx( x[, options] ) - Wraps a provided array as an array index object. - - For documentation and usage, see `{{alias:@stdlib/array/index}}`. - - Parameters - ---------- - x: Array|TypedArray|Object - Input array. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ArrayIndex - ArrayIndex instance. - - Examples - -------- - > var idx = {{alias}}.idx( [ 1, 2, 3, 4 ] ); - - See Also - -------- - diff --git a/to-fancy/docs/types/index.d.ts b/to-fancy/docs/types/index.d.ts deleted file mode 100644 index 190fa5b8..00000000 --- a/to-fancy/docs/types/index.d.ts +++ /dev/null @@ -1,332 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection, ArrayLike, AccessorArrayLike, ComplexTypedArray, TypedArray, BooleanTypedArray, ArrayIndexObject } from '@stdlib/types/array'; -import ArrayIndex = require( './../../../index' ); - -/** -* Interface describing a cache for resolving array index objects. -*/ -interface Cache { - /** - * Returns an array associated with the index object having a provided identifier. - * - * @param id - identifier - * @returns index data - */ - get( id: any ): ArrayIndexObject | null; -} - -/** -* Interface describing function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking. - */ - strict?: boolean; - - /** - * Cache for resolving array index objects. - */ - cache?: Cache; -} - -/** -* Interface describing the main export. -*/ -interface Array2Fancy { - /** - * Converts an array to an object supporting fancy indexing. - * - * @param x - input array - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking - * @param options.cache - cache for resolving array index objects - * @returns fancy array - * - * @example - * var Float64Array = require( './../../../float64' ); - * - * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1.0, 2.0, 3.0, 4.0 ] - * - * @example - * var Float32Array = require( './../../../float32' ); - * - * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1.0, 2.0, 3.0, 4.0 ] - * - * @example - * var Complex128Array = require( './../../../complex128' ); - * - * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1.0, 2.0, 3.0, 4.0 ] - * - * @example - * var Complex64Array = require( './../../../complex64' ); - * - * var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1.0, 2.0, 3.0, 4.0 ] - * - * @example - * var Int32Array = require( './../../../int32' ); - * - * var x = new Int32Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Int16Array = require( './../../../int16' ); - * - * var x = new Int16Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Int8Array = require( './../../../int8' ); - * - * var x = new Int8Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Uint32Array = require( './../../../uint32' ); - * - * var x = new Uint32Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Uint16Array = require( './../../../uint16' ); - * - * var x = new Uint16Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Uint8Array = require( './../../../uint8' ); - * - * var x = new Uint8Array( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - * - * @example - * var Uint8ClampedArray = require( './../../../uint8c' ); - * - * var x = new Uint8ClampedArray( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - */ - ( x: T, options?: Options ): T; - - /** - * Converts an array to an object supporting fancy indexing. - * - * @param x - input array - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking - * @param options.cache - cache for resolving array index objects - * @returns fancy array - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - */ - ( x: Array, options?: Options ): Array; - - /** - * Converts an array to an object supporting fancy indexing. - * - * @param x - input array - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking - * @param options.cache - cache for resolving array index objects - * @returns fancy array - * - * @example - * var toAccessorArray = require( './../../../base/to-accessor-array' ); - * - * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); - * - * var y = array2fancy( x ); - * var v = y[ ':' ]; - */ - ( x: AccessorArrayLike, options?: Options ): AccessorArrayLike; - - /** - * Converts an array to an object supporting fancy indexing. - * - * @param x - input array - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking - * @param options.cache - cache for resolving array index objects - * @returns fancy array - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - */ - ( x: Collection, options?: Options ): Collection; - - /** - * Converts an array-like value to an object supporting fancy indexing. - * - * @param x - input array - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking - * @param options.cache - cache for resolving array index objects - * @returns fancy array - * - * @example - * var x = [ 1, 2, 3, 4 ]; - * - * var y = array2fancy( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - */ - ( x: ArrayLike, options?: Options ): ArrayLike; - - /** - * Returns a function for converting an array to an object supporting fancy indexing. - * - * @param options - function options - * @param options.strict - boolean indicating whether to enforce strict bounds checking by default - * @param options.cache - cache for resolving array index objects - * @returns function for converting an array to an object supporting fancy indexing - * - * @example - * var fcn = array2fancy.factory(); - * - * var x = [ 1, 2, 3, 4 ]; - * - * var y = fcn( x ); - * // returns - * - * var v = y[ ':' ]; - * // returns [ 1, 2, 3, 4 ] - */ - factory( options?: Options ): Array2Fancy; - - /** - * Array index constructor. - * - * @param x - input array - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ArrayIndex instance - * - * @example - * var Uint8Array = require( './../../../uint8' ); - * - * var x = new Uint8Array( [ 1, 0, 1, 0 ] ); - * - * var idx = array2fancy.idx( x ); - * // returns - */ - idx: typeof ArrayIndex; -} - -/** -* Converts an array to an object supporting fancy indexing. -* -* @param x - input array -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @param options.cache - cache for resolving array index objects -* @returns fancy array -* -* @example -* var x = [ 1, 2, 3, 4 ]; -* -* var y = array2fancy( x ); -* // returns -* -* var v = y[ ':' ]; -* // returns [ 1, 2, 3, 4 ] -*/ -declare var array2fancy: Array2Fancy; - - -// EXPORTS // - -export = array2fancy; diff --git a/to-fancy/docs/types/test.ts b/to-fancy/docs/types/test.ts deleted file mode 100644 index 3a3d80e7..00000000 --- a/to-fancy/docs/types/test.ts +++ /dev/null @@ -1,190 +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. -*/ - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); -import BooleanArray = require( './../../../bool' ); -import array2fancy = require( './index' ); - - -// TESTS // - -// The function returns an array... -{ - array2fancy( [ 1, 2, 3 ] ); // $ExpectType number[] - array2fancy( new Float64Array( [ 1, 2, 3 ] ) ); // $ExpectType Float64Array - array2fancy( new Float32Array( [ 1, 2, 3 ] ) ); // $ExpectType Float32Array - array2fancy( new Int32Array( [ 1, 2, 3 ] ) ); // $ExpectType Int32Array - array2fancy( new Int16Array( [ 1, 2, 3 ] ) ); // $ExpectType Int16Array - array2fancy( new Int8Array( [ 1, 2, 3 ] ) ); // $ExpectType Int8Array - array2fancy( new Uint32Array( [ 1, 2, 3 ] ) ); // $ExpectType Uint32Array - array2fancy( new Uint16Array( [ 1, 2, 3 ] ) ); // $ExpectType Uint16Array - array2fancy( new Uint8Array( [ 1, 2, 3 ] ) ); // $ExpectType Uint8Array - array2fancy( new Uint8ClampedArray( [ 1, 2, 3 ] ) ); // $ExpectType Uint8ClampedArray - array2fancy( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ) ); // $ExpectType Complex128Array - array2fancy( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ) ); // $ExpectType Complex64Array - array2fancy( new BooleanArray( [ true, false, true ] ) ); // $ExpectType BooleanArray - - const opts = { - 'strict': true - }; - array2fancy( [ 1, 2, 3 ], opts ); // $ExpectType number[] - array2fancy( new Float64Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Float64Array - array2fancy( new Float32Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Float32Array - array2fancy( new Int32Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Int32Array - array2fancy( new Int16Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Int16Array - array2fancy( new Int8Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Int8Array - array2fancy( new Uint32Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Uint32Array - array2fancy( new Uint16Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Uint16Array - array2fancy( new Uint8Array( [ 1, 2, 3 ] ), opts ); // $ExpectType Uint8Array - array2fancy( new Uint8ClampedArray( [ 1, 2, 3 ] ), opts ); // $ExpectType Uint8ClampedArray - array2fancy( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), opts ); // $ExpectType Complex128Array - array2fancy( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), opts ); // $ExpectType Complex64Array - array2fancy( new BooleanArray( [ true, false, true ] ), opts ); // $ExpectType BooleanArray -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like value... -{ - array2fancy( 5 ); // $ExpectError - array2fancy( true ); // $ExpectError - array2fancy( false ); // $ExpectError - array2fancy( null ); // $ExpectError - array2fancy( void 0 ); // $ExpectError - array2fancy( {} ); // $ExpectError - - array2fancy( 5, {} ); // $ExpectError - array2fancy( true, {} ); // $ExpectError - array2fancy( false, {} ); // $ExpectError - array2fancy( null, {} ); // $ExpectError - array2fancy( void 0, {} ); // $ExpectError - array2fancy( {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = [ 1, 2, 3, 4 ]; - - array2fancy( x, '5' ); // $ExpectError - array2fancy( x, 5 ); // $ExpectError - array2fancy( x, true ); // $ExpectError - array2fancy( x, false ); // $ExpectError - array2fancy( x, null ); // $ExpectError - array2fancy( x, [] ); // $ExpectError - array2fancy( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = [ 1, 2, 3, 4 ]; - - array2fancy( x, { 'strict': '5' } ); // $ExpectError - array2fancy( x, { 'strict': 5 } ); // $ExpectError - array2fancy( x, { 'strict': null } ); // $ExpectError - array2fancy( x, { 'strict': [] } ); // $ExpectError - array2fancy( x, { 'strict': {} } ); // $ExpectError - array2fancy( x, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `cache` option which is not valid... -{ - const x = [ 1, 2, 3, 4 ]; - - array2fancy( x, { 'cache': '5' } ); // $ExpectError - array2fancy( x, { 'cache': 5 } ); // $ExpectError - array2fancy( x, { 'cache': true } ); // $ExpectError - array2fancy( x, { 'cache': false } ); // $ExpectError - array2fancy( x, { 'cache': null } ); // $ExpectError - array2fancy( x, { 'cache': [] } ); // $ExpectError - array2fancy( x, { 'cache': {} } ); // $ExpectError - array2fancy( x, { 'cache': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2fancy(); // $ExpectError - array2fancy( [ 1, 2, 3 ], {}, {} ); // $ExpectError -} - -// Attached to the function is a `factory` method which returns a function... -{ - array2fancy.factory(); // $ExpectType Array2Fancy - array2fancy.factory( {} ); // $ExpectType Array2Fancy - array2fancy.factory( { 'strict': true } ); // $ExpectType Array2Fancy -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - array2fancy.factory( '5' ); // $ExpectError - array2fancy.factory( 5 ); // $ExpectError - array2fancy.factory( true ); // $ExpectError - array2fancy.factory( false ); // $ExpectError - array2fancy.factory( null ); // $ExpectError - array2fancy.factory( [] ); // $ExpectError - array2fancy.factory( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `strict` option which is not a boolean... -{ - array2fancy.factory( { 'strict': '5' } ); // $ExpectError - array2fancy.factory( { 'strict': 5 } ); // $ExpectError - array2fancy.factory( { 'strict': null } ); // $ExpectError - array2fancy.factory( { 'strict': [] } ); // $ExpectError - array2fancy.factory( { 'strict': {} } ); // $ExpectError - array2fancy.factory( { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `cache` option which is not valid... -{ - array2fancy.factory( { 'cache': '5' } ); // $ExpectError - array2fancy.factory( { 'cache': 5 } ); // $ExpectError - array2fancy.factory( { 'cache': true } ); // $ExpectError - array2fancy.factory( { 'cache': false } ); // $ExpectError - array2fancy.factory( { 'cache': null } ); // $ExpectError - array2fancy.factory( { 'cache': [] } ); // $ExpectError - array2fancy.factory( { 'cache': {} } ); // $ExpectError - array2fancy.factory( { 'cache': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - array2fancy.factory( {}, {} ); // $ExpectError -} - -// Attached to the function is an `idx` method which returns an array index... -{ - const x = [ 1, 2, 3, 4 ]; - const y = [ true, false, true, false ]; - const z = new Uint8Array( [ 1, 0, 1, 0 ] ); - const w = new Int32Array( [ 1, 2, 3, 4 ] ); - const v = new BooleanArray( [ true, false, true, false ] ); - - array2fancy.idx( x ); // $ExpectType GenericIntegerArrayIndex - array2fancy.idx( x, {} ); // $ExpectType GenericIntegerArrayIndex - - array2fancy.idx( y ); // $ExpectType GenericBooleanArrayIndex - array2fancy.idx( y, {} ); // $ExpectType GenericBooleanArrayIndex - - array2fancy.idx( z ); // $ExpectType MaskArrayIndex - array2fancy.idx( z, {} ); // $ExpectType MaskArrayIndex - - array2fancy.idx( w ); // $ExpectType Int32ArrayIndex - array2fancy.idx( w, {} ); // $ExpectType Int32ArrayIndex - - array2fancy.idx( v ); // $ExpectType BooleanArrayIndex - array2fancy.idx( v, {} ); // $ExpectType BooleanArrayIndex -} diff --git a/to-fancy/examples/index.js b/to-fancy/examples/index.js deleted file mode 100644 index 8b53e31e..00000000 --- a/to-fancy/examples/index.js +++ /dev/null @@ -1,109 +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'; - -var Uint8Array = require( './../../uint8' ); -var Int32Array = require( './../../int32' ); -var BooleanArray = require( './../../bool' ); -var array2fancy = require( './../lib' ); - -var x = [ 1, 2, 3, 4, 5, 6 ]; -var y = array2fancy( x ); -// returns - -// Slice retrieval: -var z = y[ '1::2' ]; -console.log( z ); -// => [ 2, 4, 6 ] - -z = y[ '-2::-2' ]; -console.log( z ); -// => [ 5, 3, 1 ] - -z = y[ '1:4' ]; -console.log( z ); -// => [ 2, 3, 4 ] - -// Slice assignment: -y[ '4:1:-1' ] = 10; -z = y[ ':' ]; -console.log( z ); -// => [ 1, 2, 10, 10, 10, 6 ] - -y[ '2:5' ] = [ -10, -9, -8 ]; -z = y[ ':' ]; -console.log( z ); -// => [ 1, 2, -10, -9, -8, 6 ] - -// Array index retrieval: -var idx = array2fancy.idx; - -var i = idx( [ 1, 3, 4 ] ); // integer index array -z = y[ i ]; -console.log( z ); -// => [ 2, -9, -8 ] - -i = idx( [ true, false, false, true, true, true ] ); // boolean array -z = y[ i ]; -console.log( z ); -// => [ 1, -9, -8, 6 ] - -i = idx( new BooleanArray( [ true, false, false, true, true, true ] ) ); // boolean array -z = y[ i ]; -console.log( z ); -// => [ 1, -9, -8, 6 ] - -i = idx( new Uint8Array( [ 0, 0, 1, 0, 0, 1 ] ) ); // mask array -z = y[ i ]; -console.log( z ); -// => [ 1, 2, -9, -8 ] - -i = idx( new Int32Array( [ 0, 0, 1, 1, 2, 2 ] ) ); // integer index array -z = y[ i ]; -console.log( z ); -// => [ 1, 1, 2, 2, -10, -10 ] - -// Array index assignment: -x = [ 1, 2, 3, 4, 5, 6 ]; -y = array2fancy( x ); - -i = idx( [ true, false, true, false, true, false ] ); // boolean array -y[ i ] = 5; -console.log( y ); -// => [ 5, 2, 5, 4, 5, 6 ] - -i = idx( new BooleanArray( [ true, false, true, false, true, false ] ) ); // boolean array -y[ i ] = 7; -console.log( y ); -// => [ 7, 2, 7, 4, 7, 6 ] - -i = idx( new Uint8Array( [ 1, 1, 1, 0, 0, 0 ] ) ); // mask array -y[ i ] = 8; -console.log( y ); -// => [ 7, 2, 7, 8, 8, 8 ] - -i = idx( new Int32Array( [ 5, 3, 2 ] ) ); // integer index array -y[ i ] = [ 9, 10, 11 ]; -console.log( y ); -// => [ 7, 2, 11, 10, 8, 9 ] - -i = idx( [ 0, 1 ] ); // integer index array -y[ i ] = -1; -console.log( y ); -// => [ -1, -1, 11, 10, 8, 9 ] diff --git a/to-fancy/lib/ctor.js b/to-fancy/lib/ctor.js deleted file mode 100644 index 03d627b9..00000000 --- a/to-fancy/lib/ctor.js +++ /dev/null @@ -1,94 +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'; - -// MAIN // - -/** -* Returns a trap for constructing new array instances. -* -* @private -* @param {Function} array2fancy - function for creating a proxied array -* @param {Object} opts - options -* @param {boolean} opts.strict - boolean indicating whether to perform strict bounds checking -* @returns {Function} handler -*/ -function factory( array2fancy, opts ) { - return constructor; - - /** - * Trap for constructing new array instances. - * - * @private - * @param {Object} target - target object - * @param {Array} args - list of constructor arguments - * @param {Object} newTarget - constructor that was originally called - * @returns {*} new instance - */ - function constructor( target, args ) { - var x; - var a; - - a = args; - switch ( a.length ) { - case 0: - x = new target(); - break; - case 1: - x = new target( a[0] ); - break; - case 2: - x = new target( a[0], a[1] ); - break; - case 3: - x = new target( a[0], a[1], a[2] ); - break; - case 4: - x = new target( a[0], a[1], a[2], a[3] ); - break; - case 5: - x = new target( a[0], a[1], a[2], a[3], a[4] ); - break; - case 6: - x = new target( a[0], a[1], a[2], a[3], a[4], a[5] ); - break; - case 7: - x = new target( a[0], a[1], a[2], a[3], a[4], a[5], a[6] ); - break; - case 8: - x = new target( a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7] ); - break; - case 9: - x = new target( a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8] ); // eslint-disable-line max-len - break; - case 10: - x = new target( a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9] ); // eslint-disable-line max-len - break; - default: - // Fallback to using `apply`; however, some constructors may error if the constructor is not callable (i.e., if a constructor always requires `new`): - x = target.apply( null, a ); - } - return array2fancy( x, opts ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/to-fancy/lib/defaults.js b/to-fancy/lib/defaults.js deleted file mode 100644 index f9ef5cf8..00000000 --- a/to-fancy/lib/defaults.js +++ /dev/null @@ -1,48 +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 ArrayIndex = require( './../../index' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'cache': ArrayIndex, - 'strict': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/to-fancy/lib/error_constructor.js b/to-fancy/lib/error_constructor.js deleted file mode 100644 index 4ccef8c6..00000000 --- a/to-fancy/lib/error_constructor.js +++ /dev/null @@ -1,53 +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 isRangeError = require( '@stdlib/assert/is-range-error' ); -var isTypeError = require( '@stdlib/assert/is-type-error' ); -var isSyntaxError = require( '@stdlib/assert/is-syntax-error' ); - - -// MAIN // - -/** -* Returns the error constructor for a provided error object. -* -* @private -* @param {Error} err - error object -* @returns {Function} error constructor -*/ -function errConstructor( err ) { - if ( isRangeError( err ) ) { - return RangeError; - } - if ( isTypeError( err ) ) { - return TypeError; - } - if ( isSyntaxError( err ) ) { - return SyntaxError; - } - return Error; -} - - -// EXPORTS // - -module.exports = errConstructor; diff --git a/to-fancy/lib/error_message.js b/to-fancy/lib/error_message.js deleted file mode 100644 index 09d59519..00000000 --- a/to-fancy/lib/error_message.js +++ /dev/null @@ -1,42 +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 replace = require( '@stdlib/string/base/replace' ); - - -// MAIN // - -/** -* Returns an updated error message for trapped errors. -* -* @private -* @param {string} msg - error message -* @returns {string} updated message -*/ -function errMessage( msg ) { - return replace( msg, /^invalid arguments?/, 'invalid operation' ); -} - - -// EXPORTS // - -module.exports = errMessage; diff --git a/to-fancy/lib/factory.js b/to-fancy/lib/factory.js deleted file mode 100644 index efbc9888..00000000 --- a/to-fancy/lib/factory.js +++ /dev/null @@ -1,169 +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 isArrayLike = require( '@stdlib/assert/is-array-like' ); -var Proxy = require( '@stdlib/proxy/ctor' ); -var arraylike2object = require( './../../base/arraylike2object' ); -var assign = require( '@stdlib/object/assign' ); -var format = require( '@stdlib/string/format' ); -var setElementWrapper = require( './set_element_wrapper.js' ); -var getArrayWrapper = require( './get_array_wrapper.js' ); -var hasProxySupport = require( './has_proxy_support.js' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var validator = require( './validator.js' ); -var ctor = require( './ctor.js' ); -var get = require( './get.js' ); -var set = require( './set.js' ); - - -// MAIN // - -/** -* Returns a function for converting an array to an object supporting fancy indexing. -* -* @param {Options} options - function options -* @param {boolean} [options.strict=false] - boolean indicating whether to enforce strict bounds checking by default -* @param {Function} [options.cache] - default cache for resolving array index objects -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} function for converting an array to an object supporting fancy indexing -* -* @example -* var array2fancy = factory(); -* -* var x = [ 1, 2, 3, 4, 5, 6 ]; -* -* var y = array2fancy( x ); -* // returns -* -* var z = y[ '1::2' ]; -* // returns [ 2, 4, 6 ] -* -* var len = z.length; -* // returns 3 -* -* var v = z[ 0 ]; -* // returns 2 -* -* v = z[ 1 ]; -* // returns 4 -* -* v = z[ 2 ]; -* // returns 6 -*/ -function factory() { - var OPTIONS; - var err; - - OPTIONS = defaults(); - if ( arguments.length ) { - err = validate( OPTIONS, arguments[ 0 ] ); - if ( err ) { - throw err; - } - } - return array2fancy; - - /** - * Converts an array to an object supporting fancy indexing. - * - * @private - * @param {ArrayLike} x - input array - * @param {Options} [options] - function options - * @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking - * @param {Function} [options.cache] - cache for resolving array index objects - * @throws {TypeError} first argument must be array-like - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ArrayLike} fancy array - * - * @example - * var x = [ 1, 2, 3, 4, 5, 6 ]; - * - * var y = array2fancy( x ); - * // returns - * - * var z = y[ '1::2' ]; - * // returns [ 2, 4, 6 ] - * - * var len = z.length; - * // returns 3 - * - * var v = z[ 0 ]; - * // returns 2 - * - * v = z[ 1 ]; - * // returns 4 - * - * v = z[ 2 ]; - * // returns 6 - */ - function array2fancy( x ) { - var opts; - var err; - var arr; - var dt; - var o; - if ( !isArrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', x ) ); - } - if ( hasProxySupport ) { - opts = assign( {}, OPTIONS ); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - arr = arraylike2object( x ); - dt = arr.dtype || ''; - o = { - 'ref': x, - 'dtype': dt, - 'getter': arr.accessors[ 0 ], - 'setter': arr.accessors[ 1 ], - 'preSetElement': setElementWrapper( dt ), - 'postGetArray': getArrayWrapper( array2fancy, opts ), - 'cache': opts.cache, - 'strict': opts.strict, - 'validator': validator( dt ), - 'array2fancy': array2fancy, - 'ctor': new Proxy( x.constructor || Array, { - 'construct': ctor( array2fancy, opts ) - }) - }; - return new Proxy( x, { - 'get': get( o ), - 'set': set( o ) - }); - } - // TODO: replace with `@stdlib/console/warn` (or equivalent once available) - console.warn( 'WARNING: Proxy objects are not supported in the current environment. Some `FancyArray` functionality may not be available.' ); // eslint-disable-line no-console - return x; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/to-fancy/lib/get.js b/to-fancy/lib/get.js deleted file mode 100644 index 7df752c6..00000000 --- a/to-fancy/lib/get.js +++ /dev/null @@ -1,79 +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 hasProperty = require( '@stdlib/assert/has-property' ); -var isIntegerString = require( './is_integer_string.js' ); -var isArrayIndexString = require( './is_array_index_string.js' ); -var getElements = require( './get_elements.js' ); -var getElement = require( './get_element.js' ); -var getValue = require( './get_value.js' ); -var getSlice = require( './get_slice.js' ); - - -// MAIN // - -/** -* Returns a trap for retrieving property values. -* -* @private -* @param {Object} ctx - context object -* @param {Function} ctx.getter - accessor for retrieving array elements -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @param {Function} ctx.ctor - proxied array constructor -* @param {Function} ctx.postGetArray - function to process a retrieved array -* @param {Object} ctx.cache - cache for resolving array index objects -* @returns {Function} handler -*/ -function factory( ctx ) { - return get; - - /** - * Trap for retrieving property values. - * - * @private - * @param {Object} target - target object - * @param {(string|symbol)} property - property name - * @param {Object} receiver - the proxy object or an object inheriting from the proxy - * @throws {Error} invalid slice operation - * @throws {RangeError} slice exceeds array bounds - * @throws {RangeError} index exceeds array bounds - * @returns {*} result - */ - function get( target, property, receiver ) { - if ( isIntegerString( property ) ) { - return getElement( target, property, ctx ); - } - if ( hasProperty( target, property ) || !isString( property ) ) { - return getValue( target, property, receiver, ctx ); - } - if ( isArrayIndexString( property ) ) { - return getElements( target, property, ctx ); - } - return getSlice( target, property, ctx ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/to-fancy/lib/get_array_wrapper.js b/to-fancy/lib/get_array_wrapper.js deleted file mode 100644 index 32ee7e78..00000000 --- a/to-fancy/lib/get_array_wrapper.js +++ /dev/null @@ -1,51 +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'; - -// MAIN // - -/** -* Returns a wrapper function for processing arrays after retrieval. -* -* @private -* @param {Function} array2fancy - function for creating a proxied array -* @param {Object} opts - options -* @param {boolean} opts.strict - boolean indicating whether to perform strict bounds checking -* @param {Function} opts.cache - cache for resolving array index objects -* @returns {Function} wrapper function -*/ -function wrapper( array2fancy, opts ) { - return wrap; - - /** - * Returns a proxied array. - * - * @private - * @param {Array} x - input array - * @returns {Array} proxied array - */ - function wrap( x ) { - return array2fancy( x, opts ); - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/to-fancy/lib/get_element.js b/to-fancy/lib/get_element.js deleted file mode 100644 index 47e1d239..00000000 --- a/to-fancy/lib/get_element.js +++ /dev/null @@ -1,46 +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 resolveIndex = require( './resolve_index.js' ); - - -// MAIN // - -/** -* Returns the element associated with a specified index. -* -* @private -* @param {Object} target - target object -* @param {string} property - index string -* @param {Object} ctx - context object -* @param {Function} ctx.getter - accessor for retrieving array elements -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @returns {*} result -*/ -function getElement( target, property, ctx ) { - return ctx.getter( target, resolveIndex( property, target.length, ctx.strict ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = getElement; diff --git a/to-fancy/lib/get_elements.js b/to-fancy/lib/get_elements.js deleted file mode 100644 index 93c649bd..00000000 --- a/to-fancy/lib/get_elements.js +++ /dev/null @@ -1,62 +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 take = require( './../../take' ); -var mskfilter = require( './../../mskfilter' ); -var mskreject = require( './../../mskreject' ); -var format = require( '@stdlib/string/format' ); -var prop2array = require( './prop2array.js' ); - - -// MAIN // - -/** -* Returns the elements specified by an array index. -* -* @private -* @param {Object} target - target object -* @param {string} property - index string -* @param {Object} ctx - context object -* @param {Object} ctx.cache - cache for resolving array index objects -* @param {Function} ctx.postGetArray - function to process a retrieved array -* @throws {Error} invalid array index -* @throws {RangeError} index exceeds array bounds -* @returns {Collection} result -*/ -function getElements( target, property, ctx ) { - var idx = prop2array( property, ctx.cache ); - if ( idx.type === 'int' ) { - return ctx.postGetArray( take( target, idx.data ) ); - } - if ( idx.type === 'bool' ) { - return ctx.postGetArray( mskfilter( target, idx.data ) ); - } - if ( idx.type === 'mask' ) { - return ctx.postGetArray( mskreject( target, idx.data ) ); - } - throw new Error( format( 'invalid operation. Unrecognized array index type. Value: `%s`.', idx.type ) ); -} - - -// EXPORTS // - -module.exports = getElements; diff --git a/to-fancy/lib/get_slice.js b/to-fancy/lib/get_slice.js deleted file mode 100644 index 04f69284..00000000 --- a/to-fancy/lib/get_slice.js +++ /dev/null @@ -1,60 +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 slice = require( './../../base/fancy-slice' ); -var errMessage = require( './error_message.js' ); -var prop2slice = require( './prop2slice.js' ); - - -// MAIN // - -/** -* Returns a copy. -* -* @private -* @param {Object} target - target object -* @param {string} property - property name -* @param {Object} ctx - context object -* @param {Function} ctx.postGetArray - function to process a retrieved array -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @throws {Error} invalid slice operation -* @throws {RangeError} slice exceeds array bounds -* @returns {(Collection|void)} result -*/ -function getSlice( target, property, ctx ) { - var s = prop2slice( target, property, ctx.strict ); - if ( s === null ) { - // Ensure consistency with normal array behavior by returning `undefined` for any "unrecognized" property name: - return; - } - try { - return ctx.postGetArray( slice( target, s, ctx.strict ) ); - } catch ( err ) { - // In principle, we should only error when in "strict" mode and a slice exceeds array bounds... - throw new err.constructor( errMessage( err.message ) ); - } -} - - -// EXPORTS // - -module.exports = getSlice; diff --git a/to-fancy/lib/get_value.js b/to-fancy/lib/get_value.js deleted file mode 100644 index 84ac3951..00000000 --- a/to-fancy/lib/get_value.js +++ /dev/null @@ -1,70 +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 isFunction = require( '@stdlib/assert/is-function' ); - - -// MAIN // - -/** -* Returns the property value associated with a specified property. -* -* @private -* @param {Object} target - target object -* @param {(string|symbol)} property - property -* @param {Object} receiver - the proxy object or an object inheriting from the proxy -* @param {Object} ctx - context object -* @param {Function} ctx.ctor - proxied array constructor -* @returns {*} result -*/ -function getValue( target, property, receiver, ctx ) { - var value = target[ property ]; - if ( isFunction( value ) ) { - if ( value === target.constructor ) { - return ctx.ctor; - } - return wrapper; - } - return value; - - /** - * Method wrapper. - * - * @private - * @returns {*} results - */ - function wrapper() { - var args; - var i; - - args = []; - for ( i = 0; i < arguments.length; i++ ) { - args.push( arguments[ i ] ); - } - return value.apply( ( this === receiver ) ? target : this, args ); // eslint-disable-line no-invalid-this - } -} - - -// EXPORTS // - -module.exports = getValue; diff --git a/to-fancy/lib/has_proxy_support.js b/to-fancy/lib/has_proxy_support.js deleted file mode 100644 index 88b26b1b..00000000 --- a/to-fancy/lib/has_proxy_support.js +++ /dev/null @@ -1,40 +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 Proxy = require( '@stdlib/proxy/ctor' ); - - -// MAIN // - -/** -* Boolean indicating if an environment has Proxy support. -* -* @private -* @name hasSupport -* @type {boolean} -*/ -var hasSupport = ( typeof Proxy === 'function' ); // NOTE: cannot use `@stdlib/assert/has-proxy-support` here, as that API uses code evaluation and might violate CSPs; consequently, this is a relatively weak check for proxy support - - -// EXPORTS // - -module.exports = hasSupport; diff --git a/to-fancy/lib/index.js b/to-fancy/lib/index.js deleted file mode 100644 index 88895116..00000000 --- a/to-fancy/lib/index.js +++ /dev/null @@ -1,66 +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'; - -/** -* Convert an array to an object supporting fancy indexing. -* -* @module @stdlib/array/to-fancy -* -* @example -* var array2fancy = require( '@stdlib/array/to-fancy' ); -* -* var x = [ 1, 2, 3, 4, 5, 6 ]; -* -* var y = array2fancy( x ); -* // returns -* -* var z = y[ '1::2' ]; -* // returns [ 2, 4, 6 ] -* -* var len = z.length; -* // returns 3 -* -* var v = z[ 0 ]; -* // returns 2 -* -* v = z[ 1 ]; -* // returns 4 -* -* v = z[ 2 ]; -* // returns 6 -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var ArrayIndex = require( './../../index' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); -setReadOnly( main, 'idx', ArrayIndex ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-fancy/lib/is_array_index_string.js b/to-fancy/lib/is_array_index_string.js deleted file mode 100644 index be512b5d..00000000 --- a/to-fancy/lib/is_array_index_string.js +++ /dev/null @@ -1,51 +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 RE_ARRAY_INDEX = require( './re_array_index.js' ); - - -// MAIN // - -/** -* Tests if an indexing expression is a serialized array index. -* -* @private -* @param {(string|symbol)} prop - property name -* @returns {boolean} result -* -* @example -* var out = isArrayIndexString( 'ArrayIndex<0>' ); -* // returns true -* -* @example -* var out = isArrayIndexString( ':' ); -* // returns false -*/ -function isArrayIndexString( prop ) { - return ( isString( prop ) && RE_ARRAY_INDEX.test( prop ) ); -} - - -// EXPORTS // - -module.exports = isArrayIndexString; diff --git a/to-fancy/lib/is_integer_string.js b/to-fancy/lib/is_integer_string.js deleted file mode 100644 index 84a3d73e..00000000 --- a/to-fancy/lib/is_integer_string.js +++ /dev/null @@ -1,51 +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 RE_INTEGER = require( './re_integer.js' ); - - -// MAIN // - -/** -* Tests if an indexing expression is an integer. -* -* @private -* @param {(string|symbol)} prop - property name -* @returns {boolean} result -* -* @example -* var out = isIntegerString( '1' ); -* // returns true -* -* @example -* var out = isIntegerString( ':' ); -* // returns false -*/ -function isIntegerString( prop ) { - return ( isString( prop ) && RE_INTEGER.test( prop ) ); -} - - -// EXPORTS // - -module.exports = isIntegerString; diff --git a/to-fancy/lib/main.js b/to-fancy/lib/main.js deleted file mode 100644 index 024e7a74..00000000 --- a/to-fancy/lib/main.js +++ /dev/null @@ -1,68 +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 factory = require( './factory.js' ); - - -// MAIN // - -/** -* Converts an array to an object supporting fancy indexing. -* -* @name array2fancy -* @type {Function} -* @param {ArrayLike} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.strict=false] - boolean indicating whether to enforce strict bounds checking -* @param {Function} [options.cache] - cache for resolving array index objects -* @throws {TypeError} first argument must be array-like -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ArrayLike} fancy array -* -* @example -* var x = [ 1, 2, 3, 4, 5, 6 ]; -* -* var y = array2fancy( x ); -* // returns -* -* var z = y[ '1::2' ]; -* // returns [ 2, 4, 6 ] -* -* var len = z.length; -* // returns 3 -* -* var v = z[ 0 ]; -* // returns 2 -* -* v = z[ 1 ]; -* // returns 4 -* -* v = z[ 2 ]; -* // returns 6 -*/ -var array2fancy = factory(); - - -// EXPORTS // - -module.exports = array2fancy; diff --git a/to-fancy/lib/prop2array.js b/to-fancy/lib/prop2array.js deleted file mode 100644 index 18ddd1cd..00000000 --- a/to-fancy/lib/prop2array.js +++ /dev/null @@ -1,69 +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 trim = require( '@stdlib/string/base/trim' ); -var format = require( '@stdlib/string/format' ); - - -// FUNCTIONS // - -/** -* Extracts an array index identifier from an array index indexing expression. -* -* @private -* @param {string} str - input string -* @returns {string} identifier -* -* @example -* var str = 'ArrayIndex<0>'; -* -* var id = getIdentifier( str ); -* // returns '0' -*/ -function getIdentifier( str ) { - return str.substring( 11, str.length-1 ); // ArrayIndex => XX -} - - -// MAIN // - -/** -* Converts an indexing expression to an array index. -* -* @private -* @param {string} property - property name -* @param {Object} cache - cache for resolving array index objects -* @throws {Error} invalid array index -* @returns {(Object|null)} index object (or null) -*/ -function prop2array( property, cache ) { - var o = cache.get( getIdentifier( trim( property ) ) ); - if ( o === null ) { - throw new Error( format( 'invalid operation. Unable to resolve array index. Value: `%s`.', property ) ); - } - return o; -} - - -// EXPORTS // - -module.exports = prop2array; diff --git a/to-fancy/lib/prop2slice.js b/to-fancy/lib/prop2slice.js deleted file mode 100644 index 5d01a863..00000000 --- a/to-fancy/lib/prop2slice.js +++ /dev/null @@ -1,163 +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 trim = require( '@stdlib/string/base/trim' ); -var seq2slice = require( '@stdlib/slice/base/seq2slice' ); -var str2slice = require( '@stdlib/slice/base/str2slice' ); -var startsWith = require( '@stdlib/string/base/starts-with' ); -var format = require( '@stdlib/string/format' ); -var RE_SUBSEQ = require( './re_subseq.js' ); - - -// FUNCTIONS // - -/** -* Tests if an indexing expression is a serialized Slice object. -* -* @private -* @param {string} prop - property name -* @returns {boolean} result -* -* @example -* var out = isSlice( 'Slice(null,null,1)' ); -* // returns true -* -* @example -* var out = isSlice( ':' ); -* // returns false -*/ -function isSlice( prop ) { - return ( - prop[ 0 ] === 'S' && - startsWith( prop, 'Slice(', 0 ) && - prop[ prop.length-1 ] === ')' - ); -} - -/** -* Tests if an indexing expression is a subsequence. -* -* @private -* @param {string} prop - property name -* @returns {boolean} result -* -* @example -* var out = isSubsequence( '::-2' ); -* // returns true -* -* @example -* var out = isSubsequence( '-2' ); -* // returns false -*/ -function isSubsequence( prop ) { - // TODO: consider whether to make this check more robust (e.g., should we actually throw if someone tries to access `foo:bar`? If we make this check more exact, how would we distinguish between a non-existent `foo:bar` property and an actual error in the subsequence string?) - return RE_SUBSEQ.test( prop ); -} - -/** -* Parses a serialized Slice object. -* -* @private -* @param {string} raw - original unprocessed input string -* @param {string} str - serialized Slice object -* @throws {Error} invalid slice operation -* @returns {Slice} Slice object -* -* @example -* var s = parseSlice( ' Slice(null,null,1) ', 'Slice(null,null,1)' ); -* // returns -*/ -function parseSlice( raw, str ) { - var s = str2slice( str ); - if ( s === null ) { - throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', raw ) ); - } - return s; -} - -/** -* Parses a subsequence string. -* -* @private -* @param {string} raw - original unprocessed input string -* @param {string} str - subsequence string -* @param {NonNegativeInteger} max - index upper bound -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {Error} invalid slice operation -* @throws {RangeError} slice exceeds array bounds -* @returns {Slice} Slice object -* -* @example -* var s = parseSubsequence( ' ::-2 ', '::-2', 10, false ); -* // returns -*/ -function parseSubsequence( raw, str, max, strict ) { - var s = seq2slice( str, max, true ); - if ( s.code ) { - if ( s.code === 'ERR_SLICE_INVALID_INCREMENT' ) { - throw new Error( format( 'invalid operation. A subsequence increment must be a non-zero integer. Value: `%s`.', raw ) ); - } - if ( s.code === 'ERR_SLICE_INVALID_SUBSEQUENCE' ) { - throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', raw ) ); - } - // NOTE: the following error check must come last due to fall-through when in non-strict mode... - if ( s.code === 'ERR_SLICE_OUT_OF_BOUNDS' ) { - if ( strict ) { - throw new RangeError( format( 'invalid operation. Slice exceeds array bounds.' ) ); - } - // Repeat parsing, this time allowing for out-of-bounds slices: - s = seq2slice( str, max, false ); - } - } - return s; -} - - -// MAIN // - -/** -* Converts an indexing expression to a Slice object. -* -* @private -* @param {Object} target - target object -* @param {string} property - property name -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {Error} invalid slice operation -* @throws {RangeError} slice exceeds array bounds -* @returns {(Slice|null)} slice object (or null) -*/ -function prop2slice( target, property, strict ) { - var prop = trim( property ); - if ( isSlice( prop ) ) { - return parseSlice( property, prop ); - } - if ( isSubsequence( prop ) ) { - return parseSubsequence( property, prop, target.length, strict ); - } - // Everything else (including undefined/non-existent properties): - return null; -} - - -// EXPORTS // - -module.exports = prop2slice; diff --git a/to-fancy/lib/re_array_index.js b/to-fancy/lib/re_array_index.js deleted file mode 100644 index 10046eaa..00000000 --- a/to-fancy/lib/re_array_index.js +++ /dev/null @@ -1,47 +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'; - -// MAIN // - -/** -* Regular expression for testing whether a string is a serialized array index. -* -* @private -* @name RE_ARRAY_INDEX -* @type {RegExp} -* -* @example -* var bool = RE_ARRAY_INDEX.test( 'ArrayIndex<0>' ); -* // returns true -* -* @example -* var bool = RE_ARRAY_INDEX.test( '0' ); -* // returns false -* -* @example -* var bool = RE_ARRAY_INDEX.test( 'Slice(0,10,2)' ); -* // returns false -*/ -var RE_ARRAY_INDEX = /\s*ArrayIndex<[^>]+>\s*/; - - -// EXPORTS // - -module.exports = RE_ARRAY_INDEX; diff --git a/to-fancy/lib/re_integer.js b/to-fancy/lib/re_integer.js deleted file mode 100644 index e1ae210d..00000000 --- a/to-fancy/lib/re_integer.js +++ /dev/null @@ -1,47 +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'; - -// MAIN // - -/** -* Regular expression for testing whether a string is an integer string. -* -* @private -* @name RE_INTEGER -* @type {RegExp} -* -* @example -* var bool = RE_INTEGER.test( '10' ); -* // returns true -* -* @example -* var bool = RE_INTEGER.test( '-1' ); -* // returns true -* -* @example -* var bool = RE_INTEGER.test( '0:10:2' ); -* // returns false -*/ -var RE_INTEGER = /^-?[0-9]+$/; - - -// EXPORTS // - -module.exports = RE_INTEGER; diff --git a/to-fancy/lib/re_subseq.js b/to-fancy/lib/re_subseq.js deleted file mode 100644 index 6457c3ec..00000000 --- a/to-fancy/lib/re_subseq.js +++ /dev/null @@ -1,47 +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'; - -// MAIN // - -/** -* Regular expression for testing whether a string is a subsequence string. -* -* @private -* @name RE_SUBSEQ -* @type {RegExp} -* -* @example -* var bool = RE_SUBSEQ.test( '0:10:2' ); -* // returns true -* -* @example -* var bool = RE_SUBSEQ.test( '0' ); -* // returns false -* -* @example -* var bool = RE_SUBSEQ.test( 'Slice(0,10,2)' ); -* // returns false -*/ -var RE_SUBSEQ = /:/; - - -// EXPORTS // - -module.exports = RE_SUBSEQ; diff --git a/to-fancy/lib/resolve_index.js b/to-fancy/lib/resolve_index.js deleted file mode 100644 index a5861dd6..00000000 --- a/to-fancy/lib/resolve_index.js +++ /dev/null @@ -1,66 +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 normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Resolves an integer index from an integer string. -* -* @private -* @param {string} str - integer string -* @param {NonNegativeInteger} max - index upper bound (exclusive) -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} index exceeds array bounds -* @returns {integer} integer index -* -* @example -* var idx = resolveIndex( '-1', 10, false ); -* // returns 9 -* -* @example -* var idx = resolveIndex( '-20', 10, false ); -* // returns -20 -*/ -function resolveIndex( str, max, strict ) { - var idx; - var i; - - idx = parseInt( str, 10 ); - i = normalizeIndex( idx, max-1 ); - if ( i === -1 ) { - if ( strict ) { - throw new RangeError( format( 'invalid operation. Index exceeds array bounds.' ) ); - } - // Return the non-normalized index, as this should fallback to default property handling and returning "undefined": - return idx; - } - return i; -} - - -// EXPORTS // - -module.exports = resolveIndex; diff --git a/to-fancy/lib/set.js b/to-fancy/lib/set.js deleted file mode 100644 index df65012d..00000000 --- a/to-fancy/lib/set.js +++ /dev/null @@ -1,91 +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 hasProperty = require( '@stdlib/assert/has-property' ); -var isIntegerString = require( './is_integer_string.js' ); -var isArrayIndexString = require( './is_array_index_string.js' ); -var setElements = require( './set_elements.js' ); -var setElement = require( './set_element.js' ); -var setValue = require( './set_value.js' ); -var setSlice = require( './set_slice.js' ); - - -// MAIN // - -/** -* Returns a trap for setting property values. -* -* @private -* @param {Object} ctx - context object -* @param {Function} ctx.setter - accessor for setting array elements -* @param {string} ctx.dtype - array data type -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @param {Function} ctx.validator - function for validating new values -* @param {Function} ctx.setter - accessor for setting array elements -* @param {(Function|null)} ctx.preSetElement - function for normalizing new values (if necessary) -* @returns {Function} handler -*/ -function factory( ctx ) { - return set; - - /** - * Trap for setting property values. - * - * @private - * @param {Object} target - target object - * @param {(string|symbol)} property - property name - * @param {*} value - new value - * @param {Object} receiver - the proxy object or an object inheriting from the proxy - * @throws {Error} invalid slice operation - * @throws {Error} assigned value must be broadcast compatible with output array view - * @throws {TypeError} assigned value cannot be safely cast to the output array data type - * @throws {TypeError} slice exceeds array bounds - * @throws {TypeError} index exceeds array bounds - * @returns {boolean} boolean indicating whether assignment succeeded - */ - function set( target, property, value, receiver ) { - var out; - - // Note that we need to check for an integer string *before* checking for an own property, as we want to explicitly handle *all* indexed properties, not just negative integers, in order to perform assignment validation... - if ( isIntegerString( property ) ) { - return setElement( target, property, value, ctx ); - } - if ( hasProperty( property ) || !isString( property ) ) { - return setValue( target, property, value, ctx ); - } - if ( isArrayIndexString( property ) ) { - return setElements( target, property, value, ctx ); - } - out = setSlice( target, property, value, receiver, ctx ); - if ( out ) { - return out; - } - // If we were unsuccessful (e.g., due to an invalid subsequence, etc), set the "property" in the same way as would any normal property (e.g., if an indexing expression is an invalid subsequence, assign as would a regular property: `i = 'a:b:c'` => `x[i] = 1` => `v = x[i]` => `v === 1`): - return setValue( target, property, value, ctx ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/to-fancy/lib/set_element.js b/to-fancy/lib/set_element.js deleted file mode 100644 index fb2946cc..00000000 --- a/to-fancy/lib/set_element.js +++ /dev/null @@ -1,65 +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 resolveIndex = require( './resolve_index.js' ); - - -// MAIN // - -/** -* Sets the element associated with a specified index. -* -* @private -* @param {Object} target - target object -* @param {string} property - index string -* @param {*} value - new value -* @param {Object} ctx - context object -* @param {Function} ctx.setter - accessor for setting array elements -* @param {string} ctx.dtype - target array data type -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @param {Function} ctx.validator - function for validating new values -* @param {(Function|null)} ctx.preSetElement - function for normalizing new values (if necessary) -* @throws {TypeError} assigned value cannot be safely cast to the target array data type -* @throws {TypeError} target array must have a supported data type -* @returns {boolean} boolean indicating whether assignment succeeded -*/ -function setElement( target, property, value, ctx ) { - var err; - var v; - - err = ctx.validator( value, ctx.dtype ); - if ( err ) { - throw err; - } - if ( ctx.preSetElement ) { - v = ctx.preSetElement( value ); - } else { - v = value; - } - ctx.setter( target, resolveIndex( property, target.length, ctx.strict ), v ); // eslint-disable-line max-len - return true; -} - - -// EXPORTS // - -module.exports = setElement; diff --git a/to-fancy/lib/set_element_wrapper.js b/to-fancy/lib/set_element_wrapper.js deleted file mode 100644 index c06b7216..00000000 --- a/to-fancy/lib/set_element_wrapper.js +++ /dev/null @@ -1,65 +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 isComplexDataType = require( './../../base/assert/is-complex-floating-point-data-type' ); -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; - - -// FUNCTIONS // - -/** -* Normalizes values assigned to complex number arrays. -* -* @private -* @param {*} value - input value -* @returns {(ComplexLike|*)} output value -*/ -function wrapComplex( value ) { - // Wrap real-valued scalars as valid input arguments to complex number arrays... - if ( isNumber( value ) ) { - return [ value, 0.0 ]; // note: we're assuming that a ComplexXXArray setter accepts an array of interleaved real and imaginary components - } - // For everything other than a real-valued scalar, we delegate validation to the target complex number array: - return value; -} - - -// MAIN // - -/** -* Returns a wrapper function for processing scalar input values before assignment. -* -* @private -* @param {string} dtype - array data type -* @returns {(Function|null)} wrapper function or null -*/ -function wrapper( dtype ) { - if ( isComplexDataType( dtype ) ) { - return wrapComplex; - } - return null; -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/to-fancy/lib/set_elements.js b/to-fancy/lib/set_elements.js deleted file mode 100644 index fb516208..00000000 --- a/to-fancy/lib/set_elements.js +++ /dev/null @@ -1,130 +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 isMostlySafeCast = require( './../../base/assert/is-mostly-safe-data-type-cast' ); -var isRealDataType = require( './../../base/assert/is-real-data-type' ); -var isComplexDataType = require( './../../base/assert/is-complex-floating-point-data-type' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var scalar2array = require( './../../from-scalar' ); -var dtype = require( './../../dtype' ); -var put = require( './../../put' ); -var place = require( './../../place' ); -var convert = require( './../../convert' ); -var where = require( './../../base/where' ).assign; -var format = require( '@stdlib/string/format' ); -var prop2array = require( './prop2array.js' ); -var errMessage = require( './error_message.js' ); - - -// MAIN // - -/** -* Replaces the elements specified by an array index. -* -* @private -* @param {Object} target - target object -* @param {string} property - index string -* @param {*} value - new value(s) -* @param {Object} ctx - context object -* @param {string} ctx.dtype - array data type -* @param {Object} ctx.cache - cache for resolving array index objects -* @param {Function} ctx.validator - function for validating new values -* @param {(Function|null)} ctx.preSetElement - function for normalizing new values (if necessary) -* @throws {Error} invalid array index -* @throws {RangeError} index exceeds array bounds -* @throws {Error} assigned value must be broadcast compatible with target array selection -* @throws {TypeError} assigned value cannot be safely cast to the target array data type -* @throws {TypeError} target array must have a supported data type -* @returns {boolean} boolean indicating whether assignment succeeded -*/ -function setElements( target, property, value, ctx ) { - var tdt; - var vdt; - var idx; - var err; - var v; - - idx = prop2array( property, ctx.cache ); - tdt = ctx.dtype || 'generic'; - if ( isCollection( value ) ) { - // When handling collections, we delegate to implementation APIs (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here: - v = value; - } else { - // When provided a "scalar", we need to check whether the value can be safely cast to the target array data type: - err = ctx.validator( value, tdt ); - if ( err ) { - throw err; - } - if ( ctx.preSetElement ) { - v = ctx.preSetElement( value ); - } else { - v = value; - } - // As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during assignment: - v = scalar2array( v, tdt ); - vdt = tdt; - } - if ( idx.type === 'int' ) { - try { - put( target, idx.data, v ); // note: defer to `put` for ensuring a mostly safe cast - } catch ( err ) { - throw new err.constructor( errMessage( err.message ) ); - } - return true; - } - if ( idx.type === 'bool' ) { - try { - place( target, idx.data, v, { - 'mode': 'strict_broadcast' - }); - } catch ( err ) { - throw new err.constructor( errMessage( err.message ) ); - } - return true; - } - if ( vdt === void 0 ) { - vdt = dtype( value ) || 'generic'; - } - // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point... - if ( !isMostlySafeCast( vdt, tdt ) ) { - throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, tdt ) ); - } - // When performing a real-to-complex assignment, interpret the real-valued array as containing real components with implied imaginary components equal to zero and explicitly convert to a complex-valued array... - if ( isComplexDataType( tdt ) && isRealDataType( vdt ) ) { - v = convert( v, tdt ); - } - if ( idx.type === 'mask' ) { - // NOTE: we intentionally deviate from boolean array indexing here and interpret the mask as applying to both the target and values array, thus requiring that the assigned value array be broadcast compatible with the target array and NOT just the selected elements as in boolean array indexing - try { - where( idx.data, target, v, target, 1, 0 ); - } catch ( err ) { - throw new err.constructor( errMessage( err.message ) ); - } - return true; - } - throw new Error( format( 'invalid operation. Unrecognized array index type. Value: `%s`.', idx.type ) ); -} - - -// EXPORTS // - -module.exports = setElements; diff --git a/to-fancy/lib/set_slice.js b/to-fancy/lib/set_slice.js deleted file mode 100644 index 2f18383b..00000000 --- a/to-fancy/lib/set_slice.js +++ /dev/null @@ -1,84 +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 isCollection = require( '@stdlib/assert/is-collection' ); -var sliceAssign = require( './../../base/fancy-slice-assign' ); -var scalar2array = require( './../../from-scalar' ); -var prop2slice = require( './prop2slice.js' ); -var errMessage = require( './error_message.js' ); - - -// MAIN // - -/** -* Sets element values belonging to the array view specified by an indexing expression. -* -* @private -* @param {Object} target - target object -* @param {string} property - indexing expression -* @param {*} value - new value -* @param {Object} receiver - the proxy object or an object inheriting from the proxy -* @param {Object} ctx - context object -* @param {string} ctx.dtype - array data type -* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking -* @param {Function} ctx.validator - function for validating new values -* @throws {Error} invalid slice operation -* @throws {RangeError} slice exceeds array bounds -* @throws {Error} assigned value must be broadcast compatible with target array view -* @throws {TypeError} assigned value cannot be safely cast to the target array data type -* @throws {TypeError} target array must have a supported data type -* @returns {boolean} boolean indicating whether assignment succeeded -*/ -function setSlice( target, property, value, receiver, ctx ) { - var err; - var s; - var v; - - s = prop2slice( target, property, ctx.strict ); - if ( s === null ) { - // If unable to parse the property as an indexing expression, signal that we were unable to perform slice assignment: - return false; - } - if ( isCollection( value ) ) { - // When handling collections, we delegate to `sliceAssign` (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here: - v = value; - } else { - // When provided a "scalar", we need to check whether the value can be safely cast to the target array data type: - err = ctx.validator( value, ctx.dtype ); - if ( err ) { - throw err; - } - // As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during slice assignment: - v = scalar2array( value, ctx.dtype || 'generic' ); - } - try { - sliceAssign( v, receiver, s, ctx.strict ); - } catch ( err ) { - throw new err.constructor( errMessage( err.message ) ); - } - return true; -} - - -// EXPORTS // - -module.exports = setSlice; diff --git a/to-fancy/lib/set_value.js b/to-fancy/lib/set_value.js deleted file mode 100644 index 1bdb801c..00000000 --- a/to-fancy/lib/set_value.js +++ /dev/null @@ -1,40 +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'; - -// MAIN // - -/** -* Sets the value associated with a specified property. -* -* @private -* @param {Object} target - target object -* @param {string} property - property -* @param {*} value - new value -* @returns {boolean} boolean indicating whether assignment succeeded -*/ -function setValue( target, property, value ) { - target[ property ] = value; - return true; -} - - -// EXPORTS // - -module.exports = setValue; diff --git a/to-fancy/lib/validate.js b/to-fancy/lib/validate.js deleted file mode 100644 index 84510e40..00000000 --- a/to-fancy/lib/validate.js +++ /dev/null @@ -1,74 +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 isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isMethodIn = require( '@stdlib/assert/is-method-in' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @param {Function} [options.cache] - cache for resolving array index objects -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'strict': false -* }; -* 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, 'strict' ) ) { - opts.strict = options.strict; - if ( !isBoolean( opts.strict ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', opts.strict ) ); - } - } - if ( hasOwnProp( options, 'cache' ) ) { - opts.cache = options.cache; - if ( !isMethodIn( opts.cache, 'get' ) ) { - return new TypeError( format( 'invalid option. `%s` option is missing a `%s` method. Option: `%s`.', 'cache', 'get', opts.cache ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/to-fancy/lib/validator.js b/to-fancy/lib/validator.js deleted file mode 100644 index c34b0456..00000000 --- a/to-fancy/lib/validator.js +++ /dev/null @@ -1,241 +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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; -var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isComplexLike = require( '@stdlib/assert/is-complex-like' ); -var isRealFloatingDataType = require( './../../base/assert/is-real-floating-point-data-type' ); -var isUnsignedIntegerDataType = require( './../../base/assert/is-unsigned-integer-data-type' ); -var isSignedIntegerDataType = require( './../../base/assert/is-signed-integer-data-type' ); -var isBooleanDataType = require( './../../base/assert/is-boolean-data-type' ); -var isSafeCast = require( './../../base/assert/is-safe-data-type-cast' ); -var minDataType = require( './../../min-dtype' ); -var minSignedIntegerDataType = require( './../../base/min-signed-integer-dtype' ); -var complexDataType = require( '@stdlib/complex/dtype' ); -var format = require( '@stdlib/string/format' ); - - -// FUNCTIONS // - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having a "generic" or unknown data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {null} null -* -* @example -* var err = validateGeneric( 3, 'generic' ); -* // returns null -*/ -function validateGeneric() { - return null; -} - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having a boolean data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {(Error|null)} error object or null -* -* @example -* var err = validateBoolean( true, 'bool' ); -* // returns null -* -* @example -* var Complex128 = require( '@stdlib/complex/float64/ctor' ); -* -* var err = validateBoolean( new Complex128( 5.0, 6.0 ), 'bool' ); -* // returns -*/ -function validateBoolean( value, dtype ) { - if ( isBoolean( value ) ) { - return null; - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) ); -} - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having a real-valued floating-point data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {(Error|null)} error object or null -* -* @example -* var err = validateRealFloating( 3.14, 'float64' ); -* // returns null -* -* @example -* var Complex128 = require( '@stdlib/complex/float64/ctor' ); -* -* var err = validateRealFloating( new Complex128( 5.0, 6.0 ), 'float64' ); -* // returns -*/ -function validateRealFloating( value, dtype ) { - if ( isNumber( value ) ) { - return null; - } - if ( isComplexLike( value ) ) { - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) ); - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) ); -} - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having a complex-valued floating-point data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {(Error|null)} error object or null -* -* @example -* var Complex128 = require( '@stdlib/complex/float64/ctor' ); -* -* var err = validateComplexFloating( new Complex128( 5.0, 6.0 ), 'complex128' ); -* // returns null -* -* @example -* var err = validateComplexFloating( {}, 'complex128' ); -* // returns -*/ -function validateComplexFloating( value, dtype ) { - if ( isNumber( value ) || isComplexLike( value ) ) { - return null; - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) ); -} - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having a signed integer data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {(Error|null)} error object or null -* -* @example -* var err = validateSignedInteger( 3, 'int32' ); -* // returns null -* -* @example -* var err = validateSignedInteger( 3.14, 'int32' ); -* // returns -*/ -function validateSignedInteger( value, dtype ) { - var vdt; - if ( isNumber( value ) ) { - if ( !isInteger( value ) ) { - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', minDataType( value ), dtype ) ); - } - vdt = minSignedIntegerDataType( value ); - if ( isSafeCast( vdt, dtype ) ) { - return null; - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dtype ) ); - } - if ( isComplexLike( value ) ) { - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) ); - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) ); -} - -/** -* Verifies whether a provided value can be safely assigned to an element in an array having an unsigned integer data type. -* -* @private -* @param {*} value - input value -* @param {string} dtype - array data type -* @returns {(Error|null)} error object or null -* -* @example -* var err = validateUnsignedInteger( 3, 'uint32' ); -* // returns null -* -* @example -* var err = validateUnsignedInteger( -3, 'uint32' ); -* // returns -*/ -function validateUnsignedInteger( value, dtype ) { - var vdt; - if ( isNumber( value ) ) { - vdt = minDataType( value ); // note: we rely on data type resolution to handle the case where `value` is a non-integer value. In that case, `vdt` will resolve to a floating-point data type and `isSafeCast` will evaluate to `false` - if ( isSafeCast( vdt, dtype ) ) { - return null; - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, dtype ) ); - } - if ( isComplexLike( value ) ) { - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', complexDataType( value ), dtype ) ); - } - return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) ); -} - - -// MAIN // - -/** -* Returns a validation function for verifying whether a provided value can be safely assigned to an element in an array having a specified data type. -* -* @private -* @param {string} dtype - array data type -* @returns {Function} validation function -* -* @example -* var fcn = validator( 'int32' ); -* -* var err = fcn( 3, 'int32' ); -* // returns null -* -* err = fcn( 3.14, 'int32' ); -* // returns -*/ -function validator( dtype ) { - if ( dtype === 'generic' || dtype === '' ) { - return validateGeneric; - } - if ( isRealFloatingDataType( dtype ) ) { - return validateRealFloating; - } - if ( isUnsignedIntegerDataType( dtype ) ) { - return validateUnsignedInteger; - } - if ( isSignedIntegerDataType( dtype ) ) { - return validateSignedInteger; - } - if ( isBooleanDataType( dtype ) ) { - return validateBoolean; - } - // Case: isComplexDataType( dtype ) === true - return validateComplexFloating; -} - - -// EXPORTS // - -module.exports = validator; diff --git a/to-fancy/package.json b/to-fancy/package.json deleted file mode 100644 index f05f824e..00000000 --- a/to-fancy/package.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "name": "@stdlib/array/to-fancy", - "version": "0.0.0", - "description": "Convert an array to an object supporting fancy indexing.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "array", - "fancy", - "subsequence", - "subseq", - "slice", - "indexing", - "index", - "vector" - ] -} diff --git a/to-fancy/test/test.factory.js b/to-fancy/test/test.factory.js deleted file mode 100644 index 2410bfd8..00000000 --- a/to-fancy/test/test.factory.js +++ /dev/null @@ -1,143 +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 tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var Int32Array = require( './../../int32' ); -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 throws an error if provided a first argument which is not an object', 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 an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - 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({ - 'strict': value - }); - }; - } -}); - -tape( 'the function returns a function which returns an array-like object', function test( t ) { - var array2fancy; - var x; - var y; - - array2fancy = factory(); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - t.strictEqual( y instanceof Array, true, 'returns expected value' ); - t.notEqual( y, x, 'different reference' ); - t.deepEqual( y, x, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment does not support Proxy objects, the function returns a function which returns the input array (generic)', function test( t ) { - var array2fancy; - var factory; - var x; - var y; - - factory = proxyquire( './../lib/factory.js', { - './has_proxy_support.js': false - }); - array2fancy = factory(); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - t.strictEqual( y, x, 'returns expected value' ); - t.end(); -}); - -tape( 'if an environment does not support Proxy objects, the function returns a function which returns the input array (typed)', function test( t ) { - var array2fancy; - var factory; - var x; - var y; - - factory = proxyquire( './../lib/factory.js', { - './has_proxy_support.js': false - }); - array2fancy = factory(); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - t.strictEqual( y, x, 'returns expected value' ); - t.end(); -}); diff --git a/to-fancy/test/test.get.boolean_array.js b/to-fancy/test/test.get.boolean_array.js deleted file mode 100644 index bbf34b93..00000000 --- a/to-fancy/test/test.get.boolean_array.js +++ /dev/null @@ -1,430 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array indexing (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ false, false, false, false ] ); - expected = []; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ true, true, false, false ] ); - expected = [ 1, 2 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 2, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ true, false, true, false ] ); - expected = [ 1, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array indexing (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ false, false, false, false ] ); - expected = new Int32Array( [] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ true, true, false, false ] ); - expected = new Int32Array( [ 1, 2 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Int32Array( [ 2, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ true, false, true, false ] ); - expected = new Int32Array( [ 1, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array indexing and returning arrays which can themselves support boolean arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ true, false, true, false ] ); - expected = [ 1, 3 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ false, true ] ); - expected = [ 3 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array indexing and returning arrays which can themselves support boolean arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ true, false, true, false ] ); - expected = new Int32Array( [ 1, 3 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ false, true ] ); - expected = new Int32Array( [ 3 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error if provided a boolean array index having an incompatible number of elements (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - array2fancy.idx( [ true, false ] ), - array2fancy.idx( [ true, true, true ] ), - array2fancy.idx( [ true, false, true, false, true ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error if provided a boolean array index having an incompatible number of elements (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - array2fancy.idx( [ true, false ] ), - array2fancy.idx( [ true, true, true ] ), - array2fancy.idx( [ true, false, true, false, true ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': false - }); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': false - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - expected = [ 1, 2, 3, 4 ]; - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.get.integer_array.js b/to-fancy/test/test.get.integer_array.js deleted file mode 100644 index 0b42cbec..00000000 --- a/to-fancy/test/test.get.integer_array.js +++ /dev/null @@ -1,596 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array indexing (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ 3, 1, 2, 0, 0, 1 ] ); - expected = [ 4, 2, 3, 1, 1, 2 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [] ); - expected = []; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [] ) ); - expected = []; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ 0, 1 ] ); - expected = [ 1, 2 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [ 1, 2 ] ) ); - expected = [ 2, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 1, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [ -1, -3 ] ) ); - expected = [ 4, 2 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array indexing (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ 3, 1, 2, 0, 0, 1 ] ); - expected = new Int32Array( [ 4, 2, 3, 1, 1, 2 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [] ); - expected = new Int32Array( [] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [] ) ); - expected = new Int32Array( [] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ 0, 1 ] ); - expected = new Int32Array( [ 1, 2 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Int32Array( [ 2, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Int32Array( [ 1, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Int32Array( [ -1, -3 ] ) ); - expected = new Int32Array( [ 4, 2 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'by default, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an index which is out-of-bounds (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - values = [ - array2fancy.idx( [ 10, 20 ] ), - array2fancy.idx( [ -20, -10 ] ), - array2fancy.idx( new Int32Array( [ -20] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object supporting integer array indexing and returning arrays which themselves support integer arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ -4, -2 ] ); - expected = [ 1, 3 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Int32Array( [ 1, 0 ] ) ); - expected = [ 3, 1 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array indexing and returning arrays which themselves support integer arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( [ -4, -2 ] ); - expected = new Int32Array( [ 1, 3 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Int32Array( [ 1, 0 ] ) ); - expected = new Int32Array( [ 3, 1 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': false - }); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': false - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - expected = [ 1, 2, 3, 4 ]; - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.get.integers.js b/to-fancy/test/test.get.integers.js deleted file mode 100644 index 23f09414..00000000 --- a/to-fancy/test/test.get.integers.js +++ /dev/null @@ -1,330 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element retrieval (generic, positive integers)', function test( t ) { - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element retrieval (typed, positive integers)', function test( t ) { - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element retrieval (generic, negative integers)', opts, function test( t ) { - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i-x.length ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element retrieval (typed, negative integers)', opts, function test( t ) { - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i-x.length ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (generic, positive integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (typed, positive integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (generic, negative integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (typed, negative integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (generic, positive integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (typed, positive integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (generic, negative integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns `undefined` when provided an integer index which is out-of-bounds (typed, negative integers)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (generic, positive integers)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (typed, positive integers)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (generic, negative integers)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (typed, negative integers)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); diff --git a/to-fancy/test/test.get.invalid.js b/to-fancy/test/test.get.invalid.js deleted file mode 100644 index ccaa5217..00000000 --- a/to-fancy/test/test.get.invalid.js +++ /dev/null @@ -1,285 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var Uint8Array = require( './../../uint8' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized slice (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'Slice(a,b,c)', - 'Slice(1.5)', - 'Slice(0,1,0)' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized slice (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'Slice(a,b,c)', - 'Slice(1.5)', - 'Slice(0,1,0)' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid subsequence indexing expression (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'a:b:c', - ':1.5', - '0:1:0', - ':::', - '0:1:1:2' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid subsequence indexing expression (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'a:b:c', - ':1.5', - '0:1:0', - ':::', - '0:1:1:2' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized array index (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'ArrayIndex<9999999>', - 'ArrayIndex<9999999999>' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized array index (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'ArrayIndex<9999999>', - 'ArrayIndex<9999999999>' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'cache': { - 'get': get - } - }); - - values = [ - array2fancy.idx( [ 0, 1, 2, 3 ] ), - array2fancy.idx( [ true, false, true, false ] ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } - - function get() { - return { - 'data': [], - 'type': 'beep', - 'dtype': 'generic' - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'cache': { - 'get': get - } - }); - - values = [ - array2fancy.idx( [ 0, 1, 2, 3 ] ), - array2fancy.idx( [ true, false, true, false ] ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } - - function get() { - return { - 'data': [], - 'type': 'beep', - 'dtype': 'generic' - }; - } -}); diff --git a/to-fancy/test/test.get.mask_array.js b/to-fancy/test/test.get.mask_array.js deleted file mode 100644 index ff7f6e3b..00000000 --- a/to-fancy/test/test.get.mask_array.js +++ /dev/null @@ -1,431 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var Uint8Array = require( './../../uint8' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array indexing (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 1, 1, 1 ] ) ); - expected = []; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 1, 2 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 2, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 1, 3 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array indexing (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 1, 1, 1 ] ) ); - expected = new Int32Array( [] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Int32Array( [ 1, 2 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Int32Array( [ 2, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 3 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array indexing and returning arrays which can themselves support mask arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 1, 3 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Uint8Array( [ 1, 0 ] ) ); - expected = [ 3 ]; - actual = z[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array indexing and returning arrays which can themselves support mask arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - var z; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 3 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - idx = array2fancy.idx( new Uint8Array( [ 1, 0 ] ) ); - expected = new Int32Array( [ 3 ] ); - actual = z[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error if provided a mask array index having an incompatible number of elements (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - array2fancy.idx( new Uint8Array( [ 0, 1 ] ) ), - array2fancy.idx( new Uint8Array( [ 0, 0, 0 ] ) ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1, 0 ] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error if provided a mask array index having an incompatible number of elements (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - array2fancy.idx( new Uint8Array( [ 0, 1 ] ) ), - array2fancy.idx( new Uint8Array( [ 0, 0, 0 ] ) ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1, 0 ] ) ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': false - }); - expected = [ 1, 2, 3, 4 ]; - actual = y[ idx ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': false - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ idx ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - expected = [ 1, 2, 3, 4 ]; - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var actual; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = y[ idx ]; - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.get.properties.js b/to-fancy/test/test.get.properties.js deleted file mode 100644 index 63a0ca0a..00000000 --- a/to-fancy/test/test.get.properties.js +++ /dev/null @@ -1,72 +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 tape = require( 'tape' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting expected property access (generic)', function test( t ) { - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - x.foo = 'a'; - x.bar = 'b'; - - y = array2fancy( x ); - - t.strictEqual( y.foo, x.foo, 'returns expected value' ); - t.strictEqual( y.bar, x.bar, 'returns expected value' ); - t.strictEqual( y.length, x.length, 'returns expected value' ); - t.strictEqual( y.beep, void 0, 'returns expected value' ); - t.strictEqual( y.boop, void 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting expected property access (typed)', function test( t ) { - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - x.foo = 'a'; - x.bar = 'b'; - - y = array2fancy( x ); - - t.strictEqual( y.foo, x.foo, 'returns expected value' ); - t.strictEqual( y.bar, x.bar, 'returns expected value' ); - t.strictEqual( y.length, x.length, 'returns expected value' ); - t.strictEqual( y.beep, void 0, 'returns expected value' ); - t.strictEqual( y.boop, void 0, 'returns expected value' ); - - t.end(); -}); diff --git a/to-fancy/test/test.get.slice.js b/to-fancy/test/test.get.slice.js deleted file mode 100644 index bb9db4c6..00000000 --- a/to-fancy/test/test.get.slice.js +++ /dev/null @@ -1,437 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Slice = require( '@stdlib/slice/ctor' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting slices (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 1, 2, 3, 4 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( 2 ); - expected = [ 1, 2 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( 1, 3 ); - expected = [ 2, 3 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( null, null, 2 ); - expected = [ 1, 3 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -1, null, -2 ); - expected = [ 4, 2 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slices (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( 2 ); - expected = new Int32Array( [ 1, 2 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( 1, 3 ); - expected = new Int32Array( [ 2, 3 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 1, 3 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -1, null, -2 ); - expected = new Int32Array( [ 4, 2 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns an empty array when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = []; - - s = new Slice( 10, 20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20, -10 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns an empty array when provided a slice which is out-of-bounds (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [] ); - - s = new Slice( 10, 20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20, -10 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns an empty array when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - expected = []; - - s = new Slice( 10, 20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20, -10 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns an empty array when provided a slice which is out-of-bounds (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - expected = new Int32Array( [] ); - - s = new Slice( 10, 20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20, -10 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = new Slice( -20 ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = new Slice( x.length+i, x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (typed)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = new Slice( x.length+i, x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an array-like object supporting slices which can themselves support slices (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var z; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 1, 3 ] ); - actual = z[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - s = new Slice( null, null, -1 ); - expected = new Int32Array( [ 3, 1 ] ); - actual = z[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slices which can themselves support slices (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var z; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 1, 2, 3, 4 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - s = new Slice( null, null, 2 ); - expected = [ 1, 3 ]; - actual = z[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - s = new Slice( null, null, -1 ); - expected = [ 3, 1 ]; - actual = z[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.notEqual( actual, z, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/to-fancy/test/test.get.subsequence.js b/to-fancy/test/test.get.subsequence.js deleted file mode 100644 index 35bfbc63..00000000 --- a/to-fancy/test/test.get.subsequence.js +++ /dev/null @@ -1,342 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting subsequence indexing expressions (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = ':'; - expected = [ 1, 2, 3, 4 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':2'; - expected = [ 1, 2 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '1:3'; - expected = [ 2, 3 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '::2'; - expected = [ 1, 3 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-1::-2'; - expected = [ 4, 2 ]; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting subsequence indexing expressions (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = ':'; - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':2'; - expected = new Int32Array( [ 1, 2 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '1:3'; - expected = new Int32Array( [ 2, 3 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '::2'; - expected = new Int32Array( [ 1, 3 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-1::-2'; - expected = new Int32Array( [ 4, 2 ] ); - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.notEqual( actual, x, 'different reference' ); - t.notEqual( actual, y, 'different reference' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns an empty array when provided a subsequence indexing expression which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = []; - - s = '10:20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-20:-10'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':-20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which returns an empty array when provided a subsequence indexing expression which is out-of-bounds (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [] ); - - s = '10:20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-20:-10'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':-20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns an empty array when provided a subsequence indexing expression which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - expected = []; - - s = '10:20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-20:-10'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':-20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which returns an empty array when provided a subsequence indexing expression which is out-of-bounds (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - expected = new Int32Array( [] ); - - s = '10:20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = '-20:-10'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = ':-20'; - actual = y[ s ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a subsequence indexing expression which is out-of-bounds (generic)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = (x.length+i) + ':' + (x.length+10); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a subsequence indexing expression which is out-of-bounds (typed)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = (x.length+i) + ':' + (x.length+10); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = y[ value ]; // eslint-disable-line no-unused-vars - }; - } -}); diff --git a/to-fancy/test/test.js b/to-fancy/test/test.js deleted file mode 100644 index c9cc57a8..00000000 --- a/to-fancy/test/test.js +++ /dev/null @@ -1,47 +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 tape = require( 'tape' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var ArrayIndex = require( './../../index' ); -var array2fancy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( hasOwnProp( array2fancy, 'factory' ), true, 'has property' ); - t.strictEqual( typeof array2fancy.factory, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to the main export is an `ArrayIndex` constructor', function test( t ) { - t.strictEqual( hasOwnProp( array2fancy, 'idx' ), true, 'has property' ); - t.strictEqual( array2fancy.idx, ArrayIndex, 'returns expected value' ); - t.end(); -}); diff --git a/to-fancy/test/test.main.js b/to-fancy/test/test.main.js deleted file mode 100644 index 4f332687..00000000 --- a/to-fancy/test/test.main.js +++ /dev/null @@ -1,405 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var propertiesIn = require( '@stdlib/utils/properties-in' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like value', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2fancy( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like value (options)', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2fancy( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', 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() { - array2fancy( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - 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() { - array2fancy( [ 1, 2, 3 ], { - 'strict': value - }); - }; - } -}); - -tape( 'the function returns an array-like object which satisfies the same instance check (generic)', function test( t ) { - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - t.notEqual( y, x, 'different reference' ); - t.strictEqual( y instanceof Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object which satisfies the same instance check (typed)', function test( t ) { - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - t.notEqual( y, x, 'different reference' ); - t.strictEqual( y instanceof Int32Array, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object having the same properties, both own and inherited, as the input array (generic)', function test( t ) { - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - t.deepEqual( propertiesIn( y ), propertiesIn( x ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object having the same properties, both own and inherited, as the input array (typed)', function test( t ) { - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - t.deepEqual( propertiesIn( y ), propertiesIn( x ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting bracket syntax for element retrieval (generic)', function test( t ) { - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting bracket syntax for element retrieval (typed)', function test( t ) { - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < x.length; i++ ) { - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting the calling of input array methods (generic)', function test( t ) { - var expected; - var actual; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 2, 4, 6, 8 ]; - actual = y.map( fcn ); - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); - - function fcn( v ) { - return v * 2; - } -}); - -tape( 'the function returns an array-like object supporting the calling of input array methods (typed)', function test( t ) { - var expected; - var actual; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 2, 4, 6, 8 ] ); - actual = y.map( fcn ); - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); - - function fcn( v ) { - return v * 2; - } -}); - -tape( 'the function returns an array-like object supporting the return of array instances supporting slice expressions (generic)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var z; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 2, 3, 4 ]; - actual = y.slice(); - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.strictEqual( x[ ':' ], void 0, 'returns expected value' ); - - expected = [ 1, 2, 3, 4 ]; - actual = y[ ':' ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - expected = [ 1, 2, 3, 4 ]; - actual = z[ ':' ]; - - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting the return of array instances supporting slice expressions (typed)', opts, function test( t ) { - var expected; - var actual; - var x; - var y; - var z; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y.slice(); - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.strictEqual( x[ ':' ], void 0, 'returns expected value' ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = y[ ':' ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - z = actual; - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - actual = z[ ':' ]; - - t.strictEqual( actual instanceof Int32Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting constructor access (generic)', function test( t ) { - var expected; - var actual; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = []; - actual = new y.constructor(); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = new y.constructor( 1 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.strictEqual( actual.length, 1, 'returns expected value' ); - - expected = [ 1, 2 ]; - actual = new y.constructor( 1, 2 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3 ]; - actual = new y.constructor( 1, 2, 3 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4 ]; - actual = new y.constructor( 1, 2, 3, 4 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5 ]; - actual = new y.constructor( 1, 2, 3, 4, 5 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6, 7 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6, 7, 8 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - expected = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]; - actual = new y.constructor( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ); - t.strictEqual( actual instanceof Array, true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/to-fancy/test/test.set.boolean_array.js b/to-fancy/test/test.set.boolean_array.js deleted file mode 100644 index 6e568121..00000000 --- a/to-fancy/test/test.set.boolean_array.js +++ /dev/null @@ -1,1563 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint32Array = require( './../../uint32' ); -var Uint16Array = require( './../../uint16' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var BooleanArray = require( './../../bool' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment ("unknown" dtype, accessor)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment (int32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment (uint32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment (float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting boolean array assignment (complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (generic, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (generic, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (float64, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (float64, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (int32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (int32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (uint32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (uint32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (complex128, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (complex128, complex scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted boolean array assignment (complex128, real scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 0, 9, 0, 9, 0, 9, 0 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 9, 0, 9, 0, 5, 6, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 9, 0, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 9, 0, 3, 4, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (generic, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (float64, float32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (int32, int8)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int8Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (uint32, uint16)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint16Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, complex64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Float32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Float32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Float32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Float32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (complex64, complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ] ); - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) ); - expected = new Complex64Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ false, true, true, false ] ); - expected = new Complex64Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) ); - expected = new Complex64Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - [], - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - new Int32Array( [] ), - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - new Complex128Array( [ 5, 6 ] ), - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (complex128)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - new Uint32Array( [ 1 ] ), - new Uint32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 999999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': false - }); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = [ 9, 10, 11, 12 ]; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': false - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = new Int32Array( [ 9, 10, 11, 12 ] ); - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - expected = [ 5, 6, 7, 8 ]; - - y[ idx ] = [ 5, 6, 7, 8 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - expected = [ 9, 10, 11, 12 ]; - - y[ idx ] = [ 9, 10, 11, 12 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ true, true, true, true ], { - 'persist': true - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - expected = new Int32Array( [ 9, 10, 11, 12 ] ); - - y[ idx ] = new Int32Array( [ 9, 10, 11, 12 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.set.integer_array.js b/to-fancy/test/test.set.integer_array.js deleted file mode 100644 index 2c26a612..00000000 --- a/to-fancy/test/test.set.integer_array.js +++ /dev/null @@ -1,1918 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint32Array = require( './../../uint32' ); -var Uint16Array = require( './../../uint16' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = [ 1, 6, 3, 5 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment ("unknown" dtype, accessor)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = [ 1, 6, 3, 5 ]; - y[ idx ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment (int32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment (uint32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment (float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting integer array assignment (complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (generic, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = [ 1, 5, 3, 5 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (generic, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = [ 1, 5, 3, 5 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (float64, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (float64, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (int32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (int32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (uint32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (uint32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (complex128, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (complex128, complex scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted integer array assignment (complex128, real scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 0, 9, 0, 9, 0, 9, 0 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 0, 9, 0, 5, 6, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 9, 0, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex128Array( [ 9, 0, 3, 4, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 9, 0, 5, 6, 9, 0 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (generic, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = [ 1, 6, 3, 5 ]; - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (float64, float32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (int32, int8)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int8Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (uint32, uint16)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint16Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, complex64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1 ] ); - expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 2 ] ); - expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex128Array( [ 1, 2, 18, 0, 5, 6, 17, 0 ] ); - y[ idx ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Float32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Float32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Float32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Float32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Float32Array( [ 1, 6, 3, 5 ] ); - y[ idx ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (complex64, complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ] ); - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 1 ] ) ); - expected = new Complex64Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 1, 2 ] ); - expected = new Complex64Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Int32Array( [ 0, 2 ] ) ); - expected = new Complex64Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Complex64Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (generic)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'by default, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (typed)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (generic)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (typed)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (generic)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which throws an error when provided an integer array containing an index which is out-of-bounds (typed)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = array2fancy.idx( [ x.length+i ] ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx.data ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - [], - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - new Int32Array( [] ), - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - new Complex128Array( [ 5, 6 ] ), - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (complex128)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - new Uint32Array( [ 1 ] ), - new Uint32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 999999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': false - }); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = [ 9, 10, 11, 12 ]; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': false - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = new Int32Array( [ 9, 10, 11, 12 ] ); - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - expected = [ 5, 6, 7, 8 ]; - - y[ idx ] = [ 5, 6, 7, 8 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - expected = [ 9, 10, 11, 12 ]; - - y[ idx ] = [ 9, 10, 11, 12 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ 0, 1, 2, 3 ], { - 'persist': true - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - expected = new Int32Array( [ 9, 10, 11, 12 ] ); - - y[ idx ] = new Int32Array( [ 9, 10, 11, 12 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.set.integers.js b/to-fancy/test/test.set.integers.js deleted file mode 100644 index 5c84cb2f..00000000 --- a/to-fancy/test/test.set.integers.js +++ /dev/null @@ -1,688 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Uint32Array = require( './../../uint32' ); -var Int8Array = require( './../../int8' ); -var Int32Array = require( './../../int32' ); -var Float64Array = require( './../../float64' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (generic, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 2, 4, 6, 8 ]; - - for ( i = 0; i < x.length; i++ ) { - y[ i ] *= 2; - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - t.strictEqual( y[ i ], expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (int32, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 2, 4, 6, 8 ] ); - - for ( i = 0; i < x.length; i++ ) { - y[ i ] *= 2; - t.strictEqual( y[ i ], x[ i ], 'returns expected value' ); - t.strictEqual( y[ i ], expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (bool, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - y = array2fancy( x ); - - expected = new BooleanArray( [ 1, 1, 1, 1 ] ); - - for ( i = 0; i < x.length; i++ ) { - y[ i ] = true; - t.strictEqual( y[ i ], x.get( i ), 'returns expected value' ); - t.strictEqual( y[ i ], expected.get( i ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (complex128, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var v; - var i; - var j; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = 2 * i; - v = new Complex128( j+9, j+10 ); - y[ i ] = v; - } - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting floating-point downcasting (complex64, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var v; - var i; - var j; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = 2 * i; - v = new Complex128( j+9, j+10 ); - y[ i ] = v; - } - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting floating-point upcasting (complex128, positive integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - - for ( i = 0; i < x.length; i++ ) { - y[ i ] = i + 9; - } - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (generic, negative integer indices)', opts, function test( t ) { - var expected; - var x; - var y; - var i; - var j; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 2, 4, 6, 8 ]; - - for ( i = 0; i < x.length; i++ ) { - j = i - x.length; - y[ j ] *= 2; - t.strictEqual( y[ j ], x[ i ], 'returns expected value' ); - t.strictEqual( y[ j ], expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (int32, negative integer indices)', opts, function test( t ) { - var expected; - var x; - var y; - var i; - var j; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 2, 4, 6, 8 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = i - x.length; - y[ j ] *= 2; - t.strictEqual( y[ j ], x[ i ], 'returns expected value' ); - t.strictEqual( y[ j ], expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (bool, negative integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - var j; - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - y = array2fancy( x ); - - expected = new BooleanArray( [ 1, 1, 1, 1 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = i - x.length; - y[ j ] = true; - t.strictEqual( y[ j ], x.get( i ), 'returns expected value' ); - t.strictEqual( y[ j ], expected.get( i ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting individual element assignment (complex128, negative integer indices)', function test( t ) { - var expected; - var x; - var y; - var v; - var i; - var j; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = 2 * i; - v = new Complex128( j+9, j+10 ); - y[ i-x.length ] = v; - } - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting floating-point downcasting (complex64, negative integer indices)', function test( t ) { - var expected; - var x; - var y; - var v; - var i; - var j; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - for ( i = 0; i < x.length; i++ ) { - j = 2 * i; - v = new Complex128( j+9, j+10 ); - y[ i-x.length ] = v; - } - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting floating-point upcasting (complex128, negative integer indices)', function test( t ) { - var expected; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - - for ( i = 0; i < x.length; i++ ) { - y[ i-x.length ] = i + 9; - } - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'by default, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (generic, positive integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - y[ idx ] = i; - t.strictEqual( y[ idx ], i, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (int32, positive integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - y[ idx ] = i; - - // Normal behavior for typed arrays is to NOT support out-of-bounds assignment: - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (generic, negative integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - y[ idx ] = i; - t.strictEqual( y[ idx ], i, 'returns expected value' ); - } - t.end(); -}); - -tape( 'by default, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (int32, negative integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - y[ idx ] = i; - - // Normal behavior for typed arrays is to NOT support out-of-bounds assignment: - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (generic, positive integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - y[ idx ] = i; - t.strictEqual( y[ idx ], i, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (int32, positive integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - y[ idx ] = i; - - // Normal behavior for typed arrays is to NOT support out-of-bounds assignment: - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (generic, negative integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - y[ idx ] = i; - t.strictEqual( y[ idx ], i, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which performs normal property assignment when provided an integer index which is out-of-bounds (int32, negative integer indices)', function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - y[ idx ] = i; - - // Normal behavior for typed arrays is to NOT support out-of-bounds assignment: - t.strictEqual( y[ idx ], void 0, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (generic, positive integer indices)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (int32, positive integer indices)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = x.length + i; - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (generic, negative integer indices)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided an integer index which is out-of-bounds (int32, negative integer indices)', opts, function test( t ) { - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - idx = -( i + x.length + 1 ); - t.throws( badValue( idx ), RangeError, 'throws an error when provided ' + idx ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ 0 ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ 0 ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 99999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ 0 ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ 0 ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (bool)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new BooleanArray( [ 0, 1, 0, 1 ] ); - y = array2fancy( x ); - - values = [ - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - null, - 1 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ 0 ] = value; - }; - } -}); diff --git a/to-fancy/test/test.set.invalid.js b/to-fancy/test/test.set.invalid.js deleted file mode 100644 index 90b3ac1f..00000000 --- a/to-fancy/test/test.set.invalid.js +++ /dev/null @@ -1,285 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var Int32Array = require( './../../int32' ); -var Uint8Array = require( './../../uint8' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized slice (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'Slice(a,b,c)', - 'Slice(1.5)', - 'Slice(0,1,0)' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized slice (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'Slice(a,b,c)', - 'Slice(1.5)', - 'Slice(0,1,0)' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid subsequence indexing expression (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'a:b:c', - ':1.5', - '0:1:0', - ':::', - '0:1:1:2' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid subsequence indexing expression (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'a:b:c', - ':1.5', - '0:1:0', - ':::', - '0:1:1:2' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized array index (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - 'ArrayIndex<9999999>', - 'ArrayIndex<9999999999>' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an invalid serialized array index (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - 'ArrayIndex<9999999>', - 'ArrayIndex<9999999999>' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (generic)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'cache': { - 'get': get - } - }); - - values = [ - array2fancy.idx( [ 0, 1, 2, 3 ] ), - array2fancy.idx( [ true, false, true, false ] ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } - - function get() { - return { - 'data': [], - 'type': 'beep', - 'dtype': 'generic' - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (typed)', opts, function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'cache': { - 'get': get - } - }); - - values = [ - array2fancy.idx( [ 0, 1, 2, 3 ] ), - array2fancy.idx( [ true, false, true, false ] ), - array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 0; - }; - } - - function get() { - return { - 'data': [], - 'type': 'beep', - 'dtype': 'generic' - }; - } -}); diff --git a/to-fancy/test/test.set.mask_array.js b/to-fancy/test/test.set.mask_array.js deleted file mode 100644 index 93e98081..00000000 --- a/to-fancy/test/test.set.mask_array.js +++ /dev/null @@ -1,1563 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint32Array = require( './../../uint32' ); -var Uint16Array = require( './../../uint16' ); -var Uint8Array = require( './../../uint8' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6, 0, 0 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 0, 5, 6, 0 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 0, 6, 0 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment ("unknown" dtype, accessor)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = [ 5, 6, 0, 0 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = [ 0, 5, 6, 0 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = [ 5, 0, 6, 0 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment (int32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int32Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment (uint32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint32Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment (float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting mask array assignment (complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20, 0, 0, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 0, 0, 17, 18, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 0, 0, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (generic, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (generic, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 5, 5, 5, 5 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 5, 5, 3, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 1, 5, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 5, 2, 5, 4 ]; - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (float64, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (float64, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (int32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( [ -1, -3 ] ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ idx ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (int32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (uint32, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (uint32, scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ idx ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (complex128, array)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (complex128, complex scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ idx ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted mask array assignment (complex128, real scalar)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 0, 9, 0, 9, 0, 9, 0 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 9, 0, 9, 0, 5, 6, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 9, 0, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 9, 0, 3, 4, 9, 0, 7, 8 ] ); - y[ idx ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (generic, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = [ 5, 6, 3, 4 ]; - y[ idx ] = new Float64Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = [ 1, 5, 6, 4 ]; - y[ idx ] = new Float64Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = [ 5, 2, 6, 4 ]; - y[ idx ] = new Float64Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (float64, float32)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float32Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (int32, int8)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int8Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Int8Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (uint32, uint16)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Uint16Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Uint16Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, complex64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 19, 20, 0, 0, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 0, 0, 17, 18, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex64Array( [ 17, 18, 0, 0, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 18, 0, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 0, 17, 18, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 17, 0, 18, 0 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Float32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Float32Array( [ 5, 6, 3, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 6, 0, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Float32Array( [ 1, 5, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 0, 5, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Float32Array( [ 5, 2, 6, 4 ] ); - y[ idx ] = new Float64Array( [ 5, 0, 6, 0 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (complex64, complex128)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) ); - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ idx ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) ); - expected = new Complex64Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 19, 20, 0, 0, 0, 0 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) ); - expected = new Complex64Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 0, 0, 17, 18, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - expected = new Complex64Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ idx ] = new Complex128Array( [ 17, 18, 0, 0, 19, 20, 0, 0 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - [], - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - new Int32Array( [] ), - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - new Complex128Array( [ 5, 6 ] ), - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (complex128)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - new Uint32Array( [ 1 ] ), - new Uint32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 999999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var idx; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - - array2fancy.idx.free( idx ); - - t.end(); - - function badValue( value ) { - return function badValue() { - y[ idx ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': false - }); - expected = [ 5, 6, 7, 8 ]; - y[ idx ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = [ 9, 10, 11, 12 ]; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when unable to resolve an index array (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': false - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.throws( badValue( idx ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = new Int32Array( [ 9, 10, 11, 12 ] ); - }; - } -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (generic)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - expected = [ 5, 6, 7, 8 ]; - - y[ idx ] = [ 5, 6, 7, 8 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - expected = [ 9, 10, 11, 12 ]; - - y[ idx ] = [ 9, 10, 11, 12 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); - -tape( 'the function returns an array-like object which supports persisted index arrays (typed)', opts, function test( t ) { - var expected; - var idx; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ), { - 'persist': true - }); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - - y[ idx ] = new Int32Array( [ 5, 6, 7, 8 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - expected = new Int32Array( [ 9, 10, 11, 12 ] ); - - y[ idx ] = new Int32Array( [ 9, 10, 11, 12 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - array2fancy.idx.free( idx ); - - t.end(); -}); diff --git a/to-fancy/test/test.set.properties.js b/to-fancy/test/test.set.properties.js deleted file mode 100644 index 2b9ae572..00000000 --- a/to-fancy/test/test.set.properties.js +++ /dev/null @@ -1,122 +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 tape = require( 'tape' ); -var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' ); -var Symbol = require( '@stdlib/symbol/ctor' ); -var Int32Array = require( './../../int32' ); -var array2fancy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting expected property assignment (generic)', function test( t ) { - var sym; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - x.foo = 'a'; - x.bar = 'b'; - - y = array2fancy( x ); - - t.strictEqual( y.foo, x.foo, 'returns expected value' ); - t.strictEqual( y.bar, x.bar, 'returns expected value' ); - t.strictEqual( y.beep, void 0, 'returns expected value' ); - t.strictEqual( y.boop, void 0, 'returns expected value' ); - - y.foo = 1; - y.bar = 2; - y.beep = true; - y.boop = false; - - t.strictEqual( x.foo, 1, 'returns expected value' ); - t.strictEqual( x.bar, 2, 'returns expected value' ); - t.strictEqual( x.beep, true, 'returns expected value' ); - t.strictEqual( x.boop, false, 'returns expected value' ); - - t.strictEqual( y.foo, 1, 'returns expected value' ); - t.strictEqual( y.bar, 2, 'returns expected value' ); - t.strictEqual( y.beep, true, 'returns expected value' ); - t.strictEqual( y.boop, false, 'returns expected value' ); - - if ( hasSymbolSupport() ) { - sym = Symbol( 'foo' ); - t.strictEqual( x[ sym ], void 0, 'returns expected value' ); - t.strictEqual( y[ sym ], void 0, 'returns expected value' ); - - y[ sym ] = 'bar'; - t.strictEqual( x[ sym ], 'bar', 'returns expected value' ); - t.strictEqual( y[ sym ], 'bar', 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an array-like object supporting expected property assignment (typed)', function test( t ) { - var sym; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - x.foo = 'a'; - x.bar = 'b'; - - y = array2fancy( x ); - - t.strictEqual( y.foo, x.foo, 'returns expected value' ); - t.strictEqual( y.bar, x.bar, 'returns expected value' ); - t.strictEqual( y.beep, void 0, 'returns expected value' ); - t.strictEqual( y.boop, void 0, 'returns expected value' ); - - y.foo = 1; - y.bar = 2; - y.beep = true; - y.boop = false; - - t.strictEqual( x.foo, 1, 'returns expected value' ); - t.strictEqual( x.bar, 2, 'returns expected value' ); - t.strictEqual( x.beep, true, 'returns expected value' ); - t.strictEqual( x.boop, false, 'returns expected value' ); - - t.strictEqual( y.foo, 1, 'returns expected value' ); - t.strictEqual( y.bar, 2, 'returns expected value' ); - t.strictEqual( y.beep, true, 'returns expected value' ); - t.strictEqual( y.boop, false, 'returns expected value' ); - - if ( hasSymbolSupport() ) { - sym = Symbol( 'foo' ); - t.strictEqual( x[ sym ], void 0, 'returns expected value' ); - t.strictEqual( y[ sym ], void 0, 'returns expected value' ); - - y[ sym ] = 'bar'; - t.strictEqual( x[ sym ], 'bar', 'returns expected value' ); - t.strictEqual( y[ sym ], 'bar', 'returns expected value' ); - } - t.end(); -}); diff --git a/to-fancy/test/test.set.slice.js b/to-fancy/test/test.set.slice.js deleted file mode 100644 index 0fc8109a..00000000 --- a/to-fancy/test/test.set.slice.js +++ /dev/null @@ -1,1878 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Slice = require( '@stdlib/slice/ctor' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint32Array = require( './../../uint32' ); -var Uint16Array = require( './../../uint16' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (generic)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 5, 6, 7, 8 ]; - y[ s ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = [ 5, 6, 3, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = [ 1, 5, 6, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = [ 5, 2, 6, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = [ 1, 6, 3, 5 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment ("unknown" dtype, accessor)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - s = new Slice(); - expected = [ 5, 6, 7, 8 ]; - y[ s ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - s = new Slice( 2 ); - expected = [ 5, 6, 3, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - s = new Slice( 1, 3 ); - expected = [ 1, 5, 6, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - s = new Slice( null, null, 2 ); - expected = [ 5, 2, 6, 4 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - s = new Slice( -1, null, -2 ); - expected = [ 1, 6, 3, 5 ]; - y[ s ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (int32)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (uint32)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Uint32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (float64)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (complex128)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ s ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (generic, array)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 5, 5, 5, 5 ]; - y[ s ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = [ 5, 5, 3, 4 ]; - y[ s ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = [ 1, 5, 5, 4 ]; - y[ s ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = [ 5, 2, 5, 4 ]; - y[ s ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = [ 1, 5, 3, 5 ]; - y[ s ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (generic, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 5, 5, 5, 5 ]; - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = [ 5, 5, 3, 4 ]; - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = [ 1, 5, 5, 4 ]; - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = [ 5, 2, 5, 4 ]; - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = [ 1, 5, 3, 5 ]; - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (float64, array)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ s ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ s ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ s ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ s ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ s ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (float64, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (int32, array)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ s ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ s ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ s ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ s ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ s ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (int32, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (uint32, array)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ s ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ s ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ s ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ s ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ s ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (uint32, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ s ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, array)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ s ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ s ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, complex scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ s ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ s ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ s ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ s ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ s ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, real scalar)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 0, 9, 0, 9, 0, 9, 0 ] ); - y[ s ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 9, 0, 9, 0, 5, 6, 7, 8 ] ); - y[ s ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 9, 0, 9, 0, 7, 8 ] ); - y[ s ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 9, 0, 3, 4, 9, 0, 7, 8 ] ); - y[ s ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 9, 0, 5, 6, 9, 0 ] ); - y[ s ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (generic, float64)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice(); - expected = [ 5, 6, 7, 8 ]; - y[ s ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = [ 5, 6, 3, 4 ]; - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = [ 1, 5, 6, 4 ]; - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = [ 5, 2, 6, 4 ]; - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = [ 1, 6, 3, 5 ]; - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (float64, float32)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Float32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (int32, int8)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Int8Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (uint32, uint16)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Uint16Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, complex64)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ s ] = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ s ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ s ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ s ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ s ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - y[ s ] = new Float64Array( [ 9, 10, 11, 12 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] ); - y[ s ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] ); - y[ s ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] ); - y[ s ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex128Array( [ 1, 2, 18, 0, 5, 6, 17, 0 ] ); - y[ s ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Float32Array( [ 5, 6, 7, 8 ] ); - y[ s ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Float32Array( [ 5, 6, 3, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Float32Array( [ 1, 5, 6, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Float32Array( [ 5, 2, 6, 4 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Float32Array( [ 1, 6, 3, 5 ] ); - y[ s ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (complex64, complex128)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice(); - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ s ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 2 ); - expected = new Complex64Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( 1, 3 ); - expected = new Complex64Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( null, null, 2 ); - expected = new Complex64Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - s = new Slice( -1, null, -2 ); - expected = new Complex64Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ s ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which falls back to normal property assignment when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( 10, 20 ); - y[ s ] = [ 5 ]; // note: broadcast compatible with empty slice - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -20, -10 ); - y[ s ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - s = new Slice( -20 ); - y[ s ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( 10, 20 ); - y[ s ] = new Int32Array( [ 5 ] ); // note: broadcast compatible with empty slice - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -20, -10 ); - y[ s ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - s = new Slice( -20 ); - y[ s ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( 10, 20 ); - y[ s ] = [ 5 ]; // note: broadcast compatible with empty slice - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( -20, -10 ); - y[ s ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( -20 ); - y[ s ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var expected; - var x; - var y; - var s; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( 10, 20 ); - y[ s ] = new Int32Array( [ 5 ] ); // note: broadcast compatible with empty slice - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( -20, -10 ); - y[ s ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - s = new Slice( -20 ); - y[ s ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = new Slice( x.length+i, x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = new Slice( x.length+i, x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic)', function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic, out-of-bounds slice)', function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8 ], // note: this is as expected, as a zero-element slice is only compatible with either a zero- or one-element assigned value - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice( 10, 20 ) ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32, out-of-bounds slice)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), // note: this is as expected, as a zero-element slice is only compatible with either a zero- or one-element assigned value - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice( 10, 20 ) ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Complex128Array( [ 5, 6 ] ), - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (complex128)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - values = [ - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Uint32Array( [ 1 ] ), - new Uint32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 999999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ new Slice() ] = value; - }; - } -}); diff --git a/to-fancy/test/test.set.subsequence.js b/to-fancy/test/test.set.subsequence.js deleted file mode 100644 index 9bd2ce9f..00000000 --- a/to-fancy/test/test.set.subsequence.js +++ /dev/null @@ -1,1711 +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 tape = require( 'tape' ); -var hasProxySupport = require( '@stdlib/assert/has-proxy-support' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint32Array = require( './../../uint32' ); -var Uint16Array = require( './../../uint16' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var toAccessorArray = require( './../../base/to-accessor-array' ); -var array2fancy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasProxySupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2fancy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (generic)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 6, 7, 8 ]; - y[ ':' ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 6, 3, 4 ]; - y[ ':2' ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 6, 4 ]; - y[ '1:3' ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 2, 6, 4 ]; - y[ '::2' ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 6, 3, 5 ]; - y[ '-1::-2' ] = [ 5, 6 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment ("unknown" dtype, accessor)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - expected = [ 5, 6, 7, 8 ]; - y[ ':' ] = [ 5, 6, 7, 8 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - expected = [ 5, 6, 3, 4 ]; - y[ ':2' ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - expected = [ 1, 5, 6, 4 ]; - y[ '1:3' ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - expected = [ 5, 2, 6, 4 ]; - y[ '::2' ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( toAccessorArray( x ) ); - - expected = [ 1, 6, 3, 5 ]; - y[ '-1::-2' ] = [ 5, 6 ]; - - t.deepEqual( x, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (int32)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Int32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Int32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (uint32)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Uint32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Uint32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (float64)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting slice assignment (complex128)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ ':' ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ '1:3' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ '::2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ '-1::-2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (generic, array)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 5, 5, 5 ]; - y[ ':' ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 5, 3, 4 ]; - y[ ':2' ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 5, 4 ]; - y[ '1:3' ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 2, 5, 4 ]; - y[ '::2' ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 3, 5 ]; - y[ '-1::-2' ] = [ 5 ]; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (generic, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 5, 5, 5 ]; - y[ ':' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 5, 3, 4 ]; - y[ ':2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 5, 4 ]; - y[ '1:3' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 2, 5, 4 ]; - y[ '::2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 3, 5 ]; - y[ '-1::-2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (float64, array)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = new Float64Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (float64, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (int32, array)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = new Int32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (int32, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (uint32, array)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = new Uint32Array( [ 5 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (uint32, scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 5, 5, 5 ] ); - y[ ':' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 5, 3, 4 ] ); - y[ ':2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 5, 4 ] ); - y[ '1:3' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 2, 5, 4 ] ); - y[ '::2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 3, 5 ] ); - y[ '-1::-2' ] = 5; - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, array)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ ':' ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ '1:3' ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ '::2' ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ '-1::-2' ] = new Complex128Array( [ 9, 10 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, complex scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 9, 10, 9, 10, 9, 10 ] ); - y[ ':' ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 9, 10, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 10, 9, 10, 7, 8 ] ); - y[ '1:3' ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 3, 4, 9, 10, 7, 8 ] ); - y[ '::2' ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 10, 5, 6, 9, 10 ] ); - y[ '-1::-2' ] = new Complex128( 9, 10 ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting broadcasted slice assignment (complex128, real scalar)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 9, 0, 9, 0, 9, 0 ] ); - y[ ':' ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 9, 0, 5, 6, 7, 8 ] ); - y[ ':2' ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 0, 9, 0, 7, 8 ] ); - y[ '1:3' ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 3, 4, 9, 0, 7, 8 ] ); - y[ '::2' ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 9, 0, 5, 6, 9, 0 ] ); - y[ '-1::-2' ] = 9; - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (generic, float64)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 6, 7, 8 ]; - y[ ':' ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 6, 3, 4 ]; - y[ ':2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 5, 6, 4 ]; - y[ '1:3' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 5, 2, 6, 4 ]; - y[ '::2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - expected = [ 1, 6, 3, 5 ]; - y[ '-1::-2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (float64, float32)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Float32Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float64Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Float32Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (int32, int8)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Int8Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Int32Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Int8Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (uint32, uint16)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Uint16Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Uint32Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Uint16Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, complex64)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ ':' ] = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ '1:3' ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ '::2' ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ '-1::-2' ] = new Complex64Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] ); - y[ ':' ] = new Float64Array( [ 9, 10, 11, 12 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] ); - y[ '1:3' ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] ); - y[ '::2' ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex128Array( [ 1, 2, 18, 0, 5, 6, 17, 0 ] ); - y[ '-1::-2' ] = new Float64Array( [ 17, 18 ] ); - - t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float32Array( [ 5, 6, 7, 8 ] ); - y[ ':' ] = new Float64Array( [ 5, 6, 7, 8 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float32Array( [ 5, 6, 3, 4 ] ); - y[ ':2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float32Array( [ 1, 5, 6, 4 ] ); - y[ '1:3' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float32Array( [ 5, 2, 6, 4 ] ); - y[ '::2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Float32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - expected = new Float32Array( [ 1, 6, 3, 5 ] ); - y[ '-1::-2' ] = new Float64Array( [ 5, 6 ] ); - - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (complex64, complex128)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - y[ ':' ] = new Complex128Array( [ 9, 10, 11, 12, 13, 14, 15, 16 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 17, 18, 19, 20, 5, 6, 7, 8 ] ); - y[ ':2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 1, 2, 17, 18, 19, 20, 7, 8 ] ); - y[ '1:3' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 17, 18, 3, 4, 19, 20, 7, 8 ] ); - y[ '::2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - x = new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - expected = new Complex64Array( [ 1, 2, 19, 20, 5, 6, 17, 18 ] ); - y[ '-1::-2' ] = new Complex128Array( [ 17, 18, 19, 20 ] ); - - t.strictEqual( isSameComplex64Array( y, expected ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which falls back to normal property assignment when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - y[ '10:20' ] = [ 5 ]; // note: broadcast compatible with empty slice - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - y[ '-20:-10' ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - y[ ':-20' ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'by default, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - y[ '10:20' ] = new Int32Array( [ 5 ] ); // note: broadcast compatible with empty slice - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - y[ '-20:-10' ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - y[ ':-20' ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var expected; - var x; - var y; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - y[ '10:20' ] = [ 5 ]; // note: broadcast compatible with empty slice - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - y[ '-20:-10' ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': false - }); - - y[ ':-20' ] = [ 5 ]; - - expected = [ 1, 2, 3, 4 ]; - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `false`, the function returns an array-like object which leaves the array unchanged when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var expected; - var x; - var y; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - y[ '10:20' ] = new Int32Array( [ 5 ] ); // note: broadcast compatible with empty slice - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - y[ '-20:-10' ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': false - }); - - y[ ':-20' ] = new Int32Array( [ 5 ] ); - - expected = new Int32Array( [ 1, 2, 3, 4 ] ); - t.deepEqual( y, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (generic)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = ( x.length+i ) + ':' + ( x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'when `strict` is `true`, the function returns an array-like object which throws an error when provided a slice which is out-of-bounds (int32)', opts, function test( t ) { - var x; - var y; - var s; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x, { - 'strict': true - }); - - for ( i = 0; i < 10; i++ ) { - s = ( x.length+i ) + ':' + ( x.length+10 ); - t.throws( badValue( s ), RangeError, 'throws an error when provided ' + s ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ value ] = 5; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic)', function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (generic, out-of-bounds slice)', function test( t ) { - var values; - var x; - var y; - var i; - - x = [ 1, 2, 3, 4 ]; - y = array2fancy( x ); - - values = [ - [ 5, 6 ], - [ 5, 6, 7 ], - [ 5, 6, 7, 8 ], // note: this is as expected, as a zero-element slice is only compatible with either a zero- or one-element assigned value - [ 5, 6, 7, 8, 9 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ '10:20' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to assign a broadcast-incompatible array (int32, out-of-bounds slice)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 5, 6 ] ), - new Int32Array( [ 5, 6, 7 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), // note: this is as expected, as a zero-element slice is only compatible with either a zero- or one-element assigned value - new Int32Array( [ 5, 6, 7, 8, 9 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ '10:20' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (float64)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Float64Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Complex128Array( [ 5, 6 ] ), - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (complex128)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - y = array2fancy( x ); - - values = [ - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Uint32Array( [ 1 ] ), - new Uint32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (int8)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Int8Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - 999999, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); - -tape( 'the function returns an array-like object which throws an error when attempting to perform an unsafe cast (uint32)', function test( t ) { - var values; - var x; - var y; - var i; - - x = new Uint32Array( [ 1, 2, 3, 4 ] ); - y = array2fancy( x ); - - values = [ - new Int32Array( [ 1 ] ), - new Int32Array( [ 5, 6, 7, 8 ] ), - new Float64Array( [ 1 ] ), - new Float64Array( [ 5, 6, 7, 8 ] ), - new Float32Array( [ 1 ] ), - new Float32Array( [ 5, 6, 7, 8 ] ), - new Complex128Array( [ 5, 6 ] ), - -3, - 3.14, - -3.14, - new Complex128( 5, 6 ), - '5', - true, - false - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - y[ ':' ] = value; - }; - } -}); diff --git a/to-fancy/test/test.validate.js b/to-fancy/test/test.validate.js deleted file mode 100644 index 68910ccd..00000000 --- a/to-fancy/test/test.validate.js +++ /dev/null @@ -1,161 +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 tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `strict` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'strict': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `cache` option which is not valid', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'cache': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'strict': true, - 'cache': { - 'get': get - } - }; - opts = {}; - - expected = { - 'strict': true, - 'cache': options.cache - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); - - function get() { - // No-op... - } -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); diff --git a/to-iterator-right/README.md b/to-iterator-right/README.md deleted file mode 100644 index cba1a531..00000000 --- a/to-iterator-right/README.md +++ /dev/null @@ -1,244 +0,0 @@ - - -# array2iteratorRight - -> Create an iterator from an array-like object, iterating from right to left. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var array2iteratorRight = require( '@stdlib/array/to-iterator-right' ); -``` - -#### array2iteratorRight( src\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates from right to left over each element in an array-like `object`. - -```javascript -var it = array2iteratorRight( [ 1, 2, 3, 4 ] ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = array2iteratorRight( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 30.0 - -v = it.next().value; -// returns 20.0 - -// ... -``` - -The invoked function is provided three arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = array2iteratorRight( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 16 - -v = it.next().value; -// returns 9 - -v = it.next().value; -// returns 4 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = array2iteratorRight( [ 1, 2, 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 30.0 - -v = it.next().value; -// returns 20.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use [`@stdlib/array/to-sparse-iterator-right`][@stdlib/array/to-sparse-iterator-right]. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var array2iteratorRight = require( '@stdlib/array/to-iterator-right' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iteratorRight( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-iterator-right/benchmark/benchmark.js b/to-iterator-right/benchmark/benchmark.js deleted file mode 100644 index 43f2ca35..00000000 --- a/to-iterator-right/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iteratorRight = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iteratorRight( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iteratorRight( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iteratorRight( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-iterator-right/docs/repl.txt b/to-iterator-right/docs/repl.txt deleted file mode 100644 index 203cce37..00000000 --- a/to-iterator-right/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates from right to left over the elements of - an array-like object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 4 - > v = it.next().value - 3 - - See Also - -------- - diff --git a/to-iterator-right/docs/types/index.d.ts b/to-iterator-right/docs/types/index.d.ts deleted file mode 100644 index f2e7d012..00000000 --- a/to-iterator-right/docs/types/index.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object. -* -* ## Notes -* -* - For dynamic array resizing, the only behavior made intentionally consistent with iterating from left to right is when elements are pushed onto the beginning (end) of an array. In other words, iterating from left to right combined with `[].push()` is consistent with iterating from right to left combined with `[].unshift()`. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iteratorRight( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* // ... -*/ -declare function array2iteratorRight( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iteratorRight; diff --git a/to-iterator-right/docs/types/test.ts b/to-iterator-right/docs/types/test.ts deleted file mode 100644 index a1fa0cf7..00000000 --- a/to-iterator-right/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array2iteratorRight = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iteratorRight( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iteratorRight( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iteratorRight( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iteratorRight( 123 ); // $ExpectError - array2iteratorRight( true ); // $ExpectError - array2iteratorRight( false ); // $ExpectError - array2iteratorRight( {} ); // $ExpectError - array2iteratorRight( null ); // $ExpectError - array2iteratorRight( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iteratorRight( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iteratorRight(); // $ExpectError - array2iteratorRight( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/to-iterator-right/examples/index.js b/to-iterator-right/examples/index.js deleted file mode 100644 index 3a4979cb..00000000 --- a/to-iterator-right/examples/index.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'; - -var Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var array2iteratorRight = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iteratorRight( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-iterator-right/lib/index.js b/to-iterator-right/lib/index.js deleted file mode 100644 index e50d8d15..00000000 --- a/to-iterator-right/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object, iterating from right to left. -* -* @module @stdlib/array/to-iterator-right -* -* @example -* var array2iteratorRight = require( '@stdlib/array/to-iterator-right' ); -* -* var iter = array2iteratorRight( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-iterator-right/lib/main.js b/to-iterator-right/lib/main.js deleted file mode 100644 index 4adb126b..00000000 --- a/to-iterator-right/lib/main.js +++ /dev/null @@ -1,187 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object. -* -* ## Notes -* -* - For dynamic array resizing, the only behavior made intentionally consistent with iterating from left to right is when elements are pushed onto the beginning (end) of an array. In other words, iterating from left to right combined with `[].push()` is consistent with iterating from right to left combined with `[].unshift()`. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iteratorRight( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* // ... -*/ -function array2iteratorRight( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var len; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - len = src.length; - i = len; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += src.length - len - 1; // accounts for a dynamic array - len = src.length; - if ( FLG || i < 0 ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += src.length - len - 1; // accounts for a dynamic array - len = src.length; - if ( FLG || i < 0 ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iteratorRight( src, fcn, thisArg ); - } - return array2iteratorRight( src ); - } -} - - -// EXPORTS // - -module.exports = array2iteratorRight; diff --git a/to-iterator-right/package.json b/to-iterator-right/package.json deleted file mode 100644 index b869dd85..00000000 --- a/to-iterator-right/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@stdlib/array/to-iterator-right", - "version": "0.0.0", - "description": "Create an iterator from an array-like object, iterating from right to left.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-iterator-right/test/test.js b/to-iterator-right/test/test.js deleted file mode 100644 index 20f19b48..00000000 --- a/to-iterator-right/test/test.js +++ /dev/null @@ -1,492 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var array2iteratorRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iteratorRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - array2iteratorRight( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - array2iteratorRight( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iteratorRight( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object, iterating from right to left', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object, iterating from right to left (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iteratorRight; - var values; - var it1; - var it2; - var i; - - array2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iteratorRight( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iteratorRight; - var values; - var it1; - var it2; - var i; - - array2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iteratorRight( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iteratorRight; - var it; - - array2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = array2iteratorRight( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iteratorRight; - var it; - - array2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = array2iteratorRight( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-iterator/README.md b/to-iterator/README.md deleted file mode 100644 index 3823ca6b..00000000 --- a/to-iterator/README.md +++ /dev/null @@ -1,250 +0,0 @@ - - -# array2iterator - -> Create an iterator from an array-like object. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var array2iterator = require( '@stdlib/array/to-iterator' ); -``` - -#### array2iterator( src\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates over each element in an array-like `object`. - -```javascript -var it = array2iterator( [ 1, 2, 3, 4 ] ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = array2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -// ... -``` - -The invoked function is provided three arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = array2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 9 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = array2iterator( [ 1, 2, 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use [`@stdlib/array/to-sparse-iterator`][@stdlib/array/to-sparse-iterator]. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var array2iterator = require( '@stdlib/array/to-iterator' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-iterator/benchmark/benchmark.js b/to-iterator/benchmark/benchmark.js deleted file mode 100644 index e59e77b1..00000000 --- a/to-iterator/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-iterator/docs/repl.txt b/to-iterator/docs/repl.txt deleted file mode 100644 index cead6576..00000000 --- a/to-iterator/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/to-iterator/docs/types/index.d.ts b/to-iterator/docs/types/index.d.ts deleted file mode 100644 index 703a5c52..00000000 --- a/to-iterator/docs/types/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/to-iterator/docs/types/test.ts b/to-iterator/docs/types/test.ts deleted file mode 100644 index 561feb71..00000000 --- a/to-iterator/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/to-iterator/examples/index.js b/to-iterator/examples/index.js deleted file mode 100644 index c7f3c665..00000000 --- a/to-iterator/examples/index.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'; - -var Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-iterator/lib/index.js b/to-iterator/lib/index.js deleted file mode 100644 index 210a4c98..00000000 --- a/to-iterator/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array/to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array/to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-iterator/lib/main.js b/to-iterator/lib/main.js deleted file mode 100644 index 88522a80..00000000 --- a/to-iterator/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/to-iterator/package.json b/to-iterator/package.json deleted file mode 100644 index b2b4d6a7..00000000 --- a/to-iterator/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@stdlib/array/to-iterator", - "version": "0.0.0", - "description": "Create an iterator from an array-like object.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-iterator/test/test.js b/to-iterator/test/test.js deleted file mode 100644 index 80a28dce..00000000 --- a/to-iterator/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var Complex64Array = require( './../../complex64' ); -var realf = require( '@stdlib/complex/float32/real' ); -var imagf = require( '@stdlib/complex/float32/imag' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-json/README.md b/to-json/README.md deleted file mode 100644 index 4104b885..00000000 --- a/to-json/README.md +++ /dev/null @@ -1,310 +0,0 @@ - - -# typedarray2json - -> Return a [JSON][json] representation of a typed array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var typedarray2json = require( '@stdlib/array/to-json' ); -``` - -#### typedarray2json( typedarray ) - -Returns a [JSON][json] representation of a typed array. - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var arr = new Float64Array( [ 5.0, 3.0 ] ); - -var json = typedarray2json( arr ); -/* returns - { - 'type': 'Float64Array', - 'data': [ 5.0, 3.0 ] - } -*/ -``` - -For guidance on reviving a JSON-serialized typed array, see [`reviver()`][@stdlib/array/reviver]. - -
- - - - - -
- -## Notes - -- Supported typed array types: - - - [`Float64Array`][@stdlib/array/float64] - - [`Float32Array`][@stdlib/array/float32] - - [`Complex128Array`][@stdlib/array/complex128] - - [`Complex64Array`][@stdlib/array/complex64] - - [`BooleanArray`][@stdlib/array/bool] - - [`Int32Array`][@stdlib/array/int32] - - [`Uint32Array`][@stdlib/array/uint32] - - [`Int16Array`][@stdlib/array/int16] - - [`Uint16Array`][@stdlib/array/uint16] - - [`Int8Array`][@stdlib/array/int8] - - [`Uint8Array`][@stdlib/array/uint8] - - [`Uint8ClampedArray`][@stdlib/array/uint8c] - -- The implementation provides basic support for custom typed arrays and sets the `type` field to the closest known typed array type. - - - - ```javascript - class CustomArray extends Float64Array() { - constructor( data ) { - super( data ); - } - } - - var arr = new CustomArray( [ 5.0, 3.0 ] ); - - var json = typedarray2json( arr ); - /* returns - { - 'type': 'Float64Array', - 'data': [ 5.0, 3.0 ] - } - */ - ``` - -
- - - - - -
- -## Examples - - - -```javascript -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 typedarray2json = require( '@stdlib/array/to-json' ); - -var arr = new Float64Array( [ 5.0, 3.0 ] ); -var json = typedarray2json( arr ); -/* returns - { - 'type': 'Float64Array', - 'data': [ 5.0, 3.0 ] - } -*/ - -arr = new Float32Array( [ 5.0, -3.0 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Float32Array', - 'data': [ 5.0, -3.0 ] - } -*/ - -arr = new Complex128Array( [ 5.0, 3.0 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Complex128Array', - 'data': [ 5.0, 3.0 ] - } -*/ - -arr = new Complex64Array( [ 5.0, 3.0 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Complex64Array', - 'data': [ 5.0, 3.0 ] - } -*/ - -arr = new BooleanArray( [ true, false ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'BooleanArray', - 'data': [ 1, 0 ] - } -*/ - -arr = new Int32Array( [ -5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Int32Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint32Array( [ 5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Uint32Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Int16Array( [ -5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Int16Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint16Array( [ 5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Uint16Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Int8Array( [ -5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Int8Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint8Array( [ 5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Uint8Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Uint8ClampedArray( [ 5, 3 ] ); -json = typedarray2json( arr ); -/* returns - { - 'type': 'Uint8ClampedArray', - 'data': [ 5, 3 ] - } -*/ -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-json/benchmark/benchmark.js b/to-json/benchmark/benchmark.js deleted file mode 100644 index ff30b64b..00000000 --- a/to-json/benchmark/benchmark.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float64Array = require( './../../float64' ); -var randu = require( '@stdlib/random/base/randu' ); -var pkg = require( './../package.json' ).name; -var typedarray2json = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var o; - var i; - - arr = new Float64Array( [ randu(), randu() ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - o = typedarray2json( arr ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/to-json/benchmark/benchmark.length.js b/to-json/benchmark/benchmark.length.js deleted file mode 100644 index b1e874a8..00000000 --- a/to-json/benchmark/benchmark.length.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( './../../float64' ); -var pkg = require( './../package.json' ).name; -var typedarray2json = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr; - var i; - - arr = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - arr[ i ] = randu(); - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var o; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - o = typedarray2json( arr ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/to-json/docs/repl.txt b/to-json/docs/repl.txt deleted file mode 100644 index 704694f1..00000000 --- a/to-json/docs/repl.txt +++ /dev/null @@ -1,48 +0,0 @@ - -{{alias}}( arr ) - Returns a JSON representation of a typed array. - - The following typed array types are supported: - - - Float64Array - - Float32Array - - Int32Array - - Uint32Array - - Int16Array - - Uint16Array - - Int8Array - - Uint8Array - - Uint8ClampedArray - - Complex64Array - - Complex128Array - - BooleanArray - - The returned JSON object has the following properties: - - - type: typed array type - - data: typed array data as a generic array - - The implementation supports custom typed arrays and sets the `type` field to - the closest known typed array type. - - Parameters - ---------- - arr: TypedArray - Typed array to serialize. - - Returns - ------- - out: Object - JSON representation. - - Examples - -------- - > var arr = new {{alias:@stdlib/array/float64}}( 2 ); - > arr[ 0 ] = 5.0; - > arr[ 1 ] = 3.0; - > var json = {{alias}}( arr ) - { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] } - - See Also - -------- - diff --git a/to-json/docs/types/index.d.ts b/to-json/docs/types/index.d.ts deleted file mode 100644 index 83b55c95..00000000 --- a/to-json/docs/types/index.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { RealOrComplexTypedArray } from '@stdlib/types/array'; - -/** -* Typed array data type. -*/ -type dtype = 'Float64Array' | 'Float32Array' | 'Int32Array' | 'Uint32Array' | 'Int16Array' | 'Uint16Array' | 'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Complex64Array' | 'Complex128Array' | 'BooleanArray'; - -/** -* JSON representation of typed array. -*/ -interface JSONRepresentation { - /** - * Typed array type. - */ - type: dtype; - - /** - * Typed array data as a generic array. - */ - data: Array; -} - -/** -* Returns a JSON representation of a typed array. -* -* ## Notes -* -* - We build a JSON object representing a typed array similar to how Node.js `Buffer` objects are represented. See [Buffer][1]. -* -* [1]: https://nodejs.org/api/buffer.html#buffer_buf_tojson -* -* @param arr - typed array to serialize -* @returns JSON representation -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* var arr = new Float64Array( [ 5.0, 3.0 ] ); -* var json = typedarray2json( arr ); -* // returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] } -*/ -declare function typedarray2json( arr: RealOrComplexTypedArray ): JSONRepresentation; - - -// EXPORTS // - -export = typedarray2json; diff --git a/to-json/docs/types/test.ts b/to-json/docs/types/test.ts deleted file mode 100644 index 509be675..00000000 --- a/to-json/docs/types/test.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import typedarray2json = require( './index' ); - - -// TESTS // - -// The function returns a JSON representation... -{ - const x = new Float64Array( 10 ); - - typedarray2json( x ); // $ExpectType JSONRepresentation -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - typedarray2json( 'abc' ); // $ExpectError - typedarray2json( 123 ); // $ExpectError - typedarray2json( true ); // $ExpectError - typedarray2json( false ); // $ExpectError - typedarray2json( {} ); // $ExpectError - typedarray2json( [] ); // $ExpectError - typedarray2json( null ); // $ExpectError - typedarray2json( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float64Array( 10 ); - - typedarray2json(); // $ExpectError - typedarray2json( x, 3 ); // $ExpectError -} diff --git a/to-json/examples/index.js b/to-json/examples/index.js deleted file mode 100644 index ccd81318..00000000 --- a/to-json/examples/index.js +++ /dev/null @@ -1,141 +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'; - -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); -var typedarray2json = require( './../lib' ); - -var arr = new Float64Array( [ 5.0, 3.0 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Float64Array', - 'data': [ 5.0, 3.0 ] - } -*/ - -arr = new Float32Array( [ 5.0, -3.0 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Float32Array', - 'data': [ 5.0, -3.0 ] - } -*/ - -arr = new Complex128Array( [ 5.0, -3.0 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Complex128Array', - 'data': [ 5.0, -3.0 ] - } -*/ - -arr = new Complex64Array( [ 5.0, -3.0 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Complex64Array', - 'data': [ 5.0, -3.0 ] - } -*/ - -arr = new BooleanArray( [ true, false ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'BooleanArray', - 'data': [ 1, 0 ] - } -*/ - -arr = new Int32Array( [ -5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Int32Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint32Array( [ 5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Uint32Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Int16Array( [ -5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Int16Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint16Array( [ 5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Uint16Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Int8Array( [ -5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Int8Array', - 'data': [ -5, 3 ] - } -*/ - -arr = new Uint8Array( [ 5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Uint8Array', - 'data': [ 5, 3 ] - } -*/ - -arr = new Uint8ClampedArray( [ 5, 3 ] ); -console.log( typedarray2json( arr ) ); -/* => - { - 'type': 'Uint8ClampedArray', - 'data': [ 5, 3 ] - } -*/ diff --git a/to-json/lib/ctors.js b/to-json/lib/ctors.js deleted file mode 100644 index 9e967bdf..00000000 --- a/to-json/lib/ctors.js +++ /dev/null @@ -1,57 +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 Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Float32Array = require( './../../float32' ); -var Float64Array = require( './../../float64' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); - - -// MAIN // - -var CTORS = [ - [ Float64Array, 'Float64Array' ], - [ Float32Array, 'Float32Array' ], - [ Int32Array, 'Int32Array' ], - [ Uint32Array, 'Uint32Array' ], - [ Int16Array, 'Int16Array' ], - [ Uint16Array, 'Uint16Array' ], - [ Int8Array, 'Int8Array' ], - [ Uint8Array, 'Uint8Array' ], - [ Uint8ClampedArray, 'Uint8ClampedArray' ], - [ Complex64Array, 'Complex64Array' ], - [ Complex128Array, 'Complex128Array' ], - [ BooleanArray, 'BooleanArray' ] -]; - - -// EXPORTS // - -module.exports = CTORS; diff --git a/to-json/lib/index.js b/to-json/lib/index.js deleted file mode 100644 index f81c35cf..00000000 --- a/to-json/lib/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a JSON representation of a typed array. -* -* @module @stdlib/array/to-json -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var typedarray2json = require( '@stdlib/array/to-json' ); -* -* var arr = new Float64Array( [ 5.0, 3.0 ] ); -* var json = typedarray2json( arr ); -* // returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] } -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-json/lib/main.js b/to-json/lib/main.js deleted file mode 100644 index 4bb52114..00000000 --- a/to-json/lib/main.js +++ /dev/null @@ -1,86 +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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); -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 format = require( '@stdlib/string/format' ); -var typeName = require( './type.js' ); - - -// MAIN // - -/** -* Returns a JSON representation of a typed array. -* -* ## Notes -* -* - We build a JSON object representing a typed array similar to how Node.js `Buffer` objects are represented. See [Buffer][1]. -* -* [1]: https://nodejs.org/api/buffer.html#buffer_buf_tojson -* -* @param {TypedArray} arr - typed array to serialize -* @throws {TypeError} first argument must be a typed array -* @returns {Object} JSON representation -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* var arr = new Float64Array( [ 5.0, 3.0 ] ); -* var json = typedarray2json( arr ); -* // returns { 'type': 'Float64Array', 'data': [ 5.0, 3.0 ] } -*/ -function typedarray2json( arr ) { - var data; - var out; - var i; - - if ( isTypedArray( arr ) ) { - data = arr; - } else if ( isComplexTypedArray( arr ) ) { - if ( arr.BYTES_PER_ELEMENT === 8 ) { - data = reinterpret64( arr, 0 ); - } else { // arr.BYTES_PER_ELEMENT === 16 - data = reinterpret128( arr, 0 ); - } - } else if ( isBooleanArray( arr ) ) { - data = reinterpretBoolean( arr, 0 ); - } else { - throw new TypeError( format( 'invalid argument. Must provide a typed array. Value: `%s`.', arr ) ); - } - out = { - 'type': typeName( arr ), - 'data': [] - }; - for ( i = 0; i < data.length; i++ ) { - out.data.push( data[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = typedarray2json; diff --git a/to-json/lib/type.js b/to-json/lib/type.js deleted file mode 100644 index 23e3d1ba..00000000 --- a/to-json/lib/type.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var instanceOf = require( '@stdlib/assert/instance-of' ); -var ctorName = require( '@stdlib/utils/constructor-name' ); -var getPrototypeOf = require( '@stdlib/utils/get-prototype-of' ); -var CTORS = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns the typed array type. -* -* @private -* @param {TypedArray} arr - typed array -* @returns {(string|void)} typed array type -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* var arr = new Float64Array( 5 ); -* var str = typeName( arr ); -* // returns 'Float64Array' -*/ -function typeName( arr ) { - var v; - var i; - - // Check for typed array objects from the same realm (same Node.js `vm` or same `Window` object)... - for ( i = 0; i < CTORS.length; i++ ) { - if ( instanceOf( arr, CTORS[ i ][ 0 ] ) ) { - return CTORS[ i ][ 1 ]; - } - } - // Walk the prototype tree until we find an object having a desired native class... - while ( arr ) { - v = ctorName( arr ); - for ( i = 0; i < CTORS.length; i++ ) { - if ( v === CTORS[ i ][ 1 ] ) { - return CTORS[ i ][ 1 ]; - } - } - arr = getPrototypeOf( arr ); - } -} - - -// EXPORTS // - -module.exports = typeName; diff --git a/to-json/package.json b/to-json/package.json deleted file mode 100644 index b7150966..00000000 --- a/to-json/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@stdlib/array/to-json", - "version": "0.0.0", - "description": "Return a JSON representation of a typed array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "typed-array", - "typed array", - "serialize", - "marshal", - "tojson", - "json", - "to", - "convert" - ] -} diff --git a/to-json/test/fixtures/custom.proto.js b/to-json/test/fixtures/custom.proto.js deleted file mode 100644 index 516981e1..00000000 --- a/to-json/test/fixtures/custom.proto.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Float64Array = require( './../../../float64' ); -var defineProperty = require( '@stdlib/utils/define-property' ); - - -// MAIN // - -/** -* Creates a CustomTypedArray class. -* -* @private -* @param {TypedArray} ctor - typed array constructor -* @returns {CustomTypedArray} constructor -*/ -function createClass( ctor ) { - if ( !ctor ) { - ctor = Float64Array; - } - /** - * Create a new object which prototypically inherits from a typed array constructor. - * - * @private - * @constructor - * @param {Array} data - array data - * @returns {CustomTypedArray} custom typed array instance - */ - function CustomTypedArray( data ) { - var i; - for ( i = 0; i < data.length; i++ ) { - this[ i ] = data[ i ]; - } - defineProperty( this, 'length', { - 'configurable': false, - 'enumerable': true, - 'writable': false, - 'value': data.length - }); - return this; - } - - /** - * Create a prototype which inherits from the parent prototype. - */ - CustomTypedArray.prototype = Object.create( ctor.prototype ); - - /** - * Set the constructor. - */ - CustomTypedArray.prototype.constructor = CustomTypedArray; - - return CustomTypedArray; -} - - -// EXPORTS // - -module.exports = createClass; diff --git a/to-json/test/fixtures/custom.subclass.js b/to-json/test/fixtures/custom.subclass.js deleted file mode 100644 index 0bc23190..00000000 --- a/to-json/test/fixtures/custom.subclass.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Creates a CustomTypedArray class constructor. Note that we use function generation so that tests may be run in browsers not supporting ES2015 classes. This function may be loaded in non-ES2015 environments, but should only be invoked when ES2015 classes are supported. -* -* @private -* @param {string} ctor - typed array constructor name -* @returns {Function} constructor -*/ -function createClass( ctor ) { - var str = ''; - if ( !ctor ) { - ctor = 'Float64Array'; - } - str += '(function create() {'; - str += 'class CustomTypedArray extends '+ctor+' {'; - str += 'constructor( data ) {'; - str += 'super( data );'; - str += '}'; - str += '}'; - str += 'return CustomTypedArray;'; - str += '})()'; - return eval( str ); // eslint-disable-line no-eval -} - - -// EXPORTS // - -module.exports = createClass; diff --git a/to-json/test/test.ctors.js b/to-json/test/test.ctors.js deleted file mode 100644 index 7e3bca94..00000000 --- a/to-json/test/test.ctors.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isArray = require( '@stdlib/assert/is-array' ); -var CTORS = require( './../lib/ctors.js' ); - - -// TESTS // - -tape( 'typed array constructors are exposed via an exported array', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( isArray( CTORS ), true, 'export is an array' ); - t.ok( CTORS.length > 0, 'has length > 0' ); - t.end(); -}); diff --git a/to-json/test/test.js b/to-json/test/test.js deleted file mode 100644 index dfdd4813..00000000 --- a/to-json/test/test.js +++ /dev/null @@ -1,294 +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 vm = require( 'vm' ); // TODO: handle in-browser tests -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var hasClassSupport = require( '@stdlib/assert/has-class-support' ); -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Float32Array = require( './../../float32' ); -var Float64Array = require( './../../float64' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); -var toJSON = require( './../lib' ); - - -// FIXTURES // - -var createClass1 = require( './fixtures/custom.proto.js' ); -var createClass2 = require( './fixtures/custom.subclass.js' ); - - -// VARIABLES // - -var hasClasses = hasClassSupport(); -var opts = { - 'skip': false -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof toJSON, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if provided anything other than a typed array instance, the function will throw an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - true, - false, - [], - {}, - function noop() {}, - new Date(), - /.*/ - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws when provided a ' + (typeof values[i]) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - toJSON( value ); - }; - } -}); - -tape( 'the function returns a JSON object', function test( t ) { - var json; - var arr; - - arr = new Float64Array( [ 5.0, 3.0 ] ); - json = toJSON( arr ); - t.strictEqual( isPlainObject( json ), true, 'returns an object' ); - t.end(); -}); - -tape( 'the JSON object includes a typed array type', function test( t ) { - var expected; - var values; - var json; - var i; - - values = [ - new Float64Array( 1 ), - new Float32Array( 1 ), - new Int32Array( 1 ), - new Uint32Array( 1 ), - new Int16Array( 1 ), - new Uint16Array( 1 ), - new Int8Array( 1 ), - new Uint8Array( 1 ), - new Uint8ClampedArray( 1 ), - new Complex64Array( 1 ), - new Complex128Array( 1 ), - new BooleanArray( 1 ) - ]; - - expected = [ - 'Float64Array', - 'Float32Array', - 'Int32Array', - 'Uint32Array', - 'Int16Array', - 'Uint16Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray', - 'Complex64Array', - 'Complex128Array', - 'BooleanArray' - ]; - - for ( i = 0; i < values.length; i++ ) { - json = toJSON( values[ i ] ); - t.strictEqual( json.type, expected[ i ], 'type equal to ' + expected[ i ] ); - } - t.end(); -}); - -tape( 'the JSON object includes a data property', function test( t ) { - var expected; - var values; - var json; - var i; - - values = [ - new Float64Array( [ 1.0 ] ), - new Float32Array( [ 2.0 ] ), - new Int32Array( [ 3.0 ] ), - new Uint32Array( [ 4.0 ] ), - new Int16Array( [ 5.0 ] ), - new Uint16Array( [ 6.0 ] ), - new Int8Array( [ 7.0 ] ), - new Uint8Array( [ 8.0 ] ), - new Uint8ClampedArray( [ 9.0 ] ), - new Complex64Array( [ 1.0, 2.0 ] ), - new Complex128Array( [ 1.0, 2.0 ] ), - new BooleanArray( [ true, false ] ) - ]; - - expected = [ - [ 1.0 ], - [ 2.0 ], - [ 3.0 ], - [ 4.0 ], - [ 5.0 ], - [ 6.0 ], - [ 7.0 ], - [ 8.0 ], - [ 9.0 ], - [ 1.0, 2.0 ], - [ 1.0, 2.0 ], - [ 1, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - json = toJSON( values[ i ] ); - t.deepEqual( json.data, expected[ i ], 'has expected property value' ); - } - t.end(); -}); - -tape( 'custom typed arrays are supported (proto)', function test( t ) { - var CustomTypedArray; - var types; - var ctors; - var json; - var arr; - var i; - - ctors = [ - Float64Array, - Float32Array, - Int32Array, - Uint32Array, - Int16Array, - Uint16Array, - Int8Array, - Uint8Array, - Uint8ClampedArray - ]; - - types = [ - 'Float64Array', - 'Float32Array', - 'Int32Array', - 'Uint32Array', - 'Int16Array', - 'Uint16Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray' - ]; - - for ( i = 0; i < ctors.length; i++ ) { - CustomTypedArray = createClass1( ctors[ i ] ); - arr = new CustomTypedArray( [ 5.0, 3.0 ] ); - json = toJSON( arr ); - t.strictEqual( json.type, types[ i ], 'type equal to ' + types[ i ] ); - t.deepEqual( json.data, [ 5.0, 3.0 ], 'has expected value' ); - } - t.end(); -}); - -opts.skip = !hasClasses; -tape( 'custom typed arrays are supported (subclass; ES2015)', opts, function test( t ) { - var CustomTypedArray; - var ctors; - var json; - var arr; - var i; - - ctors = [ - 'Float64Array', - 'Float32Array', - 'Int32Array', - 'Uint32Array', - 'Int16Array', - 'Uint16Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray' - ]; - - for ( i = 0; i < ctors.length; i++ ) { - CustomTypedArray = createClass2( ctors[ i ] ); - arr = new CustomTypedArray( [ 5.0, 3.0 ] ); - json = toJSON( arr ); - t.strictEqual( json.type, ctors[ i ], 'type equal to ' + ctors[ i ] ); - t.deepEqual( json.data, [ 5.0, 3.0 ], 'has expected value' ); - } - t.end(); -}); - -opts.skip = IS_BROWSER; -tape( 'the function supports serializing a typed array from a different realm', opts, function test( t ) { - var json; - var arr; - - arr = vm.runInNewContext( 'new Float64Array( [ 5.0, 3.0 ] )', { - 'Float64Array': Float64Array - }); - json = toJSON( arr ); - - t.strictEqual( json.type, 'Float64Array', 'returns expected value' ); - t.deepEqual( json.data, [ 5.0, 3.0 ], 'returns expected value' ); - - t.end(); -}); - -opts.skip = IS_BROWSER; -tape( 'the function supports serializing an object from a different realm which inherits from a typed array', opts, function test( t ) { - var json; - var arr; - - arr = vm.runInNewContext( 'function Arr( data ) { Object.defineProperty( this, "length", {"configurable":false,"enumerable":true,"writable":false,"value":data.length}); for ( var i = 0; i < data.length; i++ ) { this[ i ] = data[ i ]; }; return this; }; Arr.prototype = Object.create( Float64Array.prototype ); Arr.prototype.constructor = Arr; new Arr( [ 5.0, 3.0 ] );', { - 'Float64Array': Float64Array - }); - json = toJSON( arr ); - - t.strictEqual( json.type, 'Float64Array', 'returns expected value' ); - t.deepEqual( json.data, [ 5.0, 3.0 ], 'returns expected value' ); - - t.end(); -}); diff --git a/to-json/test/test.type.js b/to-json/test/test.type.js deleted file mode 100644 index 0cea582a..00000000 --- a/to-json/test/test.type.js +++ /dev/null @@ -1,162 +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 tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Float32Array = require( './../../float32' ); -var Float64Array = require( './../../float64' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); -var typeName = require( './../lib/type.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typeName, 'function', 'export is a function' ); - t.end(); -}); - -tape( 'if provided a typed array, the function returns the closest typed array type', function test( t ) { - var expected; - var values; - var i; - - values = [ - new Float64Array( [ 5.0, 3.0 ] ), - new Float32Array( [ 5.0, 3.0 ] ), - new Int32Array( [ 5, 3 ] ), - new Uint32Array( [ 5, 3 ] ), - new Int16Array( [ 5, 3 ] ), - new Uint16Array( [ 5, 3 ] ), - new Int8Array( [ 5, 3 ] ), - new Uint8Array( [ 5, 3 ] ), - new Uint8ClampedArray( [ 5, 3 ] ), - new Complex64Array( [ 5.0, 3.0 ] ), - new Complex128Array( [ 5.0, 3.0 ] ), - new BooleanArray( [ true, false ] ) - ]; - - expected = [ - 'Float64Array', - 'Float32Array', - 'Int32Array', - 'Uint32Array', - 'Int16Array', - 'Uint16Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray', - 'Complex64Array', - 'Complex128Array', - 'BooleanArray' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( typeName( values[i] ), expected[ i ], 'returns the constructor name: ' + expected[ i ] ); - } - t.end(); -}); - -tape( 'if provided a typed array from a different realm, the function returns the closest typed array type', function test( t ) { - var typeName; - var expected; - var values; - var i; - - typeName = proxyquire( './../lib/type.js', { - '@stdlib/assert/instance-of': instanceOf - }); - - values = [ - new Float64Array( [ 5.0, 3.0 ] ), - new Float32Array( [ 5.0, 3.0 ] ), - new Int32Array( [ 5, 3 ] ), - new Uint32Array( [ 5, 3 ] ), - new Int16Array( [ 5, 3 ] ), - new Uint16Array( [ 5, 3 ] ), - new Int8Array( [ 5, 3 ] ), - new Uint8Array( [ 5, 3 ] ), - new Uint8ClampedArray( [ 5, 3 ] ), - new Complex64Array( [ 5.0, 3.0 ] ), - new Complex128Array( [ 5.0, 3.0 ] ), - new BooleanArray( [ true, false ] ) - ]; - - expected = [ - 'Float64Array', - 'Float32Array', - 'Int32Array', - 'Uint32Array', - 'Int16Array', - 'Uint16Array', - 'Int8Array', - 'Uint8Array', - 'Uint8ClampedArray', - 'Complex64Array', - 'Complex128Array', - 'BooleanArray' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( typeName( values[i] ), expected[ i ], 'returns the constructor name: ' + expected[ i ] ); - } - t.end(); - - function instanceOf() { - // Mocks comparing values from different realms... - return false; - } -}); - -tape( 'if not provided a typed array, the function returns `undefined`', function test( t ) { - var values; - var i; - - values = [ - '5', - NaN, - 5, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - function typedarray() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( typeName( values[i] ), void 0, 'returns expected value' ); - } - t.end(); -}); diff --git a/to-sparse-iterator-right/README.md b/to-sparse-iterator-right/README.md deleted file mode 100644 index 541c1c98..00000000 --- a/to-sparse-iterator-right/README.md +++ /dev/null @@ -1,247 +0,0 @@ - - -# sparsearray2iteratorRight - -> Create an iterator from a sparse array-like object, iterating from right to left. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var sparsearray2iteratorRight = require( '@stdlib/array/to-sparse-iterator-right' ); -``` - -#### sparsearray2iteratorRight( src\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates from right to left over each element in a sparse array-like `object`. - - - -```javascript -var it = sparsearray2iteratorRight( [ 1, , , 4 ] ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -To invoke a function for each `src` value, provide a callback function. - - - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = sparsearray2iteratorRight( [ 1, 2, , 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 20.0 - -// ... -``` - -The invoked function is provided three arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **src**: source array-like object. - - - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = sparsearray2iteratorRight( [ 1, 2, , 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 16 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 1 -``` - -To set the callback function execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = sparsearray2iteratorRight( [ 1, 2, , 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 20.0 - -var count = ctx.count; -// returns 2 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator **ignores** holes (i.e., `undefined` values). To iterate over all generic `array` elements, use [`@stdlib/array/to-iterator-right`][@stdlib/array/to-iterator-right]. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var sparsearray2iteratorRight = require( '@stdlib/array/to-sparse-iterator-right' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array partially filled with random numbers: -var arr = new Array( 100 ); -var i; -for ( i = 0; i < arr.length; i += 2 ) { - arr[ i ] = randu(); -} - -// Create an iterator from the array which scales iterated values: -var it = sparsearray2iteratorRight( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-sparse-iterator-right/benchmark/benchmark.js b/to-sparse-iterator-right/benchmark/benchmark.js deleted file mode 100644 index 3cbe2222..00000000 --- a/to-sparse-iterator-right/benchmark/benchmark.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var sparsearray2iteratorRight = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = sparsearray2iteratorRight( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - for ( i = 0; i < b.iterations; i++ ) { - values.push( i ); - } - - iter = sparsearray2iteratorRight( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - for ( i = 0; i < b.iterations; i++ ) { - values.push( i ); - } - - iter = sparsearray2iteratorRight( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-sparse-iterator-right/docs/repl.txt b/to-sparse-iterator-right/docs/repl.txt deleted file mode 100644 index 567177dd..00000000 --- a/to-sparse-iterator-right/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates from right to left over the elements of a - sparse array-like object. - - The returned iterator skips elements which are undefined. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Sparse array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, , 4 ] ); - > var v = it.next().value - 4 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/to-sparse-iterator-right/docs/types/index.d.ts b/to-sparse-iterator-right/docs/types/index.d.ts deleted file mode 100644 index 9565ea89..00000000 --- a/to-sparse-iterator-right/docs/types/index.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates from right to left over each element in a sparse array-like object. -* -* ## Notes -* -* - For dynamic array resizing, the only behavior made intentionally consistent with iterating from left to right is when elements are pushed onto the beginning (end) of an array. In other words, iterating from left to right combined with `[].push()` is consistent with iterating from right to left combined with `[].unshift()`. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = sparsearray2iteratorRight( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 1 -*/ -declare function sparsearray2iteratorRight( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = sparsearray2iteratorRight; diff --git a/to-sparse-iterator-right/docs/types/test.ts b/to-sparse-iterator-right/docs/types/test.ts deleted file mode 100644 index 8575e6b6..00000000 --- a/to-sparse-iterator-right/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import sparsearray2iteratorRight = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - sparsearray2iteratorRight( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - sparsearray2iteratorRight( 123 ); // $ExpectError - sparsearray2iteratorRight( true ); // $ExpectError - sparsearray2iteratorRight( false ); // $ExpectError - sparsearray2iteratorRight( {} ); // $ExpectError - sparsearray2iteratorRight( null ); // $ExpectError - sparsearray2iteratorRight( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], [] ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], {} ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], true ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], false ); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - sparsearray2iteratorRight(); // $ExpectError - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/to-sparse-iterator-right/examples/index.js b/to-sparse-iterator-right/examples/index.js deleted file mode 100644 index 6afa6697..00000000 --- a/to-sparse-iterator-right/examples/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sparsearray2iteratorRight = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array partially filled with random numbers: -var arr = new Array( 100 ); -var i; -for ( i = 0; i < arr.length; i += 2 ) { - arr[ i ] = randu(); -} - -// Create an iterator from the array which scales iterated values: -var it = sparsearray2iteratorRight( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-sparse-iterator-right/lib/index.js b/to-sparse-iterator-right/lib/index.js deleted file mode 100644 index ad638b12..00000000 --- a/to-sparse-iterator-right/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from a sparse array-like value, iterating from right to left. -* -* @module @stdlib/array/to-sparse-iterator-right -* -* @example -* var sparsearray2iteratorRight = require( '@stdlib/array/to-sparse-iterator-right' ); -* -* var iter = sparsearray2iteratorRight( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 1 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-sparse-iterator-right/lib/main.js b/to-sparse-iterator-right/lib/main.js deleted file mode 100644 index d193dbf0..00000000 --- a/to-sparse-iterator-right/lib/main.js +++ /dev/null @@ -1,201 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates from right to left over each element in a sparse array-like object. -* -* ## Notes -* -* - For dynamic array resizing, the only behavior made intentionally consistent with iterating from left to right is when elements are pushed onto the beginning (end) of an array. In other words, iterating from left to right combined with `[].push()` is consistent with iterating from right to left combined with `[].unshift()`. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = sparsearray2iteratorRight( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 4 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 1 -*/ -function sparsearray2iteratorRight( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var len; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - len = src.length; - i = len; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - if ( FLG ) { - return { - 'done': true - }; - } - i += src.length - len - 1; // accounts for a dynamic array - len = src.length; - while ( i >= 0 && get( src, i ) === void 0 ) { - i -= 1; - } - if ( i < 0 ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - if ( FLG ) { - return { - 'done': true - }; - } - i += src.length - len - 1; // accounts for a dynamic array - len = src.length; - while ( i >= 0 && get( src, i ) === void 0 ) { - i -= 1; - } - if ( i < 0 ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return sparsearray2iteratorRight( src, fcn, thisArg ); - } - return sparsearray2iteratorRight( src ); - } -} - - -// EXPORTS // - -module.exports = sparsearray2iteratorRight; diff --git a/to-sparse-iterator-right/package.json b/to-sparse-iterator-right/package.json deleted file mode 100644 index e9838bdb..00000000 --- a/to-sparse-iterator-right/package.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "name": "@stdlib/array/to-sparse-iterator-right", - "version": "0.0.0", - "description": "Create an iterator from a sparse array-like object, iterating from right to left.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "sparse", - "holes", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-sparse-iterator-right/test/test.js b/to-sparse-iterator-right/test/test.js deleted file mode 100644 index 0a7f3e64..00000000 --- a/to-sparse-iterator-right/test/test.js +++ /dev/null @@ -1,730 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var sparsearray2iteratorRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sparsearray2iteratorRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - sparsearray2iteratorRight( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - sparsearray2iteratorRight( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sparsearray2iteratorRight( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty array)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = new Array( 1e5 ); - expected = [ - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the last element empty: - for ( i = 0; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty start)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the first element empty: - for ( i = 1; i < values.length; i++ ) { - values[ i ] = i + 1; - } - - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty start+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the first and last elements empty: - for ( i = 1; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the last element empty: - for ( i = 0; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - - it = sparsearray2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '3': 4 - }; - - it = sparsearray2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, , 3, 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (callback)', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, 2, , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 16, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var sparsearray2iteratorRight; - var values; - var it1; - var it2; - var i; - - sparsearray2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = sparsearray2iteratorRight( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var sparsearray2iteratorRight; - var values; - var it1; - var it2; - var i; - - sparsearray2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = sparsearray2iteratorRight( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var sparsearray2iteratorRight; - var it; - - sparsearray2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var sparsearray2iteratorRight; - var it; - - sparsearray2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = sparsearray2iteratorRight( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-sparse-iterator/README.md b/to-sparse-iterator/README.md deleted file mode 100644 index 8ee42997..00000000 --- a/to-sparse-iterator/README.md +++ /dev/null @@ -1,247 +0,0 @@ - - -# sparsearray2iterator - -> Create an iterator from a sparse array-like object. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var sparsearray2iterator = require( '@stdlib/array/to-sparse-iterator' ); -``` - -#### sparsearray2iterator( src\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates over each element in a sparse array-like `object`. - - - -```javascript -var it = sparsearray2iterator( [ 1, , , 4 ] ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -var bool = it.next().done; -// returns true -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -To invoke a function for each `src` value, provide a callback function. - - - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = sparsearray2iterator( [ 1, , 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 30.0 - -// ... -``` - -The invoked function is provided three arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **src**: source array-like object. - - - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = sparsearray2iterator( [ 1, 2, , 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 16 -``` - -To set the callback function execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = sparsearray2iterator( [ 1, , 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 30.0 - -var count = ctx.count; -// returns 2 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator **ignores** holes (i.e., `undefined` values). To iterate over all generic `array` elements, use [`@stdlib/array/to-iterator`][@stdlib/array/to-iterator]. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var sparsearray2iterator = require( '@stdlib/array/to-sparse-iterator' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array partially filled with random numbers: -var arr = new Array( 100 ); -var i; -for ( i = 0; i < arr.length; i += 2 ) { - arr[ i ] = randu(); -} - -// Create an iterator from the array which scales iterated values: -var it = sparsearray2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-sparse-iterator/benchmark/benchmark.js b/to-sparse-iterator/benchmark/benchmark.js deleted file mode 100644 index 7419dc87..00000000 --- a/to-sparse-iterator/benchmark/benchmark.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var sparsearray2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = sparsearray2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - for ( i = 0; i < b.iterations; i++ ) { - values.push( i ); - } - - iter = sparsearray2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - for ( i = 0; i < b.iterations; i++ ) { - values.push( i ); - } - - iter = sparsearray2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-sparse-iterator/docs/repl.txt b/to-sparse-iterator/docs/repl.txt deleted file mode 100644 index e9febde0..00000000 --- a/to-sparse-iterator/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of a sparse array-like - object. - - The returned iterator skips elements which are undefined. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Sparse array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, , 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 3 - - See Also - -------- - diff --git a/to-sparse-iterator/docs/types/index.d.ts b/to-sparse-iterator/docs/types/index.d.ts deleted file mode 100644 index f09478fc..00000000 --- a/to-sparse-iterator/docs/types/index.d.ts +++ /dev/null @@ -1,98 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in a sparse array-like object. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = sparsearray2iterator( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 4 -*/ -declare function sparsearray2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = sparsearray2iterator; diff --git a/to-sparse-iterator/docs/types/test.ts b/to-sparse-iterator/docs/types/test.ts deleted file mode 100644 index 226ad113..00000000 --- a/to-sparse-iterator/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import sparsearray2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - sparsearray2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - sparsearray2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - sparsearray2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - sparsearray2iterator( 123 ); // $ExpectError - sparsearray2iterator( true ); // $ExpectError - sparsearray2iterator( false ); // $ExpectError - sparsearray2iterator( {} ); // $ExpectError - sparsearray2iterator( null ); // $ExpectError - sparsearray2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - sparsearray2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - sparsearray2iterator(); // $ExpectError - sparsearray2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/to-sparse-iterator/examples/index.js b/to-sparse-iterator/examples/index.js deleted file mode 100644 index 304c3b28..00000000 --- a/to-sparse-iterator/examples/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 sparsearray2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array partially filled with random numbers: -var arr = new Array( 100 ); -var i; -for ( i = 0; i < arr.length; i += 2 ) { - arr[ i ] = randu(); -} - -// Create an iterator from the array which scales iterated values: -var it = sparsearray2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-sparse-iterator/lib/index.js b/to-sparse-iterator/lib/index.js deleted file mode 100644 index e7c4cb3c..00000000 --- a/to-sparse-iterator/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from a sparse array-like value. -* -* @module @stdlib/array/to-sparse-iterator -* -* @example -* var sparsearray2iterator = require( '@stdlib/array/to-sparse-iterator' ); -* -* var iter = sparsearray2iterator( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 4 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-sparse-iterator/lib/main.js b/to-sparse-iterator/lib/main.js deleted file mode 100644 index bf8c6c5b..00000000 --- a/to-sparse-iterator/lib/main.js +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in a sparse array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = sparsearray2iterator( [ 1, , 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 4 -*/ -function sparsearray2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - var len; - if ( FLG ) { - return { - 'done': true - }; - } - len = src.length; - i += 1; - while ( i < len && get( src, i ) === void 0 ) { - i += 1; - } - if ( i >= len ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - var len; - if ( FLG ) { - return { - 'done': true - }; - } - len = src.length; - i += 1; - while ( i < len && get( src, i ) === void 0 ) { - i += 1; - } - if ( i >= len ) { - FLG = true; - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return sparsearray2iterator( src, fcn, thisArg ); - } - return sparsearray2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = sparsearray2iterator; diff --git a/to-sparse-iterator/package.json b/to-sparse-iterator/package.json deleted file mode 100644 index eb9e33c2..00000000 --- a/to-sparse-iterator/package.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "name": "@stdlib/array/to-sparse-iterator", - "version": "0.0.0", - "description": "Create an iterator from a sparse array-like object.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "sparse", - "holes", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-sparse-iterator/test/test.js b/to-sparse-iterator/test/test.js deleted file mode 100644 index 05d2abd4..00000000 --- a/to-sparse-iterator/test/test.js +++ /dev/null @@ -1,730 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var sparsearray2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sparsearray2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - sparsearray2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - sparsearray2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sparsearray2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty array)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = new Array( 1e5 ); - expected = [ - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the last element empty: - for ( i = 0; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty start)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the first element empty: - for ( i = 1; i < values.length; i++ ) { - values[ i ] = i + 1; - } - - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (empty start+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the first and last elements empty: - for ( i = 1; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = new Array( 4 ); - - // Leave the last element empty: - for ( i = 0; i < values.length-1; i++ ) { - values[ i ] = i + 1; - } - - it = sparsearray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '3': 4 - }; - - it = sparsearray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, , 3, 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (callback)', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, 2, , 4 ]; // eslint-disable-line no-sparse-arrays - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 16, - 'done': false - }, - { - 'done': true - } - ]; - - it = sparsearray2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = sparsearray2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = sparsearray2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = sparsearray2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = sparsearray2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var sparsearray2iterator; - var values; - var it1; - var it2; - var i; - - sparsearray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = sparsearray2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var sparsearray2iterator; - var values; - var it1; - var it2; - var i; - - sparsearray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = sparsearray2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var sparsearray2iterator; - var it; - - sparsearray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = sparsearray2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var sparsearray2iterator; - var it; - - sparsearray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = sparsearray2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-strided-iterator/README.md b/to-strided-iterator/README.md deleted file mode 100644 index b05e1915..00000000 --- a/to-strided-iterator/README.md +++ /dev/null @@ -1,251 +0,0 @@ - - -# Strided Iterator - -> Create an [iterator][mdn-iterator-protocol] from a strided array-like object. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var stridedarray2iterator = require( '@stdlib/array/to-strided-iterator' ); -``` - -#### stridedarray2iterator( N, src, stride, offset\[, mapFcn\[, thisArg]] ) - -Returns an [iterator][mdn-iterator-protocol] which iterates over elements in an array-like `object` according to specified stride parameters. - -```javascript -var values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - -var N = 4; -var stride = -2; -var offset = 6; - -var it = stridedarray2iterator( N, values, stride, offset ); -// returns - -var v = it.next().value; -// returns 7 - -v = it.next().value; -// returns 5 - -v = it.next().value; -// returns 3 - -// ... -``` - -The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: - -- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. -- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an iterator protocol-compliant object. - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, fcn ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -// ... -``` - -The invoked function is provided four arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **n**: iteration count (zero-based). -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, fcn ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 9 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, fcn, ctx ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned [iterator][mdn-iterator-protocol] is iterable. -- If provided a generic `array`, the returned [iterator][mdn-iterator-protocol] does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom [iterator][mdn-iterator-protocol]. -- A returned [iterator][mdn-iterator-protocol] does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an [iterator][mdn-iterator-protocol]. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned [iterator][mdn-iterator-protocol]. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined [iterator][mdn-iterator-protocol], invoke this method directly. -- The returned [iterator][mdn-iterator-protocol] supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var stridedarray2iterator = require( '@stdlib/array/to-strided-iterator' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator which scales every fourth value in reverse order: -var it = stridedarray2iterator( 25, arr, -4, 99, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-strided-iterator/benchmark/benchmark.js b/to-strided-iterator/benchmark/benchmark.js deleted file mode 100644 index 1a4b1da4..00000000 --- a/to-strided-iterator/benchmark/benchmark.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var stridedarray2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var N; - var i; - - values = [ 1, 2, 3, 4 ]; - N = values.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = stridedarray2iterator( N, values, 1, 0 ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var N; - var z; - var i; - - values = []; - values.length = b.iterations; - N = values.length; - - iter = stridedarray2iterator( N, values, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var N; - var z; - var i; - - values = []; - values.length = b.iterations; - N = values.length; - - iter = stridedarray2iterator( N, values, 1, 0, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-strided-iterator/docs/repl.txt b/to-strided-iterator/docs/repl.txt deleted file mode 100644 index 8d3dc826..00000000 --- a/to-strided-iterator/docs/repl.txt +++ /dev/null @@ -1,64 +0,0 @@ - -{{alias}}( N, src, stride, offset[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over elements of an array-like object - according to specified stride parameters. - - When invoked, an input function is provided four arguments: - - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - N: integer - Number of values to iterate. - - src: ArrayLikeObject - Array-like object from which to create the iterator. - - stride: integer - Stride length. - - offset: integer - Starting index. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( 2, [ 1, 2, 3, 4 ], -2, 3 ); - > var v = it.next().value - 4 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/to-strided-iterator/docs/types/index.d.ts b/to-strided-iterator/docs/types/index.d.ts deleted file mode 100644 index 09ce0689..00000000 --- a/to-strided-iterator/docs/types/index.d.ts +++ /dev/null @@ -1,124 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count (zero-based) -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, n: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count (zero-based) -* @param src - source array-like object -* @returns iterator value -*/ -type Quaternary = ( value: any, index: number, n: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param n - iteration count (zero-based) -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary | Quaternary; - -/** -* Returns an iterator which iterates over elements in an array-like object according to specified stride parameters. -* -* @param N - number of values to iterate -* @param src - input value -* @param stride - stride length -* @param offset - starting index -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @throws first argument must be a nonnegative integer -* @throws third argument must be an integer -* @throws fourth argument must be a nonnegative integer -* @returns iterator -* -* @example -* var values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* -* var N = 4; -* var stride = -2; -* var offset = 6; -* -* var iter = stridedarray2iterator( N, values, stride, offset ); -* -* var v = iter.next().value; -* // returns 7 -* -* v = iter.next().value; -* // returns 5 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function stridedarray2iterator( N: number, src: ArrayLike, stride: number, offset: number, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = stridedarray2iterator; diff --git a/to-strided-iterator/docs/types/test.ts b/to-strided-iterator/docs/types/test.ts deleted file mode 100644 index 721a86d4..00000000 --- a/to-strided-iterator/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import stridedarray2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectType Iterator - stridedarray2iterator( 4, [ 1, 2, 3, 4, 5, 6, 7, 8 ], -2, 6, times10 ); // $ExpectType Iterator - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - stridedarray2iterator( 'abc', [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError - stridedarray2iterator( true, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError - stridedarray2iterator( false, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError - stridedarray2iterator( {}, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError - stridedarray2iterator( null, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError - stridedarray2iterator( undefined, [ 1, 2, 3, 4 ], -2, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not array-like... -{ - stridedarray2iterator( 2, 123, -2, 3 ); // $ExpectError - stridedarray2iterator( 2, true, -2, 3 ); // $ExpectError - stridedarray2iterator( 2, false, -2, 3 ); // $ExpectError - stridedarray2iterator( 2, {}, -2, 3 ); // $ExpectError - stridedarray2iterator( 2, null, -2, 3 ); // $ExpectError - stridedarray2iterator( 2, undefined, -2, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], 'abc', 3 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], true, 3 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], false, 3 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], {}, 3 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], null, 3 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], undefined, 3 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 'abc' ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, true ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, false ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, {} ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, null ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a map function... -{ - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, 'abc' ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, 123 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, [] ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, {} ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, true ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, false ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - stridedarray2iterator(); // $ExpectError - stridedarray2iterator( 2 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ] ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2 ); // $ExpectError - stridedarray2iterator( 2, [ 1, 2, 3, 4 ], -2, 3, times10, {}, 123 ); // $ExpectError -} diff --git a/to-strided-iterator/examples/index.js b/to-strided-iterator/examples/index.js deleted file mode 100644 index 02a4cc83..00000000 --- a/to-strided-iterator/examples/index.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'; - -var Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var stridedarray2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator which scales every fourth value in reverse order: -var it = stridedarray2iterator( 25, arr, -4, 99, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-strided-iterator/lib/index.js b/to-strided-iterator/lib/index.js deleted file mode 100644 index a8703681..00000000 --- a/to-strided-iterator/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'; - -/** -* Create an iterator from a strided array-like value. -* -* @module @stdlib/array/to-strided-iterator -* -* @example -* var stridedarray2iterator = require( '@stdlib/array/to-strided-iterator' ); -* -* var values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* -* var N = 4; -* var stride = -2; -* var offset = 6; -* -* var iter = stridedarray2iterator( N, values, stride, offset ); -* -* var v = iter.next().value; -* // returns 7 -* -* v = iter.next().value; -* // returns 5 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-strided-iterator/lib/main.js b/to-strided-iterator/lib/main.js deleted file mode 100644 index aaef3031..00000000 --- a/to-strided-iterator/lib/main.js +++ /dev/null @@ -1,208 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over elements in an array-like object according to specified stride parameters. -* -* @param {NonNegativeInteger} N - number of values to iterate -* @param {Collection} src - input value -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be a nonnegative integer -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an integer -* @throws {TypeError} fourth argument must be a nonnegative integer -* @throws {TypeError} fifth argument must be a function -* @returns {Iterator} iterator -* -* @example -* var values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* -* var N = 4; -* var stride = -2; -* var offset = 6; -* -* var iter = stridedarray2iterator( N, values, stride, offset ); -* -* var v = iter.next().value; -* // returns 7 -* -* v = iter.next().value; -* // returns 5 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function stridedarray2iterator( N, src, stride, offset ) { - var thisArg; - var iter; - var FLG; - var fcn; - var idx; - var get; - var dt; - var i; - if ( !isNonNegativeInteger( N ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', N ) ); - } - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( !isInteger( stride ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', stride ) ); - } - if ( !isNonNegativeInteger( offset ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', offset ) ); - } - if ( arguments.length > 4 ) { - fcn = arguments[ 4 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 5 ]; - } - idx = offset; - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - var v; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - v = fcn.call( thisArg, get( src, idx ), idx, i, src ); - idx += stride; - return { - 'value': v, - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - var v; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - v = get( src, idx ); - idx += stride; - return { - 'value': v, - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return stridedarray2iterator( N, src, stride, offset, fcn, thisArg ); // eslint-disable-line max-len - } - return stridedarray2iterator( N, src, stride, offset ); - } -} - - -// EXPORTS // - -module.exports = stridedarray2iterator; diff --git a/to-strided-iterator/package.json b/to-strided-iterator/package.json deleted file mode 100644 index 6cf7f0ab..00000000 --- a/to-strided-iterator/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "@stdlib/array/to-strided-iterator", - "version": "0.0.0", - "description": "Create an iterator from a strided array-like object.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert", - "strided", - "stride", - "view", - "ndarray", - "multidimensional" - ] -} diff --git a/to-strided-iterator/test/test.js b/to-strided-iterator/test/test.js deleted file mode 100644 index b312cc59..00000000 --- a/to-strided-iterator/test/test.js +++ /dev/null @@ -1,760 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var stridedarray2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof stridedarray2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument 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() { - stridedarray2iterator( value, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a nonnegative integer (callback)', 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() { - stridedarray2iterator( value, [ 1, 2, 3 ], 1, 0, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an array-like object', 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() { - stridedarray2iterator( 1, value, 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an array-like object (callback)', 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() { - stridedarray2iterator( 1, value, 1, 0, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '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() { - stridedarray2iterator( 1, [ 1, 2, 3 ], value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an integer (callback)', function test( t ) { - var values; - var i; - - values = [ - '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() { - stridedarray2iterator( 1, [ 1, 2, 3 ], value, 0, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument 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() { - stridedarray2iterator( 1, [ 1, 2, 3 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not a nonnegative integer (callback)', 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() { - stridedarray2iterator( 1, [ 1, 2, 3 ], 1, value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a fifth argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedarray2iterator( 1, [ 1, 2, 3, 4 ], 1, 0, value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 5, - 'done': false - }, - { - 'value': 6, - 'done': false - }, - { - 'done': true - } - ]; - - it = stridedarray2iterator( 4, values, 1, 2 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < 4; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 8, - '0': 1, - '1': 2, - '2': 3, - '3': 4, - '4': 5, - '5': 6, - '6': 7, - '7': 8 - }; - expected = [ - { - 'value': 8, - 'done': false - }, - { - 'value': 7, - 'done': false - }, - { - 'value': 6, - 'done': false - }, - { - 'value': 5, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = stridedarray2iterator( 5, values, -1, 7 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < 5; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = stridedarray2iterator( 4, values, -1, 3, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = [ 4, 6, 6, 4 ]; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i, n ) { - v *= n + 1; - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = stridedarray2iterator( 4, values, 1, 0, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = [ 1, 4, 9, 16 ]; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = stridedarray2iterator( 4, values, 1, 0 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (callback)', function test( t ) { - var expected; - var values; - var actual; - var it; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'value': 9, - 'done': false - }, - { - 'value': 16, - 'done': false - }, - { - 'done': true - } - ]; - - it = stridedarray2iterator( 4, values, 1, 0, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - actual.push( it.next() ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0 ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0 ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var stridedarray2iterator; - var values; - var it1; - var it2; - var i; - - stridedarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = stridedarray2iterator( 4, values, 1, 0 ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var stridedarray2iterator; - var values; - var it1; - var it2; - var i; - - stridedarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = stridedarray2iterator( 4, values, 1, 0, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var stridedarray2iterator; - var it; - - stridedarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0 ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var stridedarray2iterator; - var it; - - stridedarray2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = stridedarray2iterator( 4, [ 1, 2, 3, 4 ], 1, 0, scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-view-iterator-right/README.md b/to-view-iterator-right/README.md deleted file mode 100644 index 84c6cfa8..00000000 --- a/to-view-iterator-right/README.md +++ /dev/null @@ -1,325 +0,0 @@ - - -# arrayview2iteratorRight - -> Create an iterator from an array-like object view, iterating from right to left. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var arrayview2iteratorRight = require( '@stdlib/array/to-view-iterator-right' ); -``` - -#### arrayview2iteratorRight( src\[, begin\[, end]]\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates from right to left over each element in an array-like `object` view. - -```javascript -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ] ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -The `begin` and `end` arguments define the starting (inclusive) and ending (non-inclusive) indices of the array view. By default, the returned iterator starts iterating from the last element in an array-like `object` (i.e., from the "end"). To specify an alternative view end, provide an `end` argument (non-inclusive). - -```javascript -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 3 ); -// returns - -var v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - -If `end` is less than `0`, the first iterated value is resolved relative to the last view element. For example, the following generates the same behavior as in the previous example - -```javascript -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, -1 ); -// returns - -var v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - -By default, the returned iterator iterates through the first element in an array-like `object` view. To specify an alternative view beginning, provide a `begin` argument (inclusive). - -```javascript -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1 ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -If `begin` is less than `0`, the last iterated value is resolved relative to the last view element. For example, the following generates the same behavior as in the previous example - -```javascript -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], -3 ); -// returns - -var v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 30.0 - -v = it.next().value; -// returns 20.0 - -// ... -``` - -The invoked function is provided four arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **n**: iteration count (zero-based). -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 16 - -v = it.next().value; -// returns 9 - -v = it.next().value; -// returns 4 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 40.0 - -v = it.next().value; -// returns 30.0 - -v = it.next().value; -// returns 20.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom iterator. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var arrayview2iteratorRight = require( '@stdlib/array/to-view-iterator-right' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from an array view which scales iterated values: -var it = arrayview2iteratorRight( arr, 40, 60, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-view-iterator-right/benchmark/benchmark.js b/to-view-iterator-right/benchmark/benchmark.js deleted file mode 100644 index 699761b0..00000000 --- a/to-view-iterator-right/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var arrayview2iteratorRight = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = arrayview2iteratorRight( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = arrayview2iteratorRight( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = arrayview2iteratorRight( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-view-iterator-right/docs/repl.txt b/to-view-iterator-right/docs/repl.txt deleted file mode 100644 index 1f909621..00000000 --- a/to-view-iterator-right/docs/repl.txt +++ /dev/null @@ -1,63 +0,0 @@ - -{{alias}}( src[, begin[, end]][, mapFcn[, thisArg]] ) - Returns an iterator which iterates from right to left over the elements of - an array-like object view. - - When invoked, an input function is provided four arguments: - - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - begin: integer (optional) - Starting index (inclusive). When negative, determined relative to the - last element. Default: 0. - - end: integer (optional) - Ending index (non-inclusive). When negative, determined relative to the - last element. Default: src.length. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ], 1, 3 ); - > var v = it.next().value - 3 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/to-view-iterator-right/docs/types/index.d.ts b/to-view-iterator-right/docs/types/index.d.ts deleted file mode 100644 index 59fa0e86..00000000 --- a/to-view-iterator-right/docs/types/index.d.ts +++ /dev/null @@ -1,149 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object view. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* function fcn( v ) { -* return v * 10.0; -* } -* -* var iter = arrayview2iteratorRight( [ 1, 2, 3, 4 ], fcn ); -* -* var v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* var bool = iter.next().done; -* // returns true -*/ -declare function arrayview2iteratorRight( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object view. -* -* @param src - input value -* @param begin - starting **view** index (inclusive) (default: 0) -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1 ); -* -* var v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* var bool = iter.next().done; -* // returns false -*/ -declare function arrayview2iteratorRight( src: ArrayLike, begin: number, mapFcn?: MapFunction, thisArg?: any ): Iterator; - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object view. -* -* @param src - input value -* @param begin - starting **view** index (inclusive) (default: 0) -* @param end - ending **view** index (non-inclusive) (default: src.length) -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* var bool = iter.next().done; -* // returns true -*/ -declare function arrayview2iteratorRight( src: ArrayLike, begin: number, end: number, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = arrayview2iteratorRight; diff --git a/to-view-iterator-right/docs/types/test.ts b/to-view-iterator-right/docs/types/test.ts deleted file mode 100644 index 6f74bf33..00000000 --- a/to-view-iterator-right/docs/types/test.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import arrayview2iteratorRight = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - arrayview2iteratorRight( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 2, times10 ); // $ExpectType Iterator - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 2, times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - arrayview2iteratorRight( 123 ); // $ExpectError - arrayview2iteratorRight( true ); // $ExpectError - arrayview2iteratorRight( false ); // $ExpectError - arrayview2iteratorRight( {} ); // $ExpectError - arrayview2iteratorRight( null ); // $ExpectError - arrayview2iteratorRight( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or function... -{ - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], [] ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], {} ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], true ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], false ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not number or function... -{ - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 'abc' ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, [] ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, {} ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, true ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, false ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, 'abc' ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, 123 ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, [] ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, {} ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, true ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, false ); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 0, 2, null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayview2iteratorRight(); // $ExpectError - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 2, times10, {}, 123 ); // $ExpectError -} diff --git a/to-view-iterator-right/examples/index.js b/to-view-iterator-right/examples/index.js deleted file mode 100644 index ac71da0a..00000000 --- a/to-view-iterator-right/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var arrayview2iteratorRight = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from an array view which scales iterated values: -var it = arrayview2iteratorRight( arr, 40, 60, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-view-iterator-right/lib/index.js b/to-view-iterator-right/lib/index.js deleted file mode 100644 index 6db09fc1..00000000 --- a/to-view-iterator-right/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object view, iterating from right to left. -* -* @module @stdlib/array/to-view-iterator-right -* -* @example -* var arrayview2iteratorRight = require( '@stdlib/array/to-view-iterator-right' ); -* -* var iter = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* var bool = iter.next().done; -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-view-iterator-right/lib/main.js b/to-view-iterator-right/lib/main.js deleted file mode 100644 index dbb4f5dd..00000000 --- a/to-view-iterator-right/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates from right to left over each element in an array-like object view. -* -* @param {Collection} src - input value -* @param {integer} [begin=0] - starting **view** index (inclusive) -* @param {integer} [end=src.length] - ending **view** index (non-inclusive) -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be either an integer (starting index) or a function -* @throws {TypeError} third argument must be either an integer (ending index) or a function -* @throws {TypeError} fourth argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 3 -* -* v = iter.next().value; -* // returns 2 -* -* var bool = iter.next().done; -* // returns true -*/ -function arrayview2iteratorRight( src ) { - var thisArg; - var begin; - var nargs; - var iter; - var FLG; - var fcn; - var end; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - nargs = arguments.length; - if ( nargs === 1 ) { - begin = 0; - end = src.length; - } else if ( nargs === 2 ) { - if ( isFunction( arguments[ 1 ] ) ) { - begin = 0; - fcn = arguments[ 1 ]; - } else { - begin = arguments[ 1 ]; - } - end = src.length; - } else if ( nargs === 3 ) { - if ( isFunction( arguments[ 1 ] ) ) { - begin = 0; - end = src.length; - fcn = arguments[ 1 ]; - thisArg = arguments[ 2 ]; - } else if ( isFunction( arguments[ 2 ] ) ) { - begin = arguments[ 1 ]; - end = src.length; - fcn = arguments[ 2 ]; - } else { - begin = arguments[ 1 ]; - end = arguments[ 2 ]; - } - } else { // nargs >= 4 - begin = arguments[ 1 ]; - end = arguments[ 2 ]; - fcn = arguments[ 3 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 4 ]; - } - if ( !isInteger( begin ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be either an integer (starting view index) or a function. Value: `%s`.', begin ) ); - } - if ( !isInteger( end ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be either an integer (ending view index) or a function. Value: `%s`.', end ) ); - } - if ( end < 0 ) { - end = src.length + end; - if ( end < 0 ) { - end = 0; - } - } else if ( end > src.length ) { - end = src.length; - } - if ( begin < 0 ) { - begin = src.length + begin; - if ( begin < 0 ) { - begin = 0; - } - } - i = end; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', finish ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i -= 1; - if ( FLG || i < begin ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, end-i-1, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i -= 1; - if ( FLG || i < begin ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function finish( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return arrayview2iteratorRight( src, begin, end, fcn, thisArg ); - } - return arrayview2iteratorRight( src, begin, end ); - } -} - - -// EXPORTS // - -module.exports = arrayview2iteratorRight; diff --git a/to-view-iterator-right/package.json b/to-view-iterator-right/package.json deleted file mode 100644 index 7933d12d..00000000 --- a/to-view-iterator-right/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/array/to-view-iterator-right", - "version": "0.0.0", - "description": "Create an iterator from an array-like object view, iterating from right to left.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "view", - "slice", - "reverse", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-view-iterator-right/test/test.js b/to-view-iterator-right/test/test.js deleted file mode 100644 index 5dbff1e9..00000000 --- a/to-view-iterator-right/test/test.js +++ /dev/null @@ -1,1490 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var arrayview2iteratorRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayview2iteratorRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - arrayview2iteratorRight( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin)', 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() { - arrayview2iteratorRight( value, 1 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+callback)', 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() { - arrayview2iteratorRight( value, 1, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+end)', 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() { - arrayview2iteratorRight( value, 1, 3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+end+callback)', 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() { - arrayview2iteratorRight( value, 1, 3, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - arrayview2iteratorRight( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is neither an integer nor a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iteratorRight( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iteratorRight( [ 1, 2, 3, 4 ], value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is neither an integer nor a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an integer (callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3, value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, 2 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, 1, 3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, 1, 3000 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, -3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, -300 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, -3, 3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, 1, -1 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, 0, -3000 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values, -3, -1 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 4, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 1, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iteratorRight( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (context)', function test( t ) { - var expected; - var values; - var ctx; - var it; - var r; - var i; - - ctx = { - 'count': 0 - }; - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, scale, ctx ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.equal( ctx.count, values.length, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - this.count += 1; // eslint-disable-line no-invalid-this - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, 1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, -3, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin+end)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, 0, 2, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin+end<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, 0, -2, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin<0+end<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, -3, -1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin+end<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iteratorRight( values, 1, -1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = arrayview2iteratorRight( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin)', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values, 1 ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+end)', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values, 1, 3 ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+callback)', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values, 1, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+end+callback)', function test( t ) { - var arrayview2iteratorRight; - var values; - var it1; - var it2; - var i; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iteratorRight( values, 1, 3, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin)', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1 ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+end)', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3 ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+callback)', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+end+callback)', function test( t ) { - var arrayview2iteratorRight; - var it; - - arrayview2iteratorRight = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iteratorRight( [ 1, 2, 3, 4 ], 1, 3, scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/to-view-iterator/README.md b/to-view-iterator/README.md deleted file mode 100644 index eaa6625a..00000000 --- a/to-view-iterator/README.md +++ /dev/null @@ -1,325 +0,0 @@ - - -# arrayview2iterator - -> Create an iterator from an array-like object view. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var arrayview2iterator = require( '@stdlib/array/to-view-iterator' ); -``` - -#### arrayview2iterator( src\[, begin\[, end]]\[, mapFcn\[, thisArg]] ) - -Returns an iterator which iterates over each element in an array-like `object` view. - -```javascript -var it = arrayview2iterator( [ 1, 2, 3, 4 ] ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -// ... -``` - -The returned iterator protocol-compliant object has the following properties: - -- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. -- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. - -By default, the returned iterator begins iterating from the first element in an array-like `object`. To specify an alternative starting index, provide a `begin` argument (inclusive). - -```javascript -var it = arrayview2iterator( [ 1, 2, 3, 4 ], 1 ); -// returns - -var v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 4 - -var bool = it.next().done; -// returns true -``` - -If `begin` is less than `0`, the starting index is resolved relative to the last element. For example, the following generates the same behavior as in the previous example - -```javascript -var it = arrayview2iterator( [ 1, 2, 3, 4 ], -3 ); -// returns - -var v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -v = it.next().value; -// returns 4 - -var bool = it.next().done; -// returns true -``` - -By default, the returned iterator iterates until the last element in an array-like `object`. To specify an alternative ending index, provide an `end` argument (non-inclusive). - -```javascript -var it = arrayview2iterator( [ 1, 2, 3, 4 ], 0, 3 ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -var bool = it.next().done; -// returns true -``` - -If `end` is less than `0`, the ending index is resolved relative to the last element. For example, the following generates the same behavior as in the previous example - -```javascript -var it = arrayview2iterator( [ 1, 2, 3, 4 ], 0, -1 ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -v = it.next().value; -// returns 3 - -var bool = it.next().done; -// returns true -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function fcn( v ) { - return v * 10.0; -} - -var it = arrayview2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -// ... -``` - -The invoked function is provided four arguments: - -- **value**: iterated value. -- **index**: iterated value index. -- **n**: iteration count (zero-based). -- **src**: source array-like object. - -```javascript -function fcn( v, i ) { - return v * (i+1); -} - -var it = arrayview2iterator( [ 1, 2, 3, 4 ], fcn ); -// returns - -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 4 - -v = it.next().value; -// returns 9 - -// ... -``` - -To set the callback function execution context, provide a `thisArg`. - -```javascript -function fcn( v ) { - this.count += 1; - return v * 10.0; -} - -var ctx = { - 'count': 0 -}; - -var it = arrayview2iterator( [ 1, 2, 3, 4 ], fcn, ctx ); -// returns - -var v = it.next().value; -// returns 10.0 - -v = it.next().value; -// returns 20.0 - -v = it.next().value; -// returns 30.0 - -var count = ctx.count; -// returns 3 -``` - - - - - - - -
- -## Notes - -- If an environment supports `Symbol.iterator`, the returned iterator is iterable. -- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use a custom iterator. -- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. -- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. -- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). - -
- - - - - -
- -## Examples - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var arrayview2iterator = require( '@stdlib/array/to-view-iterator' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from an array view which scales iterated values: -var it = arrayview2iterator( arr, 40, 60, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/to-view-iterator/benchmark/benchmark.js b/to-view-iterator/benchmark/benchmark.js deleted file mode 100644 index 29f5eba2..00000000 --- a/to-view-iterator/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var arrayview2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = arrayview2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = arrayview2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = arrayview2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/to-view-iterator/docs/repl.txt b/to-view-iterator/docs/repl.txt deleted file mode 100644 index 902971c3..00000000 --- a/to-view-iterator/docs/repl.txt +++ /dev/null @@ -1,63 +0,0 @@ - -{{alias}}( src[, begin[, end]][, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like object - view. - - When invoked, an input function is provided four arguments: - - - value: iterated value - - index: iterated value index - - n: iteration count (zero-based) - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - begin: integer (optional) - Starting index (inclusive). When negative, determined relative to the - last element. Default: 0. - - end: integer (optional) - Ending index (non-inclusive). When negative, determined relative to the - last element. Default: src.length. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ], 1, 3 ); - > var v = it.next().value - 2 - > v = it.next().value - 3 - - See Also - -------- - diff --git a/to-view-iterator/docs/types/index.d.ts b/to-view-iterator/docs/types/index.d.ts deleted file mode 100644 index 8d845c88..00000000 --- a/to-view-iterator/docs/types/index.d.ts +++ /dev/null @@ -1,149 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object view. -* -* @param src - input value -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* function fcn( v ) { -* return v * 10.0; -* } - -* var iter = arrayview2iterator( [ 1, 2, 3, 4 ], fcn ); -* -* var v = iter.next().value; -* // returns 10 -* -* v = iter.next().value; -* // returns 20 -* -* var bool = iter.next().done; -* // returns false -*/ -declare function arrayview2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - -/** -* Returns an iterator which iterates over each element in an array-like object view. -* -* @param src - input value -* @param begin - starting index (inclusive) (default: 0) -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = arrayview2iterator( [ 1, 2, 3, 4 ], 1 ); -* -* var v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* var bool = iter.next().done; -* // returns false -*/ -declare function arrayview2iterator( src: ArrayLike, begin: number, mapFcn?: MapFunction, thisArg?: any ): Iterator; - -/** -* Returns an iterator which iterates over each element in an array-like object view. -* -* @param src - input value -* @param begin - starting index (inclusive) (default: 0) -* @param end - ending index (non-inclusive) (default: src.length) -* @param mapFcn - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* var bool = iter.next().done; -* // returns true -*/ -declare function arrayview2iterator( src: ArrayLike, begin: number, end: number, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = arrayview2iterator; diff --git a/to-view-iterator/docs/types/test.ts b/to-view-iterator/docs/types/test.ts deleted file mode 100644 index 1ee78dd4..00000000 --- a/to-view-iterator/docs/types/test.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import arrayview2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - arrayview2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - arrayview2iterator( [ 1, 2, 3, 4 ], 1, 2, times10 ); // $ExpectType Iterator - arrayview2iterator( [ 1, 2, 3, 4 ], 1, 2, times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - arrayview2iterator( 123 ); // $ExpectError - arrayview2iterator( true ); // $ExpectError - arrayview2iterator( false ); // $ExpectError - arrayview2iterator( {} ); // $ExpectError - arrayview2iterator( null ); // $ExpectError - arrayview2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number or function... -{ - arrayview2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not number or function... -{ - arrayview2iterator( [ 1, 2, 3, 4 ], 1, 'abc' ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, [] ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, {} ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, true ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, false ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function... -{ - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, 'abc' ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, 123 ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, [] ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, {} ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, true ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, false ); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 0, 2, null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayview2iterator(); // $ExpectError - arrayview2iterator( [ 1, 2, 3, 4 ], 1, 2, times10, {}, 123 ); // $ExpectError -} diff --git a/to-view-iterator/examples/index.js b/to-view-iterator/examples/index.js deleted file mode 100644 index bdb66711..00000000 --- a/to-view-iterator/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( './../../float64' ); -var inmap = require( '@stdlib/utils/inmap' ); -var randu = require( '@stdlib/random/base/randu' ); -var arrayview2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from an array view which scales iterated values: -var it = arrayview2iterator( arr, 40, 60, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/to-view-iterator/lib/index.js b/to-view-iterator/lib/index.js deleted file mode 100644 index 6c98dfdf..00000000 --- a/to-view-iterator/lib/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object view. -* -* @module @stdlib/array/to-view-iterator -* -* @example -* var arrayview2iterator = require( '@stdlib/array/to-view-iterator' ); -* -* var iter = arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* var bool = iter.next().done; -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/to-view-iterator/lib/main.js b/to-view-iterator/lib/main.js deleted file mode 100644 index a7b042e0..00000000 --- a/to-view-iterator/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var isCollection = require( '@stdlib/assert/is-collection' ); -var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; -var isAccessorArray = require( './../../base/assert/is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var accessorGetter = require( './../../base/accessor-getter' ); -var getter = require( './../../base/getter' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object view. -* -* @param {Collection} src - input value -* @param {integer} [begin=0] - starting index (inclusive) -* @param {integer} [end=src.length] - ending index (non-inclusive) -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be either an integer (starting index) or a function -* @throws {TypeError} third argument must be either an integer (ending index) or a function -* @throws {TypeError} fourth argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3 ); -* -* var v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* var bool = iter.next().done; -* // returns true -*/ -function arrayview2iterator( src ) { - var thisArg; - var begin; - var nargs; - var iter; - var FLG; - var fcn; - var end; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - nargs = arguments.length; - if ( nargs === 1 ) { - begin = 0; - end = src.length; - } else if ( nargs === 2 ) { - if ( isFunction( arguments[ 1 ] ) ) { - begin = 0; - fcn = arguments[ 1 ]; - } else { - begin = arguments[ 1 ]; - } - end = src.length; - } else if ( nargs === 3 ) { - if ( isFunction( arguments[ 1 ] ) ) { - begin = 0; - end = src.length; - fcn = arguments[ 1 ]; - thisArg = arguments[ 2 ]; - } else if ( isFunction( arguments[ 2 ] ) ) { - begin = arguments[ 1 ]; - end = src.length; - fcn = arguments[ 2 ]; - } else { - begin = arguments[ 1 ]; - end = arguments[ 2 ]; - } - } else { // nargs >= 4 - begin = arguments[ 1 ]; - end = arguments[ 2 ]; - fcn = arguments[ 3 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 4 ]; - } - if ( !isInteger( begin ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be either an integer (starting index) or a function. Value: `%s`.', begin ) ); - } - if ( !isInteger( end ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be either an integer (ending index) or a function. Value: `%s`.', end ) ); - } - if ( end < 0 ) { - end = src.length + end; - if ( end < 0 ) { - end = 0; - } - } else if ( end > src.length ) { - end = src.length; - } - if ( begin < 0 ) { - begin = src.length + begin; - if ( begin < 0 ) { - begin = 0; - } - } - i = begin - 1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', finish ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= end ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, i-begin, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= end ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function finish( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return arrayview2iterator( src, begin, end, fcn, thisArg ); - } - return arrayview2iterator( src, begin, end ); - } -} - - -// EXPORTS // - -module.exports = arrayview2iterator; diff --git a/to-view-iterator/package.json b/to-view-iterator/package.json deleted file mode 100644 index fe5cffa5..00000000 --- a/to-view-iterator/package.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "name": "@stdlib/array/to-view-iterator", - "version": "0.0.0", - "description": "Create an iterator from an array-like object view.", - "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "utils", - "util", - "utilities", - "utility", - "typed", - "array", - "arr", - "view", - "slice", - "typed-array", - "typed array", - "iterator", - "iterate", - "iteration", - "iter", - "to", - "convert" - ] -} diff --git a/to-view-iterator/test/test.js b/to-view-iterator/test/test.js deleted file mode 100644 index 74df8447..00000000 --- a/to-view-iterator/test/test.js +++ /dev/null @@ -1,1490 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol/iterator' ); -var noop = require( '@stdlib/utils/noop' ); -var arrayview2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayview2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', 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() { - arrayview2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin)', 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() { - arrayview2iterator( value, 1 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+callback)', 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() { - arrayview2iterator( value, 1, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+end)', 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() { - arrayview2iterator( value, 1, 3 ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (begin+end+callback)', 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() { - arrayview2iterator( value, 1, 3, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', 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() { - arrayview2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is neither an integer nor a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iterator( [ 1, 2, 3, 4 ], value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is neither an integer nor a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iterator( [ 1, 2, 3, 4 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an integer (callback)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iterator( [ 1, 2, 3, 4 ], 1, value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a fourth argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3, value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, 2 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < 2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, 1, 3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < 2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, 1, 3000 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, -3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, -300 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0+end)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, -3, 3 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, 1, -1 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'done': true - } - ]; - - it = arrayview2iterator( values, 0, -3000 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (begin<0+end<0)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values, -3, -1 ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = arrayview2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (context)', function test( t ) { - var expected; - var values; - var ctx; - var it; - var r; - var i; - - ctx = { - 'count': 0 - }; - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, scale, ctx ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.equal( ctx.count, values.length, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - this.count += 1; // eslint-disable-line no-invalid-this - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, 1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, -3, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-1; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-1, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin+end)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, 1, 3, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin<0+end)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, -3, 3, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin<0+end<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, -3, -1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (begin+end<0)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = arrayview2iterator( values, 1, -1, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length-2; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length-2, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = arrayview2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = arrayview2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = arrayview2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = arrayview2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = arrayview2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin)', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values, 1 ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+end)', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values, 1, 3 ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+callback)', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values, 1, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (begin+end+callback)', function test( t ) { - var arrayview2iterator; - var values; - var it1; - var it2; - var i; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = arrayview2iterator( values, 1, 3, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin)', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ], 1 ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+end)', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3 ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+callback)', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ], 1, scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (begin+end+callback)', function test( t ) { - var arrayview2iterator; - var it; - - arrayview2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol/iterator': false - }); - - it = arrayview2iterator( [ 1, 2, 3, 4 ], 1, 3, scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/typed-complex-ctors/README.md b/typed-complex-ctors/README.md deleted file mode 100644 index 98910772..00000000 --- a/typed-complex-ctors/README.md +++ /dev/null @@ -1,142 +0,0 @@ - - -# Constructors - -> Complex typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-complex-ctors' ); -``` - -#### ctors( dtype ) - -Returns a complex typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'complex128' ); -// returns -``` - -The function returns constructors for the following data types: - -- `complex64`: single-precision floating-point complex numbers. -- `complex128`: double-precision floating-point complex numbers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'float64' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-complex-dtypes' ); -var ctors = require( '@stdlib/array/typed-complex-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-complex-ctors/benchmark/benchmark.js b/typed-complex-ctors/benchmark/benchmark.js deleted file mode 100644 index 5492c41b..00000000 --- a/typed-complex-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-complex-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-complex-ctors/docs/repl.txt b/typed-complex-ctors/docs/repl.txt deleted file mode 100644 index 26678259..00000000 --- a/typed-complex-ctors/docs/repl.txt +++ /dev/null @@ -1,29 +0,0 @@ - -{{alias}}( dtype ) - Returns a complex typed array constructor. - - The function returns constructors for the following data types: - - - complex64: single-precision floating-point complex numbers. - - complex128: double-precision floating-point complex numbers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Complex typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'complex64' ) - - > ctor = {{alias}}( 'float32' ) - null - - See Also - -------- - diff --git a/typed-complex-ctors/docs/types/index.d.ts b/typed-complex-ctors/docs/types/index.d.ts deleted file mode 100644 index 39562792..00000000 --- a/typed-complex-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,67 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); - -/** -* Returns a `Complex128Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex128' ); -* // returns -*/ -declare function ctors( dtype: 'complex128' ): typeof Complex128Array; - -/** -* Returns a `Complex64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex64' ); -* // returns -*/ -declare function ctors( dtype: 'complex64' ): typeof Complex64Array; - -/** -* Returns a complex typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'complex128' ); -* // returns -* -* @example -* var ctor = ctors( 'float64' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-complex-ctors/docs/types/test.ts b/typed-complex-ctors/docs/types/test.ts deleted file mode 100644 index 833338c1..00000000 --- a/typed-complex-ctors/docs/types/test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'complex128' ); // $ExpectType Complex128ArrayConstructor - ctors( 'complex64' ); // $ExpectType Complex64ArrayConstructor - ctors( 'float' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'complex128', 3 ); // $ExpectError -} diff --git a/typed-complex-ctors/examples/index.js b/typed-complex-ctors/examples/index.js deleted file mode 100644 index c72b9537..00000000 --- a/typed-complex-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-complex-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-complex-ctors/lib/ctors.js b/typed-complex-ctors/lib/ctors.js deleted file mode 100644 index 7e99df7a..00000000 --- a/typed-complex-ctors/lib/ctors.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'complex128': Complex128Array, - 'complex64': Complex64Array -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-complex-ctors/lib/index.js b/typed-complex-ctors/lib/index.js deleted file mode 100644 index 72fa15b6..00000000 --- a/typed-complex-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Complex typed array constructors. -* -* @module @stdlib/array/typed-complex-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-complex-ctors' ); -* -* var ctor = ctors( 'complex128' ); -* // returns -* -* ctor = ctors( 'float64' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-complex-ctors/lib/main.js b/typed-complex-ctors/lib/main.js deleted file mode 100644 index 83f8cc72..00000000 --- a/typed-complex-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a complex typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'complex128' ); -* // returns -* -* @example -* var ctor = ctors( 'float64' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-complex-ctors/package.json b/typed-complex-ctors/package.json deleted file mode 100644 index 128401b9..00000000 --- a/typed-complex-ctors/package.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "name": "@stdlib/array/typed-complex-ctors", - "version": "0.0.0", - "description": "Complex typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "complex", - "cmplx", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-complex-ctors/test/test.js b/typed-complex-ctors/test/test.js deleted file mode 100644 index ee76e0bf..00000000 --- a/typed-complex-ctors/test/test.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-complex-dtypes' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns complex typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'complex128', - 'complex64' - ]; - expected = [ - Complex128Array, - Complex64Array - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported complex typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits', - 'float64', - 'float32', - 'uint32', - 'int32', - 'uint16', - 'int16', - 'uint8', - 'uint8c', - 'int8' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-complex-dtypes/README.md b/typed-complex-dtypes/README.md deleted file mode 100644 index e07d02cb..00000000 --- a/typed-complex-dtypes/README.md +++ /dev/null @@ -1,145 +0,0 @@ - - -# Data Types - -> List of complex typed array data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-complex-dtypes' ); -``` - -#### dtypes() - -Returns a list of complex typed array data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'complex64', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-complex-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'complex64' ); -// returns true - -bool = isdtype( 'complex128' ); -// returns true - -bool = isdtype( 'uint8' ); -// returns false - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-complex-dtypes/benchmark/benchmark.js b/typed-complex-dtypes/benchmark/benchmark.js deleted file mode 100644 index ebfc4ee6..00000000 --- a/typed-complex-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length < 2 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-complex-dtypes/docs/repl.txt b/typed-complex-dtypes/docs/repl.txt deleted file mode 100644 index 033d6f08..00000000 --- a/typed-complex-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of complex typed array data types. - - Returns - ------- - out: Array - List of complex typed array data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-complex-dtypes/docs/types/index.d.ts b/typed-complex-dtypes/docs/types/index.d.ts deleted file mode 100644 index 834a4d02..00000000 --- a/typed-complex-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ComplexFloatingPointDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of complex typed array data types. -* -* @returns list of complex typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'complex64', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-complex-dtypes/docs/types/test.ts b/typed-complex-dtypes/docs/types/test.ts deleted file mode 100644 index e88b6ef9..00000000 --- a/typed-complex-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType ComplexFloatingPointDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-complex-dtypes/examples/index.js b/typed-complex-dtypes/examples/index.js deleted file mode 100644 index ce0f9de1..00000000 --- a/typed-complex-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'complex64' ); -console.log( bool ); -// => true - -bool = isdtype( 'complex128' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint16' ); -console.log( bool ); -// => false - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-complex-dtypes/lib/index.js b/typed-complex-dtypes/lib/index.js deleted file mode 100644 index 54e110f5..00000000 --- a/typed-complex-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of complex typed array data types. -* -* @module @stdlib/array/typed-complex-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-complex-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'complex64', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-complex-dtypes/lib/main.js b/typed-complex-dtypes/lib/main.js deleted file mode 100644 index 4ebd8cf6..00000000 --- a/typed-complex-dtypes/lib/main.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'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of complex typed array data types. -* -* @returns {StringArray} list of complex typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'complex64', ... ] -*/ -function dtypes() { - return dt( 'complex_floating_point' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-complex-dtypes/package.json b/typed-complex-dtypes/package.json deleted file mode 100644 index 6676c7ce..00000000 --- a/typed-complex-dtypes/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/array/typed-complex-dtypes", - "version": "0.0.0", - "description": "List of complex typed array data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "complex", - "cmplx", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-complex-dtypes/test/test.js b/typed-complex-dtypes/test/test.js deleted file mode 100644 index 04560b6a..00000000 --- a/typed-complex-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of complex typed array data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'complex_floating_point' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-complex/README.md b/typed-complex/README.md deleted file mode 100644 index dfbd13e4..00000000 --- a/typed-complex/README.md +++ /dev/null @@ -1,221 +0,0 @@ - - -# Complex Typed Arrays - -> Create a complex number typed array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var complexarray = require( '@stdlib/array/typed-complex' ); -``` - -#### complexarray( \[dtype] ) - -Creates a complex number typed array having a specified data type `dtype`. - -```javascript -var arr = complexarray(); -// returns -``` - -The function recognizes the following data types: - -- `complex128`: double-precision complex floating-point numbers -- `complex64`: single-precision complex floating-point numbers - -By default, the output complex number typed array data type is `complex128`. To specify an alternative data type, provide a `dtype` argument. - -```javascript -var arr = complexarray( 'complex64' ); -// returns -``` - -#### complexarray( length\[, dtype] ) - -Returns a complex number typed array having a specified `length`. - -```javascript -var arr1 = complexarray( 5 ); -// returns - -var arr2 = complexarray( 5, 'complex64' ); -// returns -``` - -#### complexarray( complexarray\[, dtype] ) - -Creates a complex number typed array from another complex number typed array. - -```javascript -var arr1 = complexarray( [ 5.0, -3.0, 2.0, 1.0 ] ); -// returns - -var arr2 = complexarray( arr1 ); -// returns - -var arr3 = complexarray( arr1, 'complex64' ); -// returns -``` - -#### complexarray( obj\[, dtype] ) - -Creates a complex number typed array from an array-like object or iterable. - -```javascript -var arr1 = complexarray( [ 0.5, 0.5, 0.5, 0.5 ] ); -// returns - -var arr2 = complexarray( [ 0.5, 0.5, 0.5, 0.5 ], 'complex64' ); -// returns -``` - -If a provided array-like object contains interleaved real and imaginary components, the array-like object must have a length which is a multiple of two. - -#### complexarray( buffer\[, byteOffset\[, length]]\[, dtype] ) - -Returns a complex number typed array view of an [`ArrayBuffer`][mdn-arraybuffer]. - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); -var buf = new ArrayBuffer( 64 ); - -var arr1 = complexarray( buf ); -// returns - -var arr2 = complexarray( buf, 'complex64' ); -// returns - -var arr3 = complexarray( buf, 32 ); -// returns - -var arr4 = complexarray( buf, 32, 'complex64' ); -// returns - -var arr5 = complexarray( buf, 32, 1 ); -// returns - -var arr6 = complexarray( buf, 24, 4, 'complex64' ); -// returns -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var complexarray = require( '@stdlib/array/typed-complex' ); - -function rand() { - var re = discreteUniform( -10, 10 ); - var im = discreteUniform( -10, 10 ); - return new Complex128( re, im ); -} - -// Create a new complex number typed array: -var arr = complexarray( 100, 'complex128' ); - -// Fill the array with random complex numbers: -gfillBy( arr.length, arr, 1, rand ); - -// Reinterpret the complex number array as a `Float64Array`: -var view = reinterpret128( arr, 0 ); - -// View the results: -console.log( view ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-complex/benchmark/benchmark.js b/typed-complex/benchmark/benchmark.js deleted file mode 100644 index b711b590..00000000 --- a/typed-complex/benchmark/benchmark.js +++ /dev/null @@ -1,83 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var complexarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = complexarray( 0 ); - 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 = complexarray( 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(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = complexarray( 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(); -}); diff --git a/typed-complex/benchmark/benchmark.length.complex128.js b/typed-complex/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 7e28e469..00000000 --- a/typed-complex/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var complexarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = complexarray( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - 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( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/typed-complex/benchmark/benchmark.length.complex64.js b/typed-complex/benchmark/benchmark.length.complex64.js deleted file mode 100644 index f7713153..00000000 --- a/typed-complex/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var complexarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = complexarray( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - 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( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/typed-complex/docs/repl.txt b/typed-complex/docs/repl.txt deleted file mode 100644 index 014eab17..00000000 --- a/typed-complex/docs/repl.txt +++ /dev/null @@ -1,137 +0,0 @@ - -{{alias}}( [dtype] ) - Creates a complex typed array. - - The function supports the following data types: - - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - The default typed array data type is `complex128`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'complex128'. - - Returns - ------- - out: ComplexArray - A complex number typed array. - - Examples - -------- - > var arr = {{alias}}() - - > arr = {{alias}}( 'complex64' ) - - - -{{alias}}( length[, dtype] ) - Returns a complex number typed array having a specified length. - - Parameters - ---------- - length: integer - Array length. - - dtype: string (optional) - Data type. Default: 'complex128'. - - Returns - ------- - out: ComplexArray - A complex number typed array. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'complex64' ) - - - -{{alias}}( complexarray[, dtype] ) - Creates a complex number typed array from another complex number typed - array. - - Parameters - ---------- - complexarray: ComplexArray - Complex number typed array from which to generate another complex number - typed array. - - dtype: string (optional) - Data type. Default: 'complex128'. - - Returns - ------- - out: ComplexArray - A complex number typed array. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'complex64' ) - - - -{{alias}}( obj[, dtype] ) - Creates a complex number typed array from an array-like object or iterable. - - If an array-like object contains interleaved real and imaginary components, - the array-like object must have a length which is a multiple of two. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate an array. - - dtype: string (optional) - Data type. Default: 'complex128'. - - Returns - ------- - out: ComplexArray - A complex number typed array. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'complex64' ) - - - -{{alias}}( buffer[, byteOffset[, length]][, dtype] ) - Returns a complex number typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first array element. - Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - dtype: string (optional) - Data type. Default: 'complex128'. - - Returns - ------- - out: ComplexArray - A complex number typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 64 ); - > var arr = {{alias}}( buf, 0, 8, 'complex64' ) - - - See Also - -------- - diff --git a/typed-complex/docs/types/index.d.ts b/typed-complex/docs/types/index.d.ts deleted file mode 100644 index f6c407df..00000000 --- a/typed-complex/docs/types/index.d.ts +++ /dev/null @@ -1,171 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/// - -import { ArrayLike, ComplexTypedArray, ComplexFloatingPointDataTypeMap as DataTypeMap } from '@stdlib/types/array'; -import ArrayBuffer = require( './../../../buffer' ); - -/** -* Creates a complex number typed array. -* -* @param dtype - data type (default: 'complex128') -* @returns complex number typed array -* -* @example -* var arr = complexarray(); -* // returns -* -* @example -* var arr = complexarray( 'complex64'); -* // returns -*/ -declare function complexarray( dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param length - typed array length -* @param dtype - data type (default: 'complex128') -* @returns typed array -* -* @example -* var arr = complexarray( 2 ); -* // returns -* -* @example -* var arr = complexarray( 2, 'complex64' ); -* // returns -*/ -declare function complexarray( length: number, dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param complexarray - complex number typed array from which to generate another complex number typed array -* @param dtype - data type (default: 'complex128') -* @returns complex number typed array -* -* @example -* var arr = complexarray( new Complex128Array( 2 ) ); -* // returns -* -* @example -* var arr = complexarray( new Complex128Array( 2 ), 'complex64' ); -* // returns -*/ -declare function complexarray( complexarray: ComplexTypedArray, dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param obj - array-like object or iterable from which to generate a typed array -* @param dtype - data type (default: 'complex128') -* @throws array length must be a multiple of two -* @returns complex number typed array -* -* @example -* var arr = complexarray( [ 0.5, 0.5 ] ); -* // returns -* -* @example -* var arr = complexarray( [ 5, -3 ], 'complex64' ); -* // returns -*/ -declare function complexarray( obj: ArrayLike | Iterable, dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param buffer - underlying ArrayBuffer -* @param dtype - data type (default: 'complex128') -* @returns complex number typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 'complex64' ); -* // returns -*/ -declare function complexarray( buffer: ArrayBuffer, dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first array element (default: 0) -* @param dtype - data type (default: 'complex128') -* @returns complex number typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16, 'complex64' ); -* // returns -*/ -declare function complexarray( buffer: ArrayBuffer, byteOffset?: number, dtype?: T ): DataTypeMap[T]; - -/** -* Creates a complex number typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first array element (default: 0) -* @param length - view length; if not provided, the view spans from the byteOffset to the end of the underlying ArrayBuffer -* @param dtype - data type (default: 'complex128') -* @returns complex number typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2, 'complex64' ); -* // returns -*/ -declare function complexarray( buffer: ArrayBuffer, byteOffset?: number, length?: number, dtype?: T ): DataTypeMap[T]; - - -// EXPORTS // - -export = complexarray; diff --git a/typed-complex/docs/types/test.ts b/typed-complex/docs/types/test.ts deleted file mode 100644 index 33077f3b..00000000 --- a/typed-complex/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import complexarray = require( './index' ); - - -// TESTS // - -// The function returns a typed array.. -{ - complexarray(); // $ExpectType Complex128Array - complexarray( 'complex64' ); // $ExpectType Complex64Array - complexarray( 10, 'complex64' ); // $ExpectType Complex64Array - complexarray( [ 1, 2, 3 ], 'complex128' ); // $ExpectType Complex128Array -} - -// The compiler throws an error if the function is provided a first argument which is not a data type, number, array-like object, or typed array... -{ - complexarray( true ); // $ExpectError - complexarray( false ); // $ExpectError - complexarray( {} ); // $ExpectError - complexarray( null ); // $ExpectError - complexarray( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const buf = new ArrayBuffer( 64 ); - complexarray( buf, 16, 2, 'complex128', {} ); // $ExpectError -} diff --git a/typed-complex/examples/index.js b/typed-complex/examples/index.js deleted file mode 100644 index d812af15..00000000 --- a/typed-complex/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var complexarray = require( './../lib' ); - -function rand() { - var re = discreteUniform( -10, 10 ); - var im = discreteUniform( -10, 10 ); - return new Complex128( re, im ); -} - -// Create a new complex number typed array: -var arr = complexarray( 100, 'complex128' ); - -// Fill the array with random complex numbers: -gfillBy( arr.length, arr, 1, rand ); - -// Reinterpret the complex number array as a `Float64Array`: -var view = reinterpret128( arr, 0 ); - -// View the results: -console.log( view ); diff --git a/typed-complex/lib/index.js b/typed-complex/lib/index.js deleted file mode 100644 index 0255ea94..00000000 --- a/typed-complex/lib/index.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a complex number typed array. -* -* @module @stdlib/array/typed-complex -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr = complexarray(); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr = complexarray( 2 ); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr = complexarray( 2, 'complex64' ); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr = complexarray( [ 0.5, 0.5 ] ); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr = complexarray( [ 5.0, -3.0 ], 'complex64' ); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr1 = complexarray( [ 5.0, 3.0 ], 'complex64' ); -* var arr2 = complexarray( arr1 ); -* // returns -* -* @example -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var arr1 = complexarray( [ 5.0, 3.0 ], 'complex128' ); -* var arr2 = complexarray( arr1, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var complexarray = require( '@stdlib/array/typed-complex' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2, 'complex64' ); -* // returns -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-complex/lib/main.js b/typed-complex/lib/main.js deleted file mode 100644 index 8603b9d3..00000000 --- a/typed-complex/lib/main.js +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 ctors = require( './../../typed-complex-ctors' ); -var defaults = require( './../../defaults' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = defaults.get( 'dtypes.complex_floating_point' ); - - -// MAIN // - -/** -* Creates a complex number typed array. -* -* @param {(NonNegativeInteger|ComplexArray|ArrayLikeObject|ArrayBuffer)} [arg] - a length, typed array, array-like object, or buffer -* @param {NonNegativeInteger} [byteOffset=0] - byte offset -* @param {NonNegativeInteger} [length] - view length -* @param {string} [dtype="complex128"] - data type -* @throws {TypeError} must provide a recognized data type -* @returns {ComplexArray} typed array -* -* @example -* var arr = complexarray(); -* // returns -* -* @example -* var arr = complexarray( 2 ); -* // returns -* -* @example -* var arr = complexarray( 2, 'complex64' ); -* // returns -* -* @example -* var arr = complexarray( [ 0.5, 0.5 ] ); -* // returns -* -* @example -* var arr = complexarray( [ 5.0, -3.0 ], 'complex64' ); -* // returns -* -* @example -* var arr1 = complexarray( [ 5.0, 3.0 ], 'complex64' ); -* var arr2 = complexarray( arr1 ); -* // returns -* -* @example -* var arr1 = complexarray( [ 5.0, 3.0 ], 'complex128' ); -* var arr2 = complexarray( arr1, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = complexarray( buf, 16, 'complex64' ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2 ); -* // returns -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 64 ); -* var arr = complexarray( buf, 16, 2, 'complex64' ); -* // returns -*/ -function complexarray() { - var nargs; - var dtype; - var ctor; - - 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 ); - } - if ( nargs === 1 ) { - return new ctor( arguments[0] ); - } - if ( nargs === 2 ) { - return new ctor( arguments[0], arguments[1] ); - } - return new ctor( arguments[0], arguments[1], arguments[2] ); -} - - -// EXPORTS // - -module.exports = complexarray; diff --git a/typed-complex/package.json b/typed-complex/package.json deleted file mode 100644 index 0b889539..00000000 --- a/typed-complex/package.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "name": "@stdlib/array/typed-complex", - "version": "0.0.0", - "description": "Create a complex number typed array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "complex64array", - "complex128array", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "complex", - "cmplx" - ] -} diff --git a/typed-complex/test/test.js b/typed-complex/test/test.js deleted file mode 100644 index d52419a6..00000000 --- a/typed-complex/test/test.js +++ /dev/null @@ -1,603 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var Float64Array = require( './../../float64' ); -var ArrayBuffer = require( './../../buffer' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var complexarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof complexarray, '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', - 'complexarray', - '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() { - complexarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'complexarray', - '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() { - complexarray( 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', - 'complexarray', - '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() { - complexarray( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (complex typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'complexarray', - '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() { - complexarray( new Complex64Array( 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', - 'complexarray', - '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() { - complexarray( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'complexarray', - '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() { - complexarray( new ArrayBuffer( 32 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'complexarray', - '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() { - complexarray( new ArrayBuffer( 32 ), 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset, length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'complexarray', - '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() { - complexarray( new ArrayBuffer( 32 ), 0, 1, value ); - }; - } -}); - -tape( 'the function returns a complex number typed array (default)', function test( t ) { - var arr = complexarray(); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128)', function test( t ) { - var arr = complexarray( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64)', function test( t ) { - var arr = complexarray( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, length)', function test( t ) { - var arr = complexarray( 10 ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, length)', function test( t ) { - var arr = complexarray( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, length)', function test( t ) { - var arr = complexarray( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = complexarray( arr ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = complexarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = complexarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, complex typed array)', function test( t ) { - var viewX; - var viewY; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - viewX = reinterpret128( arr, 0 ); - viewY = reinterpret128( out, 0 ); - t.strictEqual( viewY[ 0 ], viewX[ 0 ], 'returns expected value' ); - t.strictEqual( viewY[ 1 ], viewX[ 1 ], 'returns expected value' ); - t.strictEqual( viewY[ 2 ], viewX[ 2 ], 'returns expected value' ); - t.strictEqual( viewY[ 3 ], viewX[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, complex typed array)', function test( t ) { - var viewX; - var viewY; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - viewX = reinterpret128( arr, 0 ); - viewY = reinterpret128( out, 0 ); - t.strictEqual( viewY[ 0 ], viewX[ 0 ], 'returns expected value' ); - t.strictEqual( viewY[ 1 ], viewX[ 1 ], 'returns expected value' ); - t.strictEqual( viewY[ 2 ], viewX[ 2 ], 'returns expected value' ); - t.strictEqual( viewY[ 3 ], viewX[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, complex typed array)', function test( t ) { - var viewX; - var viewY; - var arr; - var out; - - arr = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = complexarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - viewX = reinterpret64( arr, 0 ); - viewY = reinterpret64( out, 0 ); - t.strictEqual( viewY[ 0 ], viewX[ 0 ], 'returns expected value' ); - t.strictEqual( viewY[ 1 ], viewX[ 1 ], 'returns expected value' ); - t.strictEqual( viewY[ 2 ], viewX[ 2 ], 'returns expected value' ); - t.strictEqual( viewY[ 3 ], viewX[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = complexarray( buf ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = complexarray( buf, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = complexarray( buf, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 64 ); - var out = complexarray( buf, 16 ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 64 ); - var out = complexarray( buf, 16, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = complexarray( buf, 8, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (default, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 64 ); - var out = complexarray( buf, 16, 2 ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex128, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 64 ); - var out = complexarray( buf, 16, 2, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a complex number typed array (dtype=complex64, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = complexarray( buf, 8, 2, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.end(); -}); diff --git a/typed-ctors/README.md b/typed-ctors/README.md deleted file mode 100644 index a867b8af..00000000 --- a/typed-ctors/README.md +++ /dev/null @@ -1,146 +0,0 @@ - - -# Constructors - -> Typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-ctors' ); -``` - -#### ctors( dtype ) - -Returns a typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'float64' ); -// returns -``` - -The function returns constructors for the following data types: - -- `float32`: single-precision floating-point numbers. -- `float64`: double-precision floating-point numbers. -- `complex64`: single-precision complex floating-point numbers. -- `complex128`: double-precision complex floating-point numbers. -- `bool`: boolean values. -- `int16`: signed 16-bit integers. -- `int32`: signed 32-bit integers. -- `int8`: signed 8-bit integers. -- `uint16`: unsigned 16-bit integers. -- `uint32`: unsigned 32-bit integers. -- `uint8`: unsigned 8-bit integers. -- `uint8c`: unsigned clamped 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'float' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-dtypes' ); -var ctors = require( '@stdlib/array/typed-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-ctors/benchmark/benchmark.js b/typed-ctors/benchmark/benchmark.js deleted file mode 100644 index 9e0dd226..00000000 --- a/typed-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-ctors/docs/repl.txt b/typed-ctors/docs/repl.txt deleted file mode 100644 index e7a9fcc5..00000000 --- a/typed-ctors/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( dtype ) - Returns a typed array constructor. - - The function returns constructors for the following data types: - - - float32: single-precision floating-point numbers. - - float64: double-precision floating-point numbers. - - complex64: single-precision complex floating-point numbers. - - complex128: double-precision complex floating-point numbers. - - bool: boolean values. - - int16: signed 16-bit integers. - - int32: signed 32-bit integers. - - int8: signed 8-bit integers. - - uint16: unsigned 16-bit integers. - - uint32: unsigned 32-bit integers. - - uint8: unsigned 8-bit integers. - - uint8c: unsigned clamped 8-bit integers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'float64' ) - - > ctor = {{alias}}( 'float' ) - null - - See Also - -------- - diff --git a/typed-ctors/docs/types/index.d.ts b/typed-ctors/docs/types/index.d.ts deleted file mode 100644 index e798a0f8..00000000 --- a/typed-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,188 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); -import BooleanArray = require( './../../../bool' ); - -/** -* Returns a `Float64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -*/ -declare function ctors( dtype: 'float64' ): typeof Float64Array; - -/** -* Returns a `Float32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float32' ); -* // returns -*/ -declare function ctors( dtype: 'float32' ): typeof Float32Array; - -/** -* Returns a `Complex128Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex128' ); -* // returns -*/ -declare function ctors( dtype: 'complex128' ): typeof Complex128Array; - -/** -* Returns a `Complex64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex64' ); -* // returns -*/ -declare function ctors( dtype: 'complex64' ): typeof Complex64Array; - -/** -* Returns a `BooleanArray` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'bool' ); -* // returns -*/ -declare function ctors( dtype: 'bool' ): typeof BooleanArray; - -/** -* Returns an `Int32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -*/ -declare function ctors( dtype: 'int32' ): typeof Int32Array; - -/** -* Returns an `Int16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int16' ); -* // returns -*/ -declare function ctors( dtype: 'int16' ): typeof Int16Array; - -/** -* Returns an `Int8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int8' ); -* // returns -*/ -declare function ctors( dtype: 'int8' ): typeof Int8Array; - -/** -* Returns a `Uint32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -*/ -declare function ctors( dtype: 'uint32' ): typeof Uint32Array; - -/** -* Returns a `Uint16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint16' ); -* // returns -*/ -declare function ctors( dtype: 'uint16' ): typeof Uint16Array; - -/** -* Returns a `Uint8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8' ); -* // returns -*/ -declare function ctors( dtype: 'uint8' ): typeof Uint8Array; - -/** -* Returns a `Uint8ClampedArray` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8c' ); -* // returns -*/ -declare function ctors( dtype: 'uint8c' ): typeof Uint8ClampedArray; - -/** -* Returns a typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-ctors/docs/types/test.ts b/typed-ctors/docs/types/test.ts deleted file mode 100644 index d96259b7..00000000 --- a/typed-ctors/docs/types/test.ts +++ /dev/null @@ -1,45 +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. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'float64' ); // $ExpectType Float64ArrayConstructor - ctors( 'float32' ); // $ExpectType Float32ArrayConstructor - ctors( 'complex128' ); // $ExpectType Complex128ArrayConstructor - ctors( 'complex64' ); // $ExpectType Complex64ArrayConstructor - ctors( 'bool' ); // $ExpectType BooleanArrayConstructor - ctors( 'int32' ); // $ExpectType Int32ArrayConstructor - ctors( 'int16' ); // $ExpectType Int16ArrayConstructor - ctors( 'int8' ); // $ExpectType Int8ArrayConstructor - ctors( 'uint32' ); // $ExpectType Uint32ArrayConstructor - ctors( 'uint16' ); // $ExpectType Uint16ArrayConstructor - ctors( 'uint8' ); // $ExpectType Uint8ArrayConstructor - ctors( 'uint8c' ); // $ExpectType Uint8ClampedArrayConstructor - ctors( 'float' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'int32', 3 ); // $ExpectError -} diff --git a/typed-ctors/examples/index.js b/typed-ctors/examples/index.js deleted file mode 100644 index 20cfa25a..00000000 --- a/typed-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-ctors/lib/ctors.js b/typed-ctors/lib/ctors.js deleted file mode 100644 index 83bb1429..00000000 --- a/typed-ctors/lib/ctors.js +++ /dev/null @@ -1,58 +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 Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'float64': Float64Array, - 'float32': Float32Array, - 'int16': Int16Array, - 'int32': Int32Array, - 'int8': Int8Array, - 'uint16': Uint16Array, - 'uint32': Uint32Array, - 'uint8': Uint8Array, - 'uint8c': Uint8ClampedArray, - 'complex64': Complex64Array, - 'complex128': Complex128Array, - 'bool': BooleanArray -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-ctors/lib/index.js b/typed-ctors/lib/index.js deleted file mode 100644 index e26c8c4d..00000000 --- a/typed-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructors. -* -* @module @stdlib/array/typed-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-ctors' ); -* -* var ctor = ctors( 'float64' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-ctors/lib/main.js b/typed-ctors/lib/main.js deleted file mode 100644 index d045f901..00000000 --- a/typed-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-ctors/package.json b/typed-ctors/package.json deleted file mode 100644 index 1ce679c2..00000000 --- a/typed-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-ctors", - "version": "0.0.0", - "description": "Typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-ctors/test/test.js b/typed-ctors/test/test.js deleted file mode 100644 index d0098d93..00000000 --- a/typed-ctors/test/test.js +++ /dev/null @@ -1,128 +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 tape = require( 'tape' ); -var dtypes = require( './../../typed-dtypes' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var BooleanArray = require( './../../bool' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'float64', - 'float32', - 'int16', - 'int32', - 'int8', - 'uint16', - 'uint32', - 'uint8', - 'uint8c', - 'complex64', - 'complex128', - 'bool' - ]; - expected = [ - Float64Array, - Float32Array, - Int16Array, - Int32Array, - Int8Array, - Uint16Array, - Uint32Array, - Uint8Array, - Uint8ClampedArray, - Complex64Array, - Complex128Array, - BooleanArray - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-dtypes/README.md b/typed-dtypes/README.md deleted file mode 100644 index ddf28f28..00000000 --- a/typed-dtypes/README.md +++ /dev/null @@ -1,139 +0,0 @@ - - -# Data Types - -> List of typed array data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'float32', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -// returns true - -bool = isdtype( 'int16' ); -// returns true - -bool = isdtype( 'uint8' ); -// returns true - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-dtypes/benchmark/benchmark.js b/typed-dtypes/benchmark/benchmark.js deleted file mode 100644 index 331cee04..00000000 --- a/typed-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length < 9 ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-dtypes/docs/repl.txt b/typed-dtypes/docs/repl.txt deleted file mode 100644 index c53b7ea2..00000000 --- a/typed-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array data types. - - Returns - ------- - out: Array - List of typed array data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-dtypes/docs/types/index.d.ts b/typed-dtypes/docs/types/index.d.ts deleted file mode 100644 index a42666ea..00000000 --- a/typed-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array data types. -* -* @returns list of typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-dtypes/docs/types/test.ts b/typed-dtypes/docs/types/test.ts deleted file mode 100644 index 873807c7..00000000 --- a/typed-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType TypedDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-dtypes/examples/index.js b/typed-dtypes/examples/index.js deleted file mode 100644 index dffc9666..00000000 --- a/typed-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -console.log( bool ); -// => true - -bool = isdtype( 'int8' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint16' ); -console.log( bool ); -// => true - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-dtypes/lib/index.js b/typed-dtypes/lib/index.js deleted file mode 100644 index ff86c929..00000000 --- a/typed-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array data types. -* -* @module @stdlib/array/typed-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-dtypes/lib/main.js b/typed-dtypes/lib/main.js deleted file mode 100644 index f10c1a6c..00000000 --- a/typed-dtypes/lib/main.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'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array data types. -* -* @returns {StringArray} list of typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -function dtypes() { - return dt( 'typed' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-dtypes/package.json b/typed-dtypes/package.json deleted file mode 100644 index e54c50f1..00000000 --- a/typed-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-dtypes", - "version": "0.0.0", - "description": "List of typed array data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-dtypes/test/test.js b/typed-dtypes/test/test.js deleted file mode 100644 index 4b79abc8..00000000 --- a/typed-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'typed' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-float-ctors/README.md b/typed-float-ctors/README.md deleted file mode 100644 index 66bf3e25..00000000 --- a/typed-float-ctors/README.md +++ /dev/null @@ -1,126 +0,0 @@ - - -# Constructors - -> Floating-point typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-float-ctors' ); -``` - -#### ctors( dtype ) - -Returns a floating-point typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'float64' ); -// returns -``` - -The function returns constructors for the following data types: - -- `float32`: single-precision floating-point numbers. -- `float64`: double-precision floating-point numbers. -- `complex64`: single-precision complex floating-point numbers. -- `complex128`: double-precision complex floating-point numbers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'float' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-float-dtypes' ); -var ctors = require( '@stdlib/array/typed-float-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-float-ctors/benchmark/benchmark.js b/typed-float-ctors/benchmark/benchmark.js deleted file mode 100644 index cb2d90bd..00000000 --- a/typed-float-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-float-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-float-ctors/docs/repl.txt b/typed-float-ctors/docs/repl.txt deleted file mode 100644 index b80331b8..00000000 --- a/typed-float-ctors/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( dtype ) - Returns a floating-point typed array constructor. - - The function returns constructors for the following data types: - - - float32: single-precision floating-point numbers. - - float64: double-precision floating-point numbers. - - complex64: single-precision complex floating-point numbers. - - complex128: double-precision complex floating-point numbers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'float64' ) - - > ctor = {{alias}}( 'float' ) - null - - See Also - -------- - diff --git a/typed-float-ctors/docs/types/index.d.ts b/typed-float-ctors/docs/types/index.d.ts deleted file mode 100644 index 9b5e7992..00000000 --- a/typed-float-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); - -/** -* Returns a `Float64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -*/ -declare function ctors( dtype: 'float64' ): typeof Float64Array; - -/** -* Returns a `Float32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float32' ); -* // returns -*/ -declare function ctors( dtype: 'float32' ): typeof Float32Array; - -/** -* Returns a `Complex128Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex128' ); -* // returns -*/ -declare function ctors( dtype: 'complex128' ): typeof Complex128Array; - -/** -* Returns a `Complex64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'complex64' ); -* // returns -*/ -declare function ctors( dtype: 'complex64' ): typeof Complex64Array; - -/** -* Returns a floating-point typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-float-ctors/docs/types/test.ts b/typed-float-ctors/docs/types/test.ts deleted file mode 100644 index 41c670b3..00000000 --- a/typed-float-ctors/docs/types/test.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'float64' ); // $ExpectType Float64ArrayConstructor - ctors( 'float32' ); // $ExpectType Float32ArrayConstructor - ctors( 'complex128' ); // $ExpectType Complex128ArrayConstructor - ctors( 'complex64' ); // $ExpectType Complex64ArrayConstructor - ctors( 'float' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'float64', 3 ); // $ExpectError -} diff --git a/typed-float-ctors/examples/index.js b/typed-float-ctors/examples/index.js deleted file mode 100644 index 8d6b3f27..00000000 --- a/typed-float-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-float-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-float-ctors/lib/ctors.js b/typed-float-ctors/lib/ctors.js deleted file mode 100644 index feeb0cf7..00000000 --- a/typed-float-ctors/lib/ctors.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'float64': Float64Array, - 'float32': Float32Array, - 'complex128': Complex128Array, - 'complex64': Complex64Array -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-float-ctors/lib/index.js b/typed-float-ctors/lib/index.js deleted file mode 100644 index 8e300036..00000000 --- a/typed-float-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Floating-point typed array constructors. -* -* @module @stdlib/array/typed-float-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-float-ctors' ); -* -* var ctor = ctors( 'float64' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-float-ctors/lib/main.js b/typed-float-ctors/lib/main.js deleted file mode 100644 index 4640e851..00000000 --- a/typed-float-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a floating-point typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-float-ctors/package.json b/typed-float-ctors/package.json deleted file mode 100644 index a02305b5..00000000 --- a/typed-float-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-float-ctors", - "version": "0.0.0", - "description": "Floating-point typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-float-ctors/test/test.js b/typed-float-ctors/test/test.js deleted file mode 100644 index 9e3208c8..00000000 --- a/typed-float-ctors/test/test.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-float-dtypes' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'float64', - 'float32', - 'complex128', - 'complex64' - ]; - expected = [ - Float64Array, - Float32Array, - Complex128Array, - Complex64Array - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-float-dtypes/README.md b/typed-float-dtypes/README.md deleted file mode 100644 index fbcf4cf6..00000000 --- a/typed-float-dtypes/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Data Types - -> List of typed array floating-point data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-float-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array floating-point data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'float32', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-float-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -// returns true - -bool = isdtype( 'complex128' ); -// returns true - -bool = isdtype( 'float32' ); -// returns true - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-float-dtypes/benchmark/benchmark.js b/typed-float-dtypes/benchmark/benchmark.js deleted file mode 100644 index 0df6510b..00000000 --- a/typed-float-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length <= 2 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-float-dtypes/docs/repl.txt b/typed-float-dtypes/docs/repl.txt deleted file mode 100644 index f35ce870..00000000 --- a/typed-float-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array floating-point data types. - - Returns - ------- - out: Array - List of typed array floating-point data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-float-dtypes/docs/types/index.d.ts b/typed-float-dtypes/docs/types/index.d.ts deleted file mode 100644 index cb80383e..00000000 --- a/typed-float-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { FloatingPointDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array floating-point data types. -* -* @returns list of typed array floating-point data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-float-dtypes/docs/types/test.ts b/typed-float-dtypes/docs/types/test.ts deleted file mode 100644 index 72bb9167..00000000 --- a/typed-float-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType FloatingPointDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-float-dtypes/examples/index.js b/typed-float-dtypes/examples/index.js deleted file mode 100644 index 7917242b..00000000 --- a/typed-float-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -console.log( bool ); -// => true - -bool = isdtype( 'complex128' ); -console.log( bool ); -// => true - -bool = isdtype( 'float32' ); -console.log( bool ); -// => true - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-float-dtypes/lib/index.js b/typed-float-dtypes/lib/index.js deleted file mode 100644 index 342e7b14..00000000 --- a/typed-float-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array floating-point data types. -* -* @module @stdlib/array/typed-float-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-float-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'float32', 'float64', 'complex64', 'complex128' ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-float-dtypes/lib/main.js b/typed-float-dtypes/lib/main.js deleted file mode 100644 index 9148c293..00000000 --- a/typed-float-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array floating-point data types. -* -* @returns {StringArray} list of typed array floating-point data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -function dtypes() { - return dt( 'floating_point' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-float-dtypes/package.json b/typed-float-dtypes/package.json deleted file mode 100644 index 57d288d4..00000000 --- a/typed-float-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-float-dtypes", - "version": "0.0.0", - "description": "List of typed array floating-point data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-float-dtypes/test/test.js b/typed-float-dtypes/test/test.js deleted file mode 100644 index 87ee20e3..00000000 --- a/typed-float-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array floating-point data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'floating_point' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-integer-ctors/README.md b/typed-integer-ctors/README.md deleted file mode 100644 index 7a58a4e2..00000000 --- a/typed-integer-ctors/README.md +++ /dev/null @@ -1,129 +0,0 @@ - - -# Constructors - -> Integer-valued typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-integer-ctors' ); -``` - -#### ctors( dtype ) - -Returns an integer-valued typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'int32' ); -// returns -``` - -The function returns constructors for the following data types: - -- `int16`: signed 16-bit integers. -- `int32`: signed 32-bit integers. -- `int8`: signed 8-bit integers. -- `uint16`: unsigned 16-bit integers. -- `uint32`: unsigned 32-bit integers. -- `uint8`: unsigned 8-bit integers. -- `uint8c`: unsigned clamped 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'int' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-integer-dtypes' ); -var ctors = require( '@stdlib/array/typed-integer-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-integer-ctors/benchmark/benchmark.js b/typed-integer-ctors/benchmark/benchmark.js deleted file mode 100644 index c0585ee1..00000000 --- a/typed-integer-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-integer-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-integer-ctors/docs/repl.txt b/typed-integer-ctors/docs/repl.txt deleted file mode 100644 index 7c2c7045..00000000 --- a/typed-integer-ctors/docs/repl.txt +++ /dev/null @@ -1,34 +0,0 @@ - -{{alias}}( dtype ) - Returns an integer-valued typed array constructor. - - The function returns constructors for the following data types: - - - int16: signed 16-bit integers. - - int32: signed 32-bit integers. - - int8: signed 8-bit integers. - - uint16: unsigned 16-bit integers. - - uint32: unsigned 32-bit integers. - - uint8: unsigned 8-bit integers. - - uint8c: unsigned clamped 8-bit integers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'int32' ) - - > ctor = {{alias}}( 'int' ) - null - - See Also - -------- - diff --git a/typed-integer-ctors/docs/types/index.d.ts b/typed-integer-ctors/docs/types/index.d.ts deleted file mode 100644 index 75f34402..00000000 --- a/typed-integer-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,124 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Returns an `Int32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -*/ -declare function ctors( dtype: 'int32' ): typeof Int32Array; - -/** -* Returns an `Int16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int16' ); -* // returns -*/ -declare function ctors( dtype: 'int16' ): typeof Int16Array; - -/** -* Returns an `Int8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int8' ); -* // returns -*/ -declare function ctors( dtype: 'int8' ): typeof Int8Array; - -/** -* Returns a `Uint32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -*/ -declare function ctors( dtype: 'uint32' ): typeof Uint32Array; - -/** -* Returns a `Uint16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint16' ); -* // returns -*/ -declare function ctors( dtype: 'uint16' ): typeof Uint16Array; - -/** -* Returns a `Uint8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8' ); -* // returns -*/ -declare function ctors( dtype: 'uint8' ): typeof Uint8Array; - -/** -* Returns a `Uint8ClampedArray` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8c' ); -* // returns -*/ -declare function ctors( dtype: 'uint8c' ): typeof Uint8ClampedArray; - -/** -* Returns an integer-valued typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -* -* @example -* var ctor = ctors( 'int' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-integer-ctors/docs/types/test.ts b/typed-integer-ctors/docs/types/test.ts deleted file mode 100644 index 4649207d..00000000 --- a/typed-integer-ctors/docs/types/test.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'int32' ); // $ExpectType Int32ArrayConstructor - ctors( 'int16' ); // $ExpectType Int16ArrayConstructor - ctors( 'int8' ); // $ExpectType Int8ArrayConstructor - ctors( 'uint32' ); // $ExpectType Uint32ArrayConstructor - ctors( 'uint16' ); // $ExpectType Uint16ArrayConstructor - ctors( 'uint8' ); // $ExpectType Uint8ArrayConstructor - ctors( 'uint8c' ); // $ExpectType Uint8ClampedArrayConstructor - ctors( 'int' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'int32', 3 ); // $ExpectError -} diff --git a/typed-integer-ctors/examples/index.js b/typed-integer-ctors/examples/index.js deleted file mode 100644 index 34d66dea..00000000 --- a/typed-integer-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-integer-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-integer-ctors/lib/ctors.js b/typed-integer-ctors/lib/ctors.js deleted file mode 100644 index fc640426..00000000 --- a/typed-integer-ctors/lib/ctors.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'int16': Int16Array, - 'int32': Int32Array, - 'int8': Int8Array, - 'uint16': Uint16Array, - 'uint32': Uint32Array, - 'uint8': Uint8Array, - 'uint8c': Uint8ClampedArray -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-integer-ctors/lib/index.js b/typed-integer-ctors/lib/index.js deleted file mode 100644 index 3cade485..00000000 --- a/typed-integer-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Integer-valued typed array constructors. -* -* @module @stdlib/array/typed-integer-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-integer-ctors' ); -* -* var ctor = ctors( 'int32' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-integer-ctors/lib/main.js b/typed-integer-ctors/lib/main.js deleted file mode 100644 index 38782950..00000000 --- a/typed-integer-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns an integer-valued typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -* -* @example -* var ctor = ctors( 'int' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-integer-ctors/package.json b/typed-integer-ctors/package.json deleted file mode 100644 index f4546c58..00000000 --- a/typed-integer-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-integer-ctors", - "version": "0.0.0", - "description": "Integer-valued typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-integer-ctors/test/test.js b/typed-integer-ctors/test/test.js deleted file mode 100644 index a852edd8..00000000 --- a/typed-integer-ctors/test/test.js +++ /dev/null @@ -1,113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-integer-dtypes' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'int16', - 'int32', - 'int8', - 'uint16', - 'uint32', - 'uint8', - 'uint8c' - ]; - expected = [ - Int16Array, - Int32Array, - Int8Array, - Uint16Array, - Uint32Array, - Uint8Array, - Uint8ClampedArray - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-integer-dtypes/README.md b/typed-integer-dtypes/README.md deleted file mode 100644 index 714e6179..00000000 --- a/typed-integer-dtypes/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Data Types - -> List of typed array integer data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-integer-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array integer data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'int16', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-integer-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'int32' ); -// returns true - -bool = isdtype( 'int16' ); -// returns true - -bool = isdtype( 'uint8' ); -// returns true - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-integer-dtypes/benchmark/benchmark.js b/typed-integer-dtypes/benchmark/benchmark.js deleted file mode 100644 index 0df6510b..00000000 --- a/typed-integer-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length <= 2 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-integer-dtypes/docs/repl.txt b/typed-integer-dtypes/docs/repl.txt deleted file mode 100644 index d1e78b21..00000000 --- a/typed-integer-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array integer data types. - - Returns - ------- - out: Array - List of typed array integer data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-integer-dtypes/docs/types/index.d.ts b/typed-integer-dtypes/docs/types/index.d.ts deleted file mode 100644 index 992b010b..00000000 --- a/typed-integer-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { IntegerDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array integer data types. -* -* @returns list of typed array integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-integer-dtypes/docs/types/test.ts b/typed-integer-dtypes/docs/types/test.ts deleted file mode 100644 index d833942e..00000000 --- a/typed-integer-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType IntegerDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-integer-dtypes/examples/index.js b/typed-integer-dtypes/examples/index.js deleted file mode 100644 index 6b5cbdc8..00000000 --- a/typed-integer-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'int32' ); -console.log( bool ); -// => true - -bool = isdtype( 'int8' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint16' ); -console.log( bool ); -// => true - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-integer-dtypes/lib/index.js b/typed-integer-dtypes/lib/index.js deleted file mode 100644 index 2cac16b6..00000000 --- a/typed-integer-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array integer data types. -* -* @module @stdlib/array/typed-integer-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-integer-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-integer-dtypes/lib/main.js b/typed-integer-dtypes/lib/main.js deleted file mode 100644 index 90fdfd73..00000000 --- a/typed-integer-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array integer data types. -* -* @returns {StringArray} list of typed array integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ -function dtypes() { - return dt( 'integer' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-integer-dtypes/package.json b/typed-integer-dtypes/package.json deleted file mode 100644 index 7e1b80d9..00000000 --- a/typed-integer-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-integer-dtypes", - "version": "0.0.0", - "description": "List of typed array integer data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-integer-dtypes/test/test.js b/typed-integer-dtypes/test/test.js deleted file mode 100644 index 4a3829e5..00000000 --- a/typed-integer-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'integer' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-real-ctors/README.md b/typed-real-ctors/README.md deleted file mode 100644 index 6635e4d3..00000000 --- a/typed-real-ctors/README.md +++ /dev/null @@ -1,146 +0,0 @@ - - -# Constructors - -> Typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-real-ctors' ); -``` - -#### ctors( dtype ) - -Returns a typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'float64' ); -// returns -``` - -The function returns constructors for the following data types: - -- `float32`: single-precision floating-point numbers. -- `float64`: double-precision floating-point numbers. -- `int16`: signed 16-bit integers. -- `int32`: signed 32-bit integers. -- `int8`: signed 8-bit integers. -- `uint16`: unsigned 16-bit integers. -- `uint32`: unsigned 32-bit integers. -- `uint8`: unsigned 8-bit integers. -- `uint8c`: unsigned clamped 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'float' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-real-dtypes' ); -var ctors = require( '@stdlib/array/typed-real-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-real-ctors/benchmark/benchmark.js b/typed-real-ctors/benchmark/benchmark.js deleted file mode 100644 index 5e2b2828..00000000 --- a/typed-real-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-real-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-real-ctors/docs/repl.txt b/typed-real-ctors/docs/repl.txt deleted file mode 100644 index 335f22ad..00000000 --- a/typed-real-ctors/docs/repl.txt +++ /dev/null @@ -1,36 +0,0 @@ - -{{alias}}( dtype ) - Returns a typed array constructor. - - The function returns constructors for the following data types: - - - float32: single-precision floating-point numbers. - - float64: double-precision floating-point numbers. - - int16: signed 16-bit integers. - - int32: signed 32-bit integers. - - int8: signed 8-bit integers. - - uint16: unsigned 16-bit integers. - - uint32: unsigned 32-bit integers. - - uint8: unsigned 8-bit integers. - - uint8c: unsigned clamped 8-bit integers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'float64' ) - - > ctor = {{alias}}( 'float' ) - null - - See Also - -------- - diff --git a/typed-real-ctors/docs/types/index.d.ts b/typed-real-ctors/docs/types/index.d.ts deleted file mode 100644 index e1a44c54..00000000 --- a/typed-real-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,148 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Returns a `Float64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -*/ -declare function ctors( dtype: 'float64' ): typeof Float64Array; - -/** -* Returns a `Float32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float32' ); -* // returns -*/ -declare function ctors( dtype: 'float32' ): typeof Float32Array; - -/** -* Returns an `Int32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -*/ -declare function ctors( dtype: 'int32' ): typeof Int32Array; - -/** -* Returns an `Int16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int16' ); -* // returns -*/ -declare function ctors( dtype: 'int16' ): typeof Int16Array; - -/** -* Returns an `Int8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int8' ); -* // returns -*/ -declare function ctors( dtype: 'int8' ): typeof Int8Array; - -/** -* Returns a `Uint32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -*/ -declare function ctors( dtype: 'uint32' ): typeof Uint32Array; - -/** -* Returns a `Uint16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint16' ); -* // returns -*/ -declare function ctors( dtype: 'uint16' ): typeof Uint16Array; - -/** -* Returns a `Uint8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8' ); -* // returns -*/ -declare function ctors( dtype: 'uint8' ): typeof Uint8Array; - -/** -* Returns a `Uint8ClampedArray` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8c' ); -* // returns -*/ -declare function ctors( dtype: 'uint8c' ): typeof Uint8ClampedArray; - -/** -* Returns a typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-real-ctors/docs/types/test.ts b/typed-real-ctors/docs/types/test.ts deleted file mode 100644 index 8137a947..00000000 --- a/typed-real-ctors/docs/types/test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'float64' ); // $ExpectType Float64ArrayConstructor - ctors( 'float32' ); // $ExpectType Float32ArrayConstructor - ctors( 'int32' ); // $ExpectType Int32ArrayConstructor - ctors( 'int16' ); // $ExpectType Int16ArrayConstructor - ctors( 'int8' ); // $ExpectType Int8ArrayConstructor - ctors( 'uint32' ); // $ExpectType Uint32ArrayConstructor - ctors( 'uint16' ); // $ExpectType Uint16ArrayConstructor - ctors( 'uint8' ); // $ExpectType Uint8ArrayConstructor - ctors( 'uint8c' ); // $ExpectType Uint8ClampedArrayConstructor - ctors( 'float' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'int32', 3 ); // $ExpectError -} diff --git a/typed-real-ctors/examples/index.js b/typed-real-ctors/examples/index.js deleted file mode 100644 index 04769e08..00000000 --- a/typed-real-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-real-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-real-ctors/lib/ctors.js b/typed-real-ctors/lib/ctors.js deleted file mode 100644 index b8e8bd51..00000000 --- a/typed-real-ctors/lib/ctors.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'float64': Float64Array, - 'float32': Float32Array, - 'int16': Int16Array, - 'int32': Int32Array, - 'int8': Int8Array, - 'uint16': Uint16Array, - 'uint32': Uint32Array, - 'uint8': Uint8Array, - 'uint8c': Uint8ClampedArray -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-real-ctors/lib/index.js b/typed-real-ctors/lib/index.js deleted file mode 100644 index d79084f9..00000000 --- a/typed-real-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructors. -* -* @module @stdlib/array/typed-real-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-real-ctors' ); -* -* var ctor = ctors( 'float64' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-real-ctors/lib/main.js b/typed-real-ctors/lib/main.js deleted file mode 100644 index d1db7989..00000000 --- a/typed-real-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-real-ctors/package.json b/typed-real-ctors/package.json deleted file mode 100644 index c0fb2d4a..00000000 --- a/typed-real-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-real-ctors", - "version": "0.0.0", - "description": "Typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-real-ctors/test/test.js b/typed-real-ctors/test/test.js deleted file mode 100644 index d401a716..00000000 --- a/typed-real-ctors/test/test.js +++ /dev/null @@ -1,119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-real-dtypes' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'float64', - 'float32', - 'int16', - 'int32', - 'int8', - 'uint16', - 'uint32', - 'uint8', - 'uint8c' - ]; - expected = [ - Float64Array, - Float32Array, - Int16Array, - Int32Array, - Int8Array, - Uint16Array, - Uint32Array, - Uint8Array, - Uint8ClampedArray - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-real-dtypes/README.md b/typed-real-dtypes/README.md deleted file mode 100644 index 866bedf3..00000000 --- a/typed-real-dtypes/README.md +++ /dev/null @@ -1,139 +0,0 @@ - - -# Data Types - -> List of typed array real-valued data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-real-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array real-valued data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'float32', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-real-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -// returns true - -bool = isdtype( 'int16' ); -// returns true - -bool = isdtype( 'uint8' ); -// returns true - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-real-dtypes/benchmark/benchmark.js b/typed-real-dtypes/benchmark/benchmark.js deleted file mode 100644 index b4e58baa..00000000 --- a/typed-real-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length < 9 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-real-dtypes/docs/repl.txt b/typed-real-dtypes/docs/repl.txt deleted file mode 100644 index 430bd693..00000000 --- a/typed-real-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array real-valued data types. - - Returns - ------- - out: Array - List of typed array data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-real-dtypes/docs/types/index.d.ts b/typed-real-dtypes/docs/types/index.d.ts deleted file mode 100644 index bef865a5..00000000 --- a/typed-real-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { RealDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array real-valued data types. -* -* @returns list of typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-real-dtypes/docs/types/test.ts b/typed-real-dtypes/docs/types/test.ts deleted file mode 100644 index 3ddca3af..00000000 --- a/typed-real-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType RealDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-real-dtypes/examples/index.js b/typed-real-dtypes/examples/index.js deleted file mode 100644 index df9a237c..00000000 --- a/typed-real-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -console.log( bool ); -// => true - -bool = isdtype( 'int8' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint16' ); -console.log( bool ); -// => true - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-real-dtypes/lib/index.js b/typed-real-dtypes/lib/index.js deleted file mode 100644 index 10162cc5..00000000 --- a/typed-real-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array real-valued data types. -* -* @module @stdlib/array/typed-real-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-real-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-real-dtypes/lib/main.js b/typed-real-dtypes/lib/main.js deleted file mode 100644 index 1bee4c1b..00000000 --- a/typed-real-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array real-valued data types. -* -* @returns {StringArray} list of typed array data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -function dtypes() { - return dt( 'real' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-real-dtypes/package.json b/typed-real-dtypes/package.json deleted file mode 100644 index a9c84d30..00000000 --- a/typed-real-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-real-dtypes", - "version": "0.0.0", - "description": "List of typed array real-valued data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-real-dtypes/test/test.js b/typed-real-dtypes/test/test.js deleted file mode 100644 index 96f373ab..00000000 --- a/typed-real-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array real-valued data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'real' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-real-float-ctors/README.md b/typed-real-float-ctors/README.md deleted file mode 100644 index 90731bee..00000000 --- a/typed-real-float-ctors/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Constructors - -> Real-valued floating-point typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-real-float-ctors' ); -``` - -#### ctors( dtype ) - -Returns a real-valued floating-point typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'float64' ); -// returns -``` - -The function returns constructors for the following data types: - -- `float32`: single-precision floating-point numbers. -- `float64`: double-precision floating-point numbers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'float' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-real-float-dtypes' ); -var ctors = require( '@stdlib/array/typed-real-float-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-real-float-ctors/benchmark/benchmark.js b/typed-real-float-ctors/benchmark/benchmark.js deleted file mode 100644 index 186c9790..00000000 --- a/typed-real-float-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-real-float-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-real-float-ctors/docs/repl.txt b/typed-real-float-ctors/docs/repl.txt deleted file mode 100644 index e0feb1ce..00000000 --- a/typed-real-float-ctors/docs/repl.txt +++ /dev/null @@ -1,29 +0,0 @@ - -{{alias}}( dtype ) - Returns a real-valued floating-point typed array constructor. - - The function returns constructors for the following data types: - - - float32: single-precision floating-point numbers. - - float64: double-precision floating-point numbers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'float64' ) - - > ctor = {{alias}}( 'float' ) - null - - See Also - -------- - diff --git a/typed-real-float-ctors/docs/types/index.d.ts b/typed-real-float-ctors/docs/types/index.d.ts deleted file mode 100644 index 43b60eea..00000000 --- a/typed-real-float-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Returns a `Float64Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -*/ -declare function ctors( dtype: 'float64' ): typeof Float64Array; - -/** -* Returns a `Float32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'float32' ); -* // returns -*/ -declare function ctors( dtype: 'float32' ): typeof Float32Array; - -/** -* Returns a real-valued floating-point typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-real-float-ctors/docs/types/test.ts b/typed-real-float-ctors/docs/types/test.ts deleted file mode 100644 index 67bcbf2f..00000000 --- a/typed-real-float-ctors/docs/types/test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'float64' ); // $ExpectType Float64ArrayConstructor - ctors( 'float32' ); // $ExpectType Float32ArrayConstructor - ctors( 'float' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'float64', 3 ); // $ExpectError -} diff --git a/typed-real-float-ctors/examples/index.js b/typed-real-float-ctors/examples/index.js deleted file mode 100644 index 74257115..00000000 --- a/typed-real-float-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-real-float-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-real-float-ctors/lib/ctors.js b/typed-real-float-ctors/lib/ctors.js deleted file mode 100644 index 1651dc49..00000000 --- a/typed-real-float-ctors/lib/ctors.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'float64': Float64Array, - 'float32': Float32Array -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-real-float-ctors/lib/index.js b/typed-real-float-ctors/lib/index.js deleted file mode 100644 index 8d5b3661..00000000 --- a/typed-real-float-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Real-valued floating-point typed array constructors. -* -* @module @stdlib/array/typed-real-float-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-real-float-ctors' ); -* -* var ctor = ctors( 'float64' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-real-float-ctors/lib/main.js b/typed-real-float-ctors/lib/main.js deleted file mode 100644 index 703a0c95..00000000 --- a/typed-real-float-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a real-valued floating-point typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'float64' ); -* // returns -* -* @example -* var ctor = ctors( 'float' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-real-float-ctors/package.json b/typed-real-float-ctors/package.json deleted file mode 100644 index 8c4b881d..00000000 --- a/typed-real-float-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-real-float-ctors", - "version": "0.0.0", - "description": "Real-valued floating-point typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-real-float-ctors/test/test.js b/typed-real-float-ctors/test/test.js deleted file mode 100644 index 28650880..00000000 --- a/typed-real-float-ctors/test/test.js +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-real-float-dtypes' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'float64', - 'float32' - ]; - expected = [ - Float64Array, - Float32Array - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-real-float-dtypes/README.md b/typed-real-float-dtypes/README.md deleted file mode 100644 index 36d42067..00000000 --- a/typed-real-float-dtypes/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Data Types - -> List of typed array real-valued floating-point data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-real-float-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array real-valued floating-point data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'float32', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-real-float-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -// returns true - -bool = isdtype( 'float32' ); -// returns true - -bool = isdtype( 'complex128' ); -// returns false - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-real-float-dtypes/benchmark/benchmark.js b/typed-real-float-dtypes/benchmark/benchmark.js deleted file mode 100644 index 5ca3dd71..00000000 --- a/typed-real-float-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length <= 1 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-real-float-dtypes/docs/repl.txt b/typed-real-float-dtypes/docs/repl.txt deleted file mode 100644 index fc9b563a..00000000 --- a/typed-real-float-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array real-valued floating-point data types. - - Returns - ------- - out: Array - List of typed array real-valued floating-point data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-real-float-dtypes/docs/types/index.d.ts b/typed-real-float-dtypes/docs/types/index.d.ts deleted file mode 100644 index 8237c65f..00000000 --- a/typed-real-float-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { RealFloatingPointDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array real-valued floating-point data types. -* -* @returns list of typed array real-valued floating-point data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-real-float-dtypes/docs/types/test.ts b/typed-real-float-dtypes/docs/types/test.ts deleted file mode 100644 index 38e2c071..00000000 --- a/typed-real-float-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType RealFloatingPointDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-real-float-dtypes/examples/index.js b/typed-real-float-dtypes/examples/index.js deleted file mode 100644 index ac1bee1c..00000000 --- a/typed-real-float-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'float64' ); -console.log( bool ); -// => true - -bool = isdtype( 'float32' ); -console.log( bool ); -// => true - -bool = isdtype( 'complex128' ); -console.log( bool ); -// => false - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-real-float-dtypes/lib/index.js b/typed-real-float-dtypes/lib/index.js deleted file mode 100644 index 418515af..00000000 --- a/typed-real-float-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array real-valued floating-point data types. -* -* @module @stdlib/array/typed-real-float-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-real-float-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-real-float-dtypes/lib/main.js b/typed-real-float-dtypes/lib/main.js deleted file mode 100644 index ca936308..00000000 --- a/typed-real-float-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array real-valued floating-point data types. -* -* @returns {StringArray} list of typed array real-valued floating-point data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'float32', ... ] -*/ -function dtypes() { - return dt( 'real_floating_point' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-real-float-dtypes/package.json b/typed-real-float-dtypes/package.json deleted file mode 100644 index b3040616..00000000 --- a/typed-real-float-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-real-float-dtypes", - "version": "0.0.0", - "description": "List of typed array real-valued floating-point data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-real-float-dtypes/test/test.js b/typed-real-float-dtypes/test/test.js deleted file mode 100644 index 22b7ab7b..00000000 --- a/typed-real-float-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array real-valued floating-point data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'real_floating_point' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-real/README.md b/typed-real/README.md deleted file mode 100644 index c3f03ac4..00000000 --- a/typed-real/README.md +++ /dev/null @@ -1,236 +0,0 @@ - - -# Typed Arrays - -> Create a typed array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var realarray = require( '@stdlib/array/typed-real' ); -``` - -#### realarray( \[dtype] ) - -Creates a [typed array][mdn-typed-array] having a specified data type `dtype`. - -```javascript -var arr = realarray(); -// returns -``` - -The function recognizes the following data types: - -- `float64`: double-precision floating-point numbers (IEEE 754) -- `float32`: single-precision floating-point numbers (IEEE 754) -- `int32`: 32-bit two's complement signed integers -- `uint32`: 32-bit unsigned integers -- `int16`: 16-bit two's complement signed integers -- `uint16`: 16-bit unsigned integers -- `int8`: 8-bit two's complement signed integers -- `uint8`: 8-bit unsigned integers -- `uint8c`: 8-bit unsigned integers clamped to `0-255` - -By default, the output [typed array][mdn-typed-array] data type is `float64`. To specify an alternative data type, provide a `dtype` argument. - -```javascript -var arr = realarray( 'int32' ); -// returns -``` - -#### realarray( length\[, dtype] ) - -Returns a [typed array][mdn-typed-array] having a specified `length`. - -```javascript -var arr1 = realarray( 5 ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -var arr2 = realarray( 5, 'uint8' ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### realarray( realarray\[, dtype] ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - -```javascript -var arr1 = realarray( [ 5.0, -3.0, 2.0 ] ); -// returns [ 5.0, -3.0, 2.0 ] - -var arr2 = realarray( arr1 ); -// returns [ 5.0, -3.0, 2.0 ] - -var arr3 = realarray( arr1, 'int32' ); -// returns [ 5, -3, 2 ] -``` - -#### realarray( obj\[, dtype] ) - -Creates a [typed array][mdn-typed-array] from an array-like object or iterable. - -```javascript -var arr1 = realarray( [ 0.5, 0.5, 0.5 ] ); -// returns [ 0.5, 0.5, 0.5 ] - -var arr2 = realarray( [ 0.5, 0.5, 0.5 ], 'float32' ); -// returns [ 0.5, 0.5, 0.5 ] -``` - -#### realarray( buffer\[, byteOffset\[, length]]\[, dtype] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][mdn-arraybuffer]. - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); -var buf = new ArrayBuffer( 32 ); - -var arr1 = realarray( buf ); -// returns [ 0.0, 0.0, 0.0, 0.0 ] - -var arr2 = realarray( buf, 'float32' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] - -var arr3 = realarray( buf, 16 ); -// returns [ 0.0, 0.0 ] - -var arr4 = realarray( buf, 16, 'float32' ); -// returns [ 0.0, 0.0, 0.0, 0.0 ] - -var arr5 = realarray( buf, 16, 1 ); -// returns [ 0.0 ] - -var arr6 = realarray( buf, 10, 4, 'int16' ); -// returns [ 0, 0, 0, 0 ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var realarray = require( '@stdlib/array/typed-real' ); - -var arr = realarray( 100, 'float64' ); - -var i; -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = randu() * 100.0; -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-real/benchmark/benchmark.js b/typed-real/benchmark/benchmark.js deleted file mode 100644 index c1fc183c..00000000 --- a/typed-real/benchmark/benchmark.js +++ /dev/null @@ -1,209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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 = realarray( 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(); -}); diff --git a/typed-real/benchmark/benchmark.length.float32.js b/typed-real/benchmark/benchmark.length.float32.js deleted file mode 100644 index 7b314ea4..00000000 --- a/typed-real/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.float64.js b/typed-real/benchmark/benchmark.length.float64.js deleted file mode 100644 index b92107d2..00000000 --- a/typed-real/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.int16.js b/typed-real/benchmark/benchmark.length.int16.js deleted file mode 100644 index a26a4169..00000000 --- a/typed-real/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.int32.js b/typed-real/benchmark/benchmark.length.int32.js deleted file mode 100644 index c2107bc5..00000000 --- a/typed-real/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.int8.js b/typed-real/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5478bc9b..00000000 --- a/typed-real/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.uint16.js b/typed-real/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 6ff01fc7..00000000 --- a/typed-real/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.uint32.js b/typed-real/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 312a36af..00000000 --- a/typed-real/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.uint8.js b/typed-real/benchmark/benchmark.length.uint8.js deleted file mode 100644 index bfb8fa12..00000000 --- a/typed-real/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/typed-real/benchmark/benchmark.length.uint8c.js b/typed-real/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 605f557d..00000000 --- a/typed-real/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var realarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = realarray( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/typed-real/docs/repl.txt b/typed-real/docs/repl.txt deleted file mode 100644 index 0a9881ff..00000000 --- a/typed-real/docs/repl.txt +++ /dev/null @@ -1,139 +0,0 @@ - -{{alias}}( [dtype] ) - Creates a typed array. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr = {{alias}}() - - > arr = {{alias}}( 'float32' ) - - - -{{alias}}( length[, dtype] ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr = {{alias}}( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray[, dtype] ) - Creates a 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 - A typed array. - - 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 typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( buffer[, byteOffset[, length]][, dtype] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 16 ); - > var arr = {{alias}}( buf, 0, 4, 'float32' ) - [ 0.0, 0.0, 0.0, 0.0 ] - - See Also - -------- - diff --git a/typed-real/docs/types/index.d.ts b/typed-real/docs/types/index.d.ts deleted file mode 100644 index 9f18f6c2..00000000 --- a/typed-real/docs/types/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/// - -import { ArrayLike, TypedArray, RealDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( './../../../buffer' ); - -/** -* Creates a typed array. -* -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = realarray(); -* // returns -* -* @example -* var arr = realarray( 'float32'); -* // returns -*/ -declare function realarray( dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param length - typed array length -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = realarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = realarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function realarray( length: number, dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param realarray - typed array from which to generate another typed array -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = realarray( new Float64Array( 2 ) ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = realarray( new Float64Array( 2 ), 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -*/ -declare function realarray( realarray: TypedArray, dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param obj - array-like object or iterable from which to generate a typed array -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = realarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var arr = realarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -*/ -declare function realarray( obj: ArrayLike | Iterable, dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -*/ -declare function realarray( buffer: ArrayBuffer, dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first typed array element (default: 0) -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function realarray( buffer: ArrayBuffer, byteOffset?: number, dtype?: DataType ): TypedArray; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first typed array element (default: 0) -* @param length - view length; if not provided, the view spans from the byteOffset to the end of the underlying ArrayBuffer -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ -declare function realarray( buffer: ArrayBuffer, byteOffset?: number, length?: number, dtype?: DataType ): TypedArray; - - -// EXPORTS // - -export = realarray; diff --git a/typed-real/docs/types/test.ts b/typed-real/docs/types/test.ts deleted file mode 100644 index 6403af5a..00000000 --- a/typed-real/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import realarray = require( './index' ); - - -// TESTS // - -// The function returns a typed array.. -{ - realarray(); // $ExpectType TypedArray - realarray( 'float32' ); // $ExpectType TypedArray - realarray( 10, 'float32' ); // $ExpectType TypedArray - realarray( [ 1, 2, 3 ], 'int32' ); // $ExpectType TypedArray -} - -// The compiler throws an error if the function is provided a first argument which is not a data type, number, array-like object, or typed array... -{ - realarray( true ); // $ExpectError - realarray( false ); // $ExpectError - realarray( {} ); // $ExpectError - realarray( null ); // $ExpectError - realarray( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const buf = new ArrayBuffer( 32 ); - realarray( buf, 8, 2, 'int32', {} ); // $ExpectError -} diff --git a/typed-real/examples/index.js b/typed-real/examples/index.js deleted file mode 100644 index 9d890757..00000000 --- a/typed-real/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 realarray = require( './../lib' ); - -var arr = realarray( 100, 'float64' ); - -var i; -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = randu() * 100.0; -} -console.log( arr ); diff --git a/typed-real/lib/index.js b/typed-real/lib/index.js deleted file mode 100644 index 082fea66..00000000 --- a/typed-real/lib/index.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a typed array. -* -* @module @stdlib/array/typed-real -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr = realarray(); -* // returns -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr = realarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr = realarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr = realarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr = realarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var realarray = require( '@stdlib/array/typed-real' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-real/lib/main.js b/typed-real/lib/main.js deleted file mode 100644 index 986da2b1..00000000 --- a/typed-real/lib/main.js +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 ctors = require( './../../typed-ctors' ); -var defaults = require( './../../defaults' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = defaults.get( 'dtypes.real' ); - - -// MAIN // - -/** -* Creates a typed array. -* -* @param {(NonNegativeInteger|TypedArray|ArrayLikeObject|ArrayBuffer)} [arg] - a length, typed array, array-like object, or buffer -* @param {NonNegativeInteger} [byteOffset=0] - byte offset -* @param {NonNegativeInteger} [length] - view length -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a recognized data type -* @returns {TypedArray} typed array -* -* @example -* var arr = realarray(); -* // returns -* -* @example -* var arr = realarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = realarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = realarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var arr = realarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -* -* @example -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var arr1 = realarray( [ 5, 3 ], 'int32' ); -* var arr2 = realarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = realarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = realarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ -function realarray() { - var nargs; - var dtype; - var ctor; - - 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 ); - } - if ( nargs === 1 ) { - return new ctor( arguments[0] ); - } - if ( nargs === 2 ) { - return new ctor( arguments[0], arguments[1] ); - } - return new ctor( arguments[0], arguments[1], arguments[2] ); -} - - -// EXPORTS // - -module.exports = realarray; diff --git a/typed-real/package.json b/typed-real/package.json deleted file mode 100644 index 6e6ff5e6..00000000 --- a/typed-real/package.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "name": "@stdlib/array/typed-real", - "version": "0.0.0", - "description": "Create a typed array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long" - ] -} diff --git a/typed-real/test/test.js b/typed-real/test/test.js deleted file mode 100644 index 04a526e7..00000000 --- a/typed-real/test/test.js +++ /dev/null @@ -1,1005 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var ArrayBuffer = require( './../../buffer' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var realarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof realarray, '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', - 'realarray', - '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() { - realarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'realarray', - '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() { - realarray( 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', - 'realarray', - '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() { - realarray( 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', - 'realarray', - '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() { - realarray( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'realarray', - '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() { - realarray( new ArrayBuffer( 16 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'realarray', - '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() { - realarray( new ArrayBuffer( 16 ), 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset, length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'realarray', - '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() { - realarray( new ArrayBuffer( 16 ), 0, 1, value ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = realarray(); - 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 = realarray( 'float64' ); - 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=float32)', function test( t ) { - var arr = realarray( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = realarray( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = realarray( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = realarray( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = realarray( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = realarray( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = realarray( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = realarray( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = realarray( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = realarray( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = realarray( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = realarray( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = realarray( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = realarray( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = realarray( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = realarray( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = realarray( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = realarray( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - var out = realarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = realarray( buf, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = realarray( buf, 8 ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = realarray( buf, 8, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 6, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 6, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = realarray( buf, 8, 2 ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = realarray( buf, 8, 2, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = realarray( buf, 4, 2, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); diff --git a/typed-signed-integer-ctors/README.md b/typed-signed-integer-ctors/README.md deleted file mode 100644 index c2b32e06..00000000 --- a/typed-signed-integer-ctors/README.md +++ /dev/null @@ -1,125 +0,0 @@ - - -# Constructors - -> Signed integer typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-signed-integer-ctors' ); -``` - -#### ctors( dtype ) - -Returns a signed integer typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'int32' ); -// returns -``` - -The function returns constructors for the following data types: - -- `int16`: signed 16-bit integers. -- `int32`: signed 32-bit integers. -- `int8`: signed 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'int' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-signed-integer-dtypes' ); -var ctors = require( '@stdlib/array/typed-signed-integer-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-signed-integer-ctors/benchmark/benchmark.js b/typed-signed-integer-ctors/benchmark/benchmark.js deleted file mode 100644 index 2ecfb878..00000000 --- a/typed-signed-integer-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-signed-integer-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-signed-integer-ctors/docs/repl.txt b/typed-signed-integer-ctors/docs/repl.txt deleted file mode 100644 index 86311b86..00000000 --- a/typed-signed-integer-ctors/docs/repl.txt +++ /dev/null @@ -1,30 +0,0 @@ - -{{alias}}( dtype ) - Returns a signed integer typed array constructor. - - The function returns constructors for the following data types: - - - int16: signed 16-bit integers. - - int32: signed 32-bit integers. - - int8: signed 8-bit integers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'int32' ) - - > ctor = {{alias}}( 'int' ) - null - - See Also - -------- - diff --git a/typed-signed-integer-ctors/docs/types/index.d.ts b/typed-signed-integer-ctors/docs/types/index.d.ts deleted file mode 100644 index 5a99f31f..00000000 --- a/typed-signed-integer-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Returns an `Int32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -*/ -declare function ctors( dtype: 'int32' ): typeof Int32Array; - -/** -* Returns an `Int16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int16' ); -* // returns -*/ -declare function ctors( dtype: 'int16' ): typeof Int16Array; - -/** -* Returns an `Int8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'int8' ); -* // returns -*/ -declare function ctors( dtype: 'int8' ): typeof Int8Array; - -/** -* Returns a signed integer typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -* -* @example -* var ctor = ctors( 'int' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-signed-integer-ctors/docs/types/test.ts b/typed-signed-integer-ctors/docs/types/test.ts deleted file mode 100644 index 1df80322..00000000 --- a/typed-signed-integer-ctors/docs/types/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'int32' ); // $ExpectType Int32ArrayConstructor - ctors( 'int16' ); // $ExpectType Int16ArrayConstructor - ctors( 'int8' ); // $ExpectType Int8ArrayConstructor - ctors( 'int' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'int32', 3 ); // $ExpectError -} diff --git a/typed-signed-integer-ctors/examples/index.js b/typed-signed-integer-ctors/examples/index.js deleted file mode 100644 index e1a16e4f..00000000 --- a/typed-signed-integer-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-signed-integer-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-signed-integer-ctors/lib/ctors.js b/typed-signed-integer-ctors/lib/ctors.js deleted file mode 100644 index a75a3af1..00000000 --- a/typed-signed-integer-ctors/lib/ctors.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'int16': Int16Array, - 'int32': Int32Array, - 'int8': Int8Array -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-signed-integer-ctors/lib/index.js b/typed-signed-integer-ctors/lib/index.js deleted file mode 100644 index 597da25d..00000000 --- a/typed-signed-integer-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Signed integer typed array constructors. -* -* @module @stdlib/array/typed-signed-integer-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-signed-integer-ctors' ); -* -* var ctor = ctors( 'int32' ); -* // returns -* -* ctor = ctors( 'int' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-signed-integer-ctors/lib/main.js b/typed-signed-integer-ctors/lib/main.js deleted file mode 100644 index 1bd5add3..00000000 --- a/typed-signed-integer-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns a signed integer typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'int32' ); -* // returns -* -* @example -* var ctor = ctors( 'int' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-signed-integer-ctors/package.json b/typed-signed-integer-ctors/package.json deleted file mode 100644 index 1b8af95c..00000000 --- a/typed-signed-integer-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-signed-integer-ctors", - "version": "0.0.0", - "description": "Signed integer typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-signed-integer-ctors/test/test.js b/typed-signed-integer-ctors/test/test.js deleted file mode 100644 index 44e24f21..00000000 --- a/typed-signed-integer-ctors/test/test.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-signed-integer-dtypes' ); -var Int16Array = require( './../../int16' ); -var Int32Array = require( './../../int32' ); -var Int8Array = require( './../../int8' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'int16', - 'int32', - 'int8' - ]; - expected = [ - Int16Array, - Int32Array, - Int8Array - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-signed-integer-dtypes/README.md b/typed-signed-integer-dtypes/README.md deleted file mode 100644 index ac2bebca..00000000 --- a/typed-signed-integer-dtypes/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Data Types - -> List of typed array signed integer data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-signed-integer-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array signed integer data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'int16', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-signed-integer-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'int32' ); -// returns true - -bool = isdtype( 'int16' ); -// returns true - -bool = isdtype( 'uint8' ); -// returns false - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-signed-integer-dtypes/benchmark/benchmark.js b/typed-signed-integer-dtypes/benchmark/benchmark.js deleted file mode 100644 index 0df6510b..00000000 --- a/typed-signed-integer-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length <= 2 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-signed-integer-dtypes/docs/repl.txt b/typed-signed-integer-dtypes/docs/repl.txt deleted file mode 100644 index a46c67f8..00000000 --- a/typed-signed-integer-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array signed integer data types. - - Returns - ------- - out: Array - List of typed array signed integer data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-signed-integer-dtypes/docs/types/index.d.ts b/typed-signed-integer-dtypes/docs/types/index.d.ts deleted file mode 100644 index 8a6cbe9d..00000000 --- a/typed-signed-integer-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { SignedIntegerDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array signed integer data types. -* -* @returns list of typed array signed integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-signed-integer-dtypes/docs/types/test.ts b/typed-signed-integer-dtypes/docs/types/test.ts deleted file mode 100644 index 2f78d681..00000000 --- a/typed-signed-integer-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType SignedIntegerDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-signed-integer-dtypes/examples/index.js b/typed-signed-integer-dtypes/examples/index.js deleted file mode 100644 index 8c3e403c..00000000 --- a/typed-signed-integer-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'int32' ); -console.log( bool ); -// => true - -bool = isdtype( 'int8' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint8' ); -console.log( bool ); -// => false - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-signed-integer-dtypes/lib/index.js b/typed-signed-integer-dtypes/lib/index.js deleted file mode 100644 index 50c27c34..00000000 --- a/typed-signed-integer-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array signed integer data types. -* -* @module @stdlib/array/typed-signed-integer-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-signed-integer-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-signed-integer-dtypes/lib/main.js b/typed-signed-integer-dtypes/lib/main.js deleted file mode 100644 index 7911a21d..00000000 --- a/typed-signed-integer-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array signed integer data types. -* -* @returns {StringArray} list of typed array signed integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'int16', ... ] -*/ -function dtypes() { - return dt( 'signed_integer' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-signed-integer-dtypes/package.json b/typed-signed-integer-dtypes/package.json deleted file mode 100644 index 2085a540..00000000 --- a/typed-signed-integer-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-signed-integer-dtypes", - "version": "0.0.0", - "description": "List of typed array signed integer data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-signed-integer-dtypes/test/test.js b/typed-signed-integer-dtypes/test/test.js deleted file mode 100644 index ed02ae8f..00000000 --- a/typed-signed-integer-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'signed_integer' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed-unsigned-integer-ctors/README.md b/typed-unsigned-integer-ctors/README.md deleted file mode 100644 index 57344826..00000000 --- a/typed-unsigned-integer-ctors/README.md +++ /dev/null @@ -1,126 +0,0 @@ - - -# Constructors - -> Unsigned integer typed array constructors. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var ctors = require( '@stdlib/array/typed-unsigned-integer-ctors' ); -``` - -#### ctors( dtype ) - -Returns an unsigned integer typed array constructor for a specified data type. - -```javascript -var ctor = ctors( 'uint32' ); -// returns -``` - -The function returns constructors for the following data types: - -- `uint16`: unsigned 16-bit integers. -- `uint32`: unsigned 32-bit integers. -- `uint8`: unsigned 8-bit integers. -- `uint8c`: unsigned clamped 8-bit integers. - -If provided an unknown or unsupported data type, the function returns `null`. - -```javascript -var ctor = ctors( 'uint' ); -// returns null -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/typed-unsigned-integer-dtypes' ); -var ctors = require( '@stdlib/array/typed-unsigned-integer-ctors' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-unsigned-integer-ctors/benchmark/benchmark.js b/typed-unsigned-integer-ctors/benchmark/benchmark.js deleted file mode 100644 index 79fb0dd9..00000000 --- a/typed-unsigned-integer-ctors/benchmark/benchmark.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var dtypes = require( './../../typed-unsigned-integer-dtypes' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var pkg = require( './../package.json' ).name; -var ctors = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var ctor; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - ctor = ctors( DTYPES[ i%DTYPES.length ] ); - if ( typeof ctor !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( ctor ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-unsigned-integer-ctors/docs/repl.txt b/typed-unsigned-integer-ctors/docs/repl.txt deleted file mode 100644 index 65992800..00000000 --- a/typed-unsigned-integer-ctors/docs/repl.txt +++ /dev/null @@ -1,31 +0,0 @@ - -{{alias}}( dtype ) - Returns an unsigned integer typed array constructor. - - The function returns constructors for the following data types: - - - uint16: unsigned 16-bit integers. - - uint32: unsigned 32-bit integers. - - uint8: unsigned 8-bit integers. - - uint8c: unsigned clamped 8-bit integers. - - Parameters - ---------- - dtype: string - Data type. - - Returns - ------- - out: Function|null - Typed array constructor. - - Examples - -------- - > var ctor = {{alias}}( 'uint32' ) - - > ctor = {{alias}}( 'uint' ) - null - - See Also - -------- - diff --git a/typed-unsigned-integer-ctors/docs/types/index.d.ts b/typed-unsigned-integer-ctors/docs/types/index.d.ts deleted file mode 100644 index 8eb165a5..00000000 --- a/typed-unsigned-integer-ctors/docs/types/index.d.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Returns a `Uint32Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -*/ -declare function ctors( dtype: 'uint32' ): typeof Uint32Array; - -/** -* Returns a `Uint16Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint16' ); -* // returns -*/ -declare function ctors( dtype: 'uint16' ): typeof Uint16Array; - -/** -* Returns a `Uint8Array` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8' ); -* // returns -*/ -declare function ctors( dtype: 'uint8' ): typeof Uint8Array; - -/** -* Returns a `Uint8ClampedArray` constructor. -* -* @param dtype - data type -* @returns constructor -* -* @example -* var ctor = ctors( 'uint8c' ); -* // returns -*/ -declare function ctors( dtype: 'uint8c' ): typeof Uint8ClampedArray; - -/** -* Returns an unsigned integer typed array constructor. -* -* @param dtype - data type -* @returns constructor or null -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -* -* @example -* var ctor = ctors( 'uint' ); -* // returns null -*/ -declare function ctors( dtype: string ): Function | null; - - -// EXPORTS // - -export = ctors; diff --git a/typed-unsigned-integer-ctors/docs/types/test.ts b/typed-unsigned-integer-ctors/docs/types/test.ts deleted file mode 100644 index a178b1b3..00000000 --- a/typed-unsigned-integer-ctors/docs/types/test.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ctors = require( './index' ); - - -// TESTS // - -// The function returns a function or null.. -{ - ctors( 'uint32' ); // $ExpectType Uint32ArrayConstructor - ctors( 'uint16' ); // $ExpectType Uint16ArrayConstructor - ctors( 'uint8' ); // $ExpectType Uint8ArrayConstructor - ctors( 'uint8c' ); // $ExpectType Uint8ClampedArrayConstructor - ctors( 'uint' ); // $ExpectType Function | null -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - ctors(); // $ExpectError - ctors( 'uint32', 3 ); // $ExpectError -} diff --git a/typed-unsigned-integer-ctors/examples/index.js b/typed-unsigned-integer-ctors/examples/index.js deleted file mode 100644 index 89a06deb..00000000 --- a/typed-unsigned-integer-ctors/examples/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../typed-unsigned-integer-dtypes' ); -var ctors = require( './../lib' ); - -var DTYPES = dtypes(); -var ctor; -var i; - -for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - console.log( ctor ); -} diff --git a/typed-unsigned-integer-ctors/lib/ctors.js b/typed-unsigned-integer-ctors/lib/ctors.js deleted file mode 100644 index 6a9216fe..00000000 --- a/typed-unsigned-integer-ctors/lib/ctors.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); - - -// MAIN // - -// Mapping from data types to constructors... -var ctors = { - 'uint16': Uint16Array, - 'uint32': Uint32Array, - 'uint8': Uint8Array, - 'uint8c': Uint8ClampedArray -}; - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-unsigned-integer-ctors/lib/index.js b/typed-unsigned-integer-ctors/lib/index.js deleted file mode 100644 index fd10ef05..00000000 --- a/typed-unsigned-integer-ctors/lib/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Unsigned integer typed array constructors. -* -* @module @stdlib/array/typed-unsigned-integer-ctors -* -* @example -* var ctors = require( '@stdlib/array/typed-unsigned-integer-ctors' ); -* -* var ctor = ctors( 'uint32' ); -* // returns -* -* ctor = ctors( 'uint' ); -* // returns null -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-unsigned-integer-ctors/lib/main.js b/typed-unsigned-integer-ctors/lib/main.js deleted file mode 100644 index d5078f02..00000000 --- a/typed-unsigned-integer-ctors/lib/main.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var table = require( './ctors.js' ); - - -// MAIN // - -/** -* Returns an unsigned integer typed array constructor. -* -* @param {string} dtype - data type -* @returns {(Function|null)} constructor or null -* -* @example -* var ctor = ctors( 'uint32' ); -* // returns -* -* @example -* var ctor = ctors( 'uint' ); -* // returns null -*/ -function ctors( dtype ) { - return table[ dtype ] || null; -} - - -// EXPORTS // - -module.exports = ctors; diff --git a/typed-unsigned-integer-ctors/package.json b/typed-unsigned-integer-ctors/package.json deleted file mode 100644 index 58d8bef6..00000000 --- a/typed-unsigned-integer-ctors/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@stdlib/array/typed-unsigned-integer-ctors", - "version": "0.0.0", - "description": "Unsigned integer typed array constructors.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "array", - "typed array", - "typed-array", - "typed", - "dtypes", - "dtype", - "data", - "type", - "structure", - "constructors", - "constructor", - "ctors", - "ctor", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-unsigned-integer-ctors/test/test.js b/typed-unsigned-integer-ctors/test/test.js deleted file mode 100644 index a965e058..00000000 --- a/typed-unsigned-integer-ctors/test/test.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dtypes = require( './../../typed-unsigned-integer-dtypes' ); -var Uint16Array = require( './../../uint16' ); -var Uint32Array = require( './../../uint32' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var ctors = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctors, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns typed array constructors', function test( t ) { - var expected; - var dtypes; - var ctor; - var i; - - dtypes = [ - 'uint16', - 'uint32', - 'uint8', - 'uint8c' - ]; - expected = [ - Uint16Array, - Uint32Array, - Uint8Array, - Uint8ClampedArray - ]; - for ( i = 0; i < dtypes.length; i++ ) { - ctor = ctors( dtypes[ i ] ); - t.strictEqual( ctor, expected[ i ], 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); - -tape( 'the function returns a constructor for each supported typed array data type', function test( t ) { - var DTYPES; - var ctor; - var i; - - DTYPES = dtypes(); - for ( i = 0; i < DTYPES.length; i++ ) { - ctor = ctors( DTYPES[ i ] ); - - // Note: this is a weak test for a "constructor" - t.strictEqual( isFunction( ctor ), true, 'returns a function for ' + DTYPES[ i ] ); - } - t.end(); -}); - -tape( 'if provided an unknown/unsupported data type, the function returns `null`', function test( t ) { - var dtypes; - var i; - - dtypes = [ - 'binary', - 'buffer', - 'buf', - 'generic', - 'float', - 'double', - 'single', - 'int', - 'integer', - 'uint', - 'uinteger', - 'byte', - 'bits' - ]; - for ( i = 0; i < dtypes.length; i++ ) { - t.strictEqual( ctors( dtypes[i] ), null, 'returns expected value for ' + dtypes[ i ] ); - } - t.end(); -}); diff --git a/typed-unsigned-integer-dtypes/README.md b/typed-unsigned-integer-dtypes/README.md deleted file mode 100644 index 7240e057..00000000 --- a/typed-unsigned-integer-dtypes/README.md +++ /dev/null @@ -1,124 +0,0 @@ - - -# Data Types - -> List of typed array unsigned integer data types. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var dtypes = require( '@stdlib/array/typed-unsigned-integer-dtypes' ); -``` - -#### dtypes() - -Returns a list of typed array unsigned integer data types. - -```javascript -var out = dtypes(); -// e.g., returns [ 'uint16', ... ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( '@stdlib/array/typed-unsigned-integer-dtypes' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'uint32' ); -// returns true - -bool = isdtype( 'uint16' ); -// returns true - -bool = isdtype( 'int16' ); -// returns false - -bool = isdtype( 'beep' ); -// returns false -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed-unsigned-integer-dtypes/benchmark/benchmark.js b/typed-unsigned-integer-dtypes/benchmark/benchmark.js deleted file mode 100644 index 0df6510b..00000000 --- a/typed-unsigned-integer-dtypes/benchmark/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; -var pkg = require( './../package.json' ).name; -var dtypes = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dtypes(); - if ( out.length <= 2 ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isStringArray( out ) ) { - b.fail( 'should return an array of strings' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/typed-unsigned-integer-dtypes/docs/repl.txt b/typed-unsigned-integer-dtypes/docs/repl.txt deleted file mode 100644 index 1b4f5799..00000000 --- a/typed-unsigned-integer-dtypes/docs/repl.txt +++ /dev/null @@ -1,17 +0,0 @@ - -{{alias}}() - Returns a list of typed array unsigned integer data types. - - Returns - ------- - out: Array - List of typed array unsigned integer data types. - - Examples - -------- - > var out = {{alias}}() - - - See Also - -------- - diff --git a/typed-unsigned-integer-dtypes/docs/types/index.d.ts b/typed-unsigned-integer-dtypes/docs/types/index.d.ts deleted file mode 100644 index 440975a3..00000000 --- a/typed-unsigned-integer-dtypes/docs/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { UnsignedIntegerDataType as DataType } from '@stdlib/types/array'; - -/** -* Returns a list of typed array unsigned integer data types. -* -* @returns list of typed array unsigned integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'uint16', ... ] -*/ -declare function dtypes(): Array; - - -// EXPORTS // - -export = dtypes; diff --git a/typed-unsigned-integer-dtypes/docs/types/test.ts b/typed-unsigned-integer-dtypes/docs/types/test.ts deleted file mode 100644 index dac8fe20..00000000 --- a/typed-unsigned-integer-dtypes/docs/types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import dtypes = require( './index' ); - - -// TESTS // - -// The function returns a string array.. -{ - dtypes(); // $ExpectType UnsignedIntegerDataType[] -} - -// The compiler throws an error if the function is provided arguments... -{ - dtypes( 1 ); // $ExpectError - dtypes( 1, 2 ); // $ExpectError -} diff --git a/typed-unsigned-integer-dtypes/examples/index.js b/typed-unsigned-integer-dtypes/examples/index.js deleted file mode 100644 index 58305dc3..00000000 --- a/typed-unsigned-integer-dtypes/examples/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 indexOf = require( '@stdlib/utils/index-of' ); -var dtypes = require( './../lib' ); - -var DTYPES = dtypes(); - -function isdtype( str ) { - if ( indexOf( DTYPES, str ) === -1 ) { - return false; - } - return true; -} - -var bool = isdtype( 'uint32' ); -console.log( bool ); -// => true - -bool = isdtype( 'uint8' ); -console.log( bool ); -// => true - -bool = isdtype( 'int16' ); -console.log( bool ); -// => false - -bool = isdtype( 'beep' ); -console.log( bool ); -// => false diff --git a/typed-unsigned-integer-dtypes/lib/index.js b/typed-unsigned-integer-dtypes/lib/index.js deleted file mode 100644 index 04039217..00000000 --- a/typed-unsigned-integer-dtypes/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a list of typed array unsigned integer data types. -* -* @module @stdlib/array/typed-unsigned-integer-dtypes -* -* @example -* var dtypes = require( '@stdlib/array/typed-unsigned-integer-dtypes' ); -* -* var list = dtypes(); -* // e.g., returns [ 'uint16', ... ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed-unsigned-integer-dtypes/lib/main.js b/typed-unsigned-integer-dtypes/lib/main.js deleted file mode 100644 index 36106d1b..00000000 --- a/typed-unsigned-integer-dtypes/lib/main.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var dt = require( './../../dtypes' ); - - -// MAIN // - -/** -* Returns a list of typed array unsigned integer data types. -* -* @returns {StringArray} list of typed array unsigned integer data types -* -* @example -* var list = dtypes(); -* // e.g., returns [ 'uint16', ... ] -*/ -function dtypes() { - return dt( 'unsigned_integer' ); -} - - -// EXPORTS // - -module.exports = dtypes; diff --git a/typed-unsigned-integer-dtypes/package.json b/typed-unsigned-integer-dtypes/package.json deleted file mode 100644 index 1e140365..00000000 --- a/typed-unsigned-integer-dtypes/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@stdlib/array/typed-unsigned-integer-dtypes", - "version": "0.0.0", - "description": "List of typed array unsigned integer data types.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "typed", - "array", - "dtypes", - "dtype", - "data", - "type", - "utilities", - "utility", - "utils", - "util" - ], - "__stdlib__": {} -} diff --git a/typed-unsigned-integer-dtypes/test/test.js b/typed-unsigned-integer-dtypes/test/test.js deleted file mode 100644 index d8401083..00000000 --- a/typed-unsigned-integer-dtypes/test/test.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var dt = require( './../../dtypes' ); -var dtypes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dtypes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a list of typed array data types', function test( t ) { - var expected; - var actual; - - expected = dt( 'unsigned_integer' ); - actual = dtypes(); - - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/typed/README.md b/typed/README.md deleted file mode 100644 index de936354..00000000 --- a/typed/README.md +++ /dev/null @@ -1,238 +0,0 @@ - - -# typedarray - -> Create a typed array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var typedarray = require( '@stdlib/array/typed' ); -``` - -#### typedarray( \[dtype] ) - -Creates a [typed array][mdn-typed-array] having a specified [data type][@stdlib/array/typed-dtypes]. - -```javascript -var arr = typedarray(); -// returns -``` - -By default, the output [typed array][mdn-typed-array] data type is `float64`. To specify an alternative data type, provide a [`dtype`][@stdlib/array/typed-dtypes] argument. - -```javascript -var arr = typedarray( 'int32' ); -// returns -``` - -#### typedarray( length\[, dtype] ) - -Returns a [typed array][mdn-typed-array] having a specified `length`. - -```javascript -var arr1 = typedarray( 5 ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -var arr2 = typedarray( 5, 'uint8' ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### typedarray( typedarray\[, dtype] ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - -```javascript -var arr1 = typedarray( [ 5.0, -3.0, 2.0 ] ); -// returns [ 5.0, -3.0, 2.0 ] - -var arr2 = typedarray( arr1 ); -// returns [ 5.0, -3.0, 2.0 ] - -var arr3 = typedarray( arr1, 'int32' ); -// returns [ 5, -3, 2 ] -``` - -#### typedarray( obj\[, dtype] ) - -Creates a [typed array][mdn-typed-array] from an array-like object or iterable. - -```javascript -var arr1 = typedarray( [ 0.5, 0.5, 0.5 ] ); -// returns [ 0.5, 0.5, 0.5 ] - -var arr2 = typedarray( [ 0.5, 0.5, 0.5 ], 'float32' ); -// returns [ 0.5, 0.5, 0.5 ] -``` - -If [`dtype`][@stdlib/array/typed-dtypes] is complex number data type and an array-like object contains interleaved real and imaginary components, the array-like object must have a length which is a multiple of two. - -#### typedarray( buffer\[, byteOffset\[, length]]\[, dtype] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][mdn-arraybuffer]. - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); -var buf = new ArrayBuffer( 32 ); - -var arr1 = typedarray( buf ); -// returns [ 0.0, 0.0, 0.0, 0.0 ] - -var arr2 = typedarray( buf, 'float32' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] - -var arr3 = typedarray( buf, 16 ); -// returns [ 0.0, 0.0 ] - -var arr4 = typedarray( buf, 16, 'float32' ); -// returns [ 0.0, 0.0, 0.0, 0.0 ] - -var arr5 = typedarray( buf, 16, 1 ); -// returns [ 0.0 ] - -var arr6 = typedarray( buf, 10, 4, 'int16' ); -// returns [ 0, 0, 0, 0 ] -``` - -
- - - - - -
- -## Notes - -- When providing a complex number array, if [`dtype`][@stdlib/array/typed-dtypes] is unspecified or the specified data type is not a complex number data type, the returned array contains interleaved real and imaginary components. - -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var typedarray = require( '@stdlib/array/typed' ); - -var arr = typedarray( 100, 'float64' ); - -var i; -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = randu() * 100.0; -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/typed/benchmark/benchmark.js b/typed/benchmark/benchmark.js deleted file mode 100644 index 265d7f3f..00000000 --- a/typed/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' ); -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=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(); -}); - -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=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=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(); -}); diff --git a/typed/benchmark/benchmark.length.bool.js b/typed/benchmark/benchmark.length.bool.js deleted file mode 100644 index 08097a6f..00000000 --- a/typed/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,93 +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' ); -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 {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - 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( len ); - bench( pkg+':dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.complex128.js b/typed/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 0d479fe6..00000000 --- a/typed/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - 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( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.complex64.js b/typed/benchmark/benchmark.length.complex64.js deleted file mode 100644 index f0535a8c..00000000 --- a/typed/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - 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( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.float32.js b/typed/benchmark/benchmark.length.float32.js deleted file mode 100644 index 316a3d1e..00000000 --- a/typed/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.float64.js b/typed/benchmark/benchmark.length.float64.js deleted file mode 100644 index 3693b12a..00000000 --- a/typed/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.int16.js b/typed/benchmark/benchmark.length.int16.js deleted file mode 100644 index 39946d32..00000000 --- a/typed/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.int32.js b/typed/benchmark/benchmark.length.int32.js deleted file mode 100644 index 32a75125..00000000 --- a/typed/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.int8.js b/typed/benchmark/benchmark.length.int8.js deleted file mode 100644 index fdd4fa3a..00000000 --- a/typed/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.uint16.js b/typed/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 1c92537b..00000000 --- a/typed/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.uint32.js b/typed/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 069fbf2a..00000000 --- a/typed/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.uint8.js b/typed/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 74f2179f..00000000 --- a/typed/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/typed/benchmark/benchmark.length.uint8c.js b/typed/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 3b11bd99..00000000 --- a/typed/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/typed/docs/repl.txt b/typed/docs/repl.txt deleted file mode 100644 index 11b947d0..00000000 --- a/typed/docs/repl.txt +++ /dev/null @@ -1,125 +0,0 @@ - -{{alias}}( [dtype] ) - Creates a typed array. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr = {{alias}}() - - > arr = {{alias}}( 'float32' ) - - - -{{alias}}( length[, dtype] ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr = {{alias}}( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray[, dtype] ) - Creates a 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 - A typed array. - - 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 typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( buffer[, byteOffset[, length]][, dtype] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 16 ); - > var arr = {{alias}}( buf, 0, 4, 'float32' ) - [ 0.0, 0.0, 0.0, 0.0 ] - - See Also - -------- - diff --git a/typed/docs/types/index.d.ts b/typed/docs/types/index.d.ts deleted file mode 100644 index d8d08fec..00000000 --- a/typed/docs/types/index.d.ts +++ /dev/null @@ -1,180 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/* eslint-disable @typescript-eslint/unified-signatures */ - -/// - -import { RealOrComplexTypedArray, TypedDataTypeMap } from '@stdlib/types/array'; -import ArrayBuffer = require( './../../../buffer' ); - -/** -* Creates a typed array. -* -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = typedarray(); -* // returns -* -* @example -* var arr = typedarray( 'float32'); -* // returns -*/ -declare function typedarray( dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param length - typed array length -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = typedarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = typedarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function typedarray( length: number, dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param typedarray - typed array from which to generate another typed array -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = typedarray( new Float64Array( 2 ) ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = typedarray( new Float64Array( 2 ), 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -*/ -declare function typedarray( typedarray: RealOrComplexTypedArray, dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param obj - array-like object or iterable from which to generate a typed array -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var arr = typedarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var arr = typedarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -*/ -declare function typedarray( obj: ArrayLike | Iterable, dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -*/ -declare function typedarray( buffer: ArrayBuffer, dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first typed array element (default: 0) -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function typedarray( buffer: ArrayBuffer, byteOffset?: number, dtype?: T ): TypedDataTypeMap[T]; - -/** -* Creates a typed array. -* -* @param buffer - underlying ArrayBuffer -* @param byteOffset - integer byte offset specifying the location of the first typed array element (default: 0) -* @param length - view length; if not provided, the view spans from the byteOffset to the end of the underlying ArrayBuffer -* @param dtype - data type (default: 'float64') -* @returns typed array -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ -declare function typedarray( buffer: ArrayBuffer, byteOffset?: number, length?: number, dtype?: T ): TypedDataTypeMap[T]; - - -// EXPORTS // - -export = typedarray; diff --git a/typed/docs/types/test.ts b/typed/docs/types/test.ts deleted file mode 100644 index 08c9fb16..00000000 --- a/typed/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import typedarray = require( './index' ); - - -// TESTS // - -// The function returns a typed array.. -{ - typedarray(); // $ExpectType Float64Array - typedarray( 'float32' ); // $ExpectType Float32Array - typedarray( 10, 'float32' ); // $ExpectType Float32Array - typedarray( [ 1, 2, 3 ], 'int32' ); // $ExpectType Int32Array -} - -// The compiler throws an error if the function is provided a first argument which is not a data type, number, array-like object, or typed array... -{ - typedarray( true ); // $ExpectError - typedarray( false ); // $ExpectError - typedarray( {} ); // $ExpectError - typedarray( null ); // $ExpectError - typedarray( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const buf = new ArrayBuffer( 32 ); - typedarray( buf, 8, 2, 'int32', {} ); // $ExpectError -} diff --git a/typed/examples/index.js b/typed/examples/index.js deleted file mode 100644 index 11add274..00000000 --- a/typed/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 typedarray = require( './../lib' ); - -var arr = typedarray( 100, 'float64' ); - -var i; -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = randu() * 100.0; -} -console.log( arr ); diff --git a/typed/lib/index.js b/typed/lib/index.js deleted file mode 100644 index 97c1de86..00000000 --- a/typed/lib/index.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a typed array. -* -* @module @stdlib/array/typed -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr = typedarray(); -* // returns -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr = typedarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr = typedarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr = typedarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr = typedarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var typedarray = require( '@stdlib/array/typed' ); -* -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* var typedarray = require( '@stdlib/array/typed' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/typed/lib/main.js b/typed/lib/main.js deleted file mode 100644 index 5cb8a082..00000000 --- a/typed/lib/main.js +++ /dev/null @@ -1,166 +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 ctors = require( './../../typed-ctors' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); -var defaults = require( './../../defaults' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// MAIN // - -/** -* Creates a typed array. -* -* @param {(NonNegativeInteger|ComplexArray|TypedArray|ArrayLikeObject|ArrayBuffer)} [arg] - a length, typed array, array-like object, or buffer -* @param {NonNegativeInteger} [byteOffset=0] - byte offset -* @param {NonNegativeInteger} [length] - view length -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a recognized data type -* @returns {(ComplexArray|TypedArray)} typed array -* -* @example -* var arr = typedarray(); -* // returns -* -* @example -* var arr = typedarray( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = typedarray( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = typedarray( [ 0.5, 0.5 ] ); -* // returns [ 0.5, 0.5 ] -* -* @example -* var arr = typedarray( [ 5, -3 ], 'int32' ); -* // returns [ 5, -3 ] -* -* @example -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1 ); -* // returns [ 5.0, 3.0 ] -* -* @example -* var arr1 = typedarray( [ 5, 3 ], 'int32' ); -* var arr2 = typedarray( arr1, 'uint32' ); -* // returns [ 5, 3 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 'float32' ); -* // returns [ 0.0, 0.0, 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8 ); -* // returns [ 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 16 ); -* var arr = typedarray( buf, 8, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array/buffer' ); -* -* var buf = new ArrayBuffer( 32 ); -* var arr = typedarray( buf, 8, 2, 'int32' ); -* // returns [ 0, 0 ] -*/ -function typedarray() { - var nargs; - var dtype; - var ctor; - var arg; - - 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 ); - } - if ( nargs === 1 ) { - arg = arguments[ 0 ]; - - // Note: the following checks are not particularly robust, as `instanceof` will fail for cross-realm instances... - if ( arg instanceof Complex64Array ) { - arg = reinterpret64( arg, 0 ); - } else if ( arg instanceof Complex128Array ) { - arg = reinterpret128( arg, 0 ); - } else if ( arg instanceof BooleanArray ) { - arg = reinterpretBoolean( arg, 0 ); - } - return new ctor( arg ); - } - if ( nargs === 2 ) { - return new ctor( arguments[0], arguments[1] ); - } - return new ctor( arguments[0], arguments[1], arguments[2] ); -} - - -// EXPORTS // - -module.exports = typedarray; diff --git a/typed/package.json b/typed/package.json deleted file mode 100644 index b80e9e43..00000000 --- a/typed/package.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "name": "@stdlib/array/typed", - "version": "0.0.0", - "description": "Create a typed array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "complex64array", - "complex128array", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long", - "complex", - "cmplx" - ] -} diff --git a/typed/test/test.js b/typed/test/test.js deleted file mode 100644 index b85837ff..00000000 --- a/typed/test/test.js +++ /dev/null @@ -1,1555 +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 tape = require( 'tape' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex128Array = require( './../../complex128' ); -var Complex64Array = require( './../../complex64' ); -var BooleanArray = require( './../../bool' ); -var ArrayBuffer = require( './../../buffer' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); -var typedarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarray, '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() { - typedarray( 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() { - typedarray( 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() { - typedarray( 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() { - typedarray( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer)', 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() { - typedarray( new ArrayBuffer( 16 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset)', 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() { - typedarray( new ArrayBuffer( 16 ), 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset, 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() { - typedarray( new ArrayBuffer( 16 ), 0, 1, value ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarray(); - 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 = typedarray( 'float64' ); - 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=float32)', function test( t ) { - var arr = typedarray( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarray( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarray( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarray( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarray( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarray( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarray( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarray( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarray( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarray( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarray( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarray( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarray( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarray( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarray( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarray( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarray( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarray( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarray( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarray( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarray( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarray( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarray( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarray( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var view; - var arr; - var out; - - arr = [ 1, 0, 0, 1 ]; - out = typedarray( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpretBoolean( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr = [ 1.0, 2.0, 3.0 ]; - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Uint8Array( [ 1, 0, 1, 0 ] ); - out = typedarray( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpretBoolean( out, 0 ); - t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); - t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - var out = typedarray( 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' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret64( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, complex typed array)', function test( t ) { - var viewX; - var viewY; - var arr; - var out; - - arr = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - viewX = reinterpret64( arr, 0 ); - viewY = reinterpret128( out, 0 ); - t.strictEqual( viewY[ 0 ], viewX[ 0 ], 'returns expected value' ); - t.strictEqual( viewY[ 1 ], viewX[ 1 ], 'returns expected value' ); - t.strictEqual( viewY[ 2 ], viewX[ 2 ], 'returns expected value' ); - t.strictEqual( viewY[ 3 ], viewX[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, complex typed array)', function test( t ) { - var viewX; - var viewY; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - viewX = reinterpret128( arr, 0 ); - viewY = reinterpret64( out, 0 ); - t.strictEqual( viewY[ 0 ], viewX[ 0 ], 'returns expected value' ); - t.strictEqual( viewY[ 1 ], viewX[ 1 ], 'returns expected value' ); - t.strictEqual( viewY[ 2 ], viewX[ 2 ], 'returns expected value' ); - t.strictEqual( viewY[ 3 ], viewX[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, complex typed array)', function test( t ) { - var view; - var arr; - var out; - - arr = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarray( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - view = reinterpret128( arr, 0 ); - t.strictEqual( out[ 0 ], view[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], view[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], view[ 2 ], 'returns expected value' ); - t.strictEqual( out[ 3 ], view[ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, arraybuffer)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 16 ); - out = typedarray( buf, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, arraybuffer)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 8 ); - out = typedarray( buf, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, arraybuffer)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 2 ); - out = typedarray( buf, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpretBoolean( out, 0 ); - t.strictEqual( view[ 0 ], 0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer)', function test( t ) { - var buf = new ArrayBuffer( 8 ); - var out = typedarray( buf, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 8, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = typedarray( buf, 8 ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = typedarray( buf, 8, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, arraybuffer, byteoffset)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 32 ); - out = typedarray( buf, 16, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, arraybuffer, byteoffset)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 16 ); - out = typedarray( buf, 8, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, arraybuffer, byteoffset)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 2 ); - out = typedarray( buf, 1, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 1, 'returns expected value' ); - - view = reinterpretBoolean( out, 0 ); - t.strictEqual( view[ 0 ], 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 6, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 6, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer, byteoffset)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 12, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.strictEqual( out[ 2 ], 0, 'returns expected value' ); - t.strictEqual( out[ 3 ], 0, 'returns expected value' ); - t.strictEqual( out[ 4 ], 0, 'returns expected value' ); - t.strictEqual( out[ 5 ], 0, 'returns expected value' ); - t.strictEqual( out[ 6 ], 0, 'returns expected value' ); - t.strictEqual( out[ 7 ], 0, 'returns expected value' ); - t.strictEqual( out[ 8 ], 0, 'returns expected value' ); - t.strictEqual( out[ 9 ], 0, 'returns expected value' ); - t.strictEqual( out[ 10 ], 0, 'returns expected value' ); - t.strictEqual( out[ 11 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (default, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = typedarray( buf, 8, 2 ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 32 ); - var out = typedarray( buf, 8, 2, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, arraybuffer, byteoffset, length)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 64 ); - out = typedarray( buf, 16, 2, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret128( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 2 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 3 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, arraybuffer, byteoffset, length)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 32 ); - out = typedarray( buf, 8, 2, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpret64( out, 0 ); - t.strictEqual( view[ 0 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 2 ], 0.0, 'returns expected value' ); - t.strictEqual( view[ 3 ], 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, arraybuffer, byteoffset, length)', function test( t ) { - var view; - var buf; - var out; - - buf = new ArrayBuffer( 4 ); - out = typedarray( buf, 1, 2, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - view = reinterpretBoolean( out, 0 ); - t.strictEqual( view[ 0 ], 0, 'returns expected value' ); - t.strictEqual( view[ 1 ], 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, arraybuffer, byteoffset, length)', function test( t ) { - var buf = new ArrayBuffer( 16 ); - var out = typedarray( buf, 4, 2, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], 0, 'returns expected value' ); - t.strictEqual( out[ 1 ], 0, 'returns expected value' ); - t.end(); -}); diff --git a/uint16/README.md b/uint16/README.md deleted file mode 100644 index 25ec2c47..00000000 --- a/uint16/README.md +++ /dev/null @@ -1,1473 +0,0 @@ - - -# Uint16Array - -> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 16-bit unsigned integers in the platform byte order. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var Uint16Array = require( '@stdlib/array/uint16' ); -``` - -#### Uint16Array() - -A [typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 16-bit unsigned integers in the platform byte order. - - - -```javascript -var arr = new Uint16Array(); -// returns -``` - -#### Uint16Array( length ) - -Returns a [typed array][mdn-typed-array] having a specified length. - - - -```javascript -var arr = new Uint16Array( 5 ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### Uint16Array( typedarray ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var arr1 = new Float32Array( [ 5.0, 5.0, 5.0 ] ); -var arr2 = new Uint16Array( arr1 ); -// returns [ 5, 5, 5 ] -``` - -#### Uint16Array( obj ) - -Creates a [typed array][mdn-typed-array] from an array-like `object` or iterable. - - - -```javascript -var arr = new Uint16Array( [ 5.0, 5.0, 5.0 ] ); -// returns [ 5, 5, 5 ] -``` - -#### Uint16Array( buffer\[, byteOffset\[, length]] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); - -var buf = new ArrayBuffer( 8 ); -var arr = new Uint16Array( buf, 0, 4 ); -// returns [ 0, 0, 0, 0 ] -``` - -* * * - -### Properties - - - -#### Uint16Array.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var nbytes = Uint16Array.BYTES_PER_ELEMENT; -// returns 2 -``` - - - -#### Uint16Array.name - -[Typed array][mdn-typed-array] constructor name. - - - -```javascript -var str = Uint16Array.name; -// returns 'Uint16Array' -``` - - - -#### Uint16Array.prototype.buffer - -**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint16Array( 5 ); -var buf = arr.buffer; -// returns -``` - - - -#### Uint16Array.prototype.byteLength - -**Read-only** property which returns the length (in bytes) of the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint16Array( 5 ); -var byteLength = arr.byteLength; -// returns 10 -``` - - - -#### Uint16Array.prototype.byteOffset - -**Read-only** property which returns the offset (in bytes) of the [typed array][mdn-typed-array] from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var arr = new Uint16Array( 5 ); -var byteOffset = arr.byteOffset; -// returns 0 -``` - - - -#### Uint16Array.prototype.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var arr = new Uint16Array( 5 ); -var nbytes = arr.BYTES_PER_ELEMENT; -// returns 2 -``` - - - -#### Uint16Array.prototype.length - -**Read-only** property which returns the number of view elements. - - - -```javascript -var arr = new Uint16Array( 5 ); -var len = arr.length; -// returns 5 -``` - -* * * - -### Methods - - - -#### Uint16Array.from( src\[, map\[, thisArg]] ) - -Creates a new typed array from an array-like `object` or an iterable. - -```javascript -var arr = Uint16Array.from( [ 1, 2 ] ); -// returns [ 1, 2 ] -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function mapFcn( v ) { - return v * 2; -} - -var arr = Uint16Array.from( [ 1, 2 ], mapFcn ); -// returns [ 2, 4 ] -``` - -A callback function is provided two arguments: - -- `value`: source value -- `index`: source index - -To set the callback execution context, provide a `thisArg`. - -```javascript -function mapFcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr = Uint16Array.from( [ 1, 2 ], mapFcn, ctx ); -// returns [ 2, 4 ] - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint16Array.of( element0\[, element1\[, ...elementN]] ) - -Creates a new typed array from a variable number of arguments. - -```javascript -var arr = Uint16Array.of( 1, 2 ); -// returns [ 1, 2 ] -``` - - - -#### Uint16Array.prototype.copyWithin( target, start\[, end] ) - -Copies a sequence of elements within an array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the last two elements to the first two elements: -arr.copyWithin( 0, 3 ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( 3, 0, 2 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - -When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( -2, -5, -3 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - - - -#### Uint16Array.prototype.entries() - -Returns an iterator for iterating over array key-value pairs. - - - -```javascript -var arr = new Uint16Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.entries(); - -// Iterate over key-value pairs... -var v = it.next().value; -// returns [ 0, 1 ] - -v = it.next().value; -// returns [ 1, 2 ] - -var bool = it.next().done; -// returns true -``` - - - -#### Uint16Array.prototype.every( predicate\[, thisArg] ) - -Tests whether all array elements pass a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v <= 1 ); -} - -var arr = new Uint16Array( [ 1, 2 ] ); - -var bool = arr.every( predicate ); -// returns false -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 1 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint16Array( [ 1, 2 ] ); - -var bool = arr.every( predicate, ctx ); -// returns true - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint16Array.prototype.fill( value\[, start\[, end]] ) - -Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `value`. - - - -```javascript -var arr = new Uint16Array( 2 ); - -// Set all array elements to the same value: -arr.fill( 2 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 2 - -// Set all array elements starting from the first index to the same value: -arr.fill( 3, 1 ); - -v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 3 - -// Set all array elements, except the last element, to the same value: -arr.fill( 4, 0, arr.length-1 ); - -v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 3 -``` - -When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr = new Uint16Array( 2 ); - -// Set all array elements, except the last element, to the same value: -arr.fill( 2, -arr.length, -1 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 0 -``` - - - -#### Uint16Array.prototype.filter( predicate\[, thisArg] ) - -Creates a new array (of the same data type as the host array) which includes those elements for which a `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [ 2, 3 ] -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns an empty array. - - - -```javascript -function predicate( v ) { - return ( v >= 10 ); -} - -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [] -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint16Array.prototype.find( predicate\[, thisArg] ) - -Returns the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v > 2 ); -} - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns 3 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `undefined`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns undefined -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v > 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate, ctx ); -// returns 3 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint16Array.prototype.findIndex( predicate\[, thisArg] ) - -Returns the index of the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 3 ); -} - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns 2 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `-1`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns -1 -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 3 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate, ctx ); -// returns 2 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint16Array.prototype.forEach( fcn\[, thisArg] ) - -Invokes a callback for each array element. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var str = ''; - -function fcn( v, i ) { - str += i + ':' + v; - if ( i < arr.length-1 ) { - str += ' '; - } -} - -arr.forEach( fcn ); - -console.log( str ); -// => '0:1 1:2 2:3' -``` - -The callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn() { - this.count += 1; -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -arr.forEach( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint16Array.prototype.includes( searchElement\[, fromIndex] ) - -Returns a `boolean` indicating whether an array includes a search element. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 3 ); -// returns true - -bool = arr.includes( 0 ); -// returns false -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, 1 ); -// returns false -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, -2 ); -// returns false -``` - - - -#### Uint16Array.prototype.indexOf( searchElement\[, fromIndex] ) - -Returns the index of the first array element strictly equal to a search element. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 3 ); -// returns 2 - -idx = arr.indexOf( 0 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, 1 ); -// returns -1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, -2 ); -// returns -1 -``` - - - -#### Uint16Array.prototype.join( \[separator] ) - -Serializes an array by joining all array elements as a string. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var str = arr.join(); -// returns '1,2,3' -``` - -By default, the method delineates array elements using a comma `,`. To specify a custom separator, provide a `separator` string. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var str = arr.join( '|' ); -// returns '1|2|3' -``` - - - -#### Uint16Array.prototype.keys() - -Returns an iterator for iterating over array keys. - - - -```javascript -var arr = new Uint16Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.keys(); - -// Iterate over keys... -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - - - -#### Uint16Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) - -Returns the index of the last array element strictly equal to a search element, iterating from right to left. - - - -```javascript -var arr = new Uint16Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0 ); -// returns 3 - -idx = arr.lastIndexOf( 3 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = -1`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint16Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, 2 ); -// returns 1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint16Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, -3 ); -// returns 1 -``` - - - -#### Uint16Array.prototype.map( fcn\[, thisArg] ) - -Maps each array element to an element in a new array having the same data type as the host array. - - - -```javascript -function fcn( v ) { - return v * 2; -} - -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn ); -// returns [ 2, 4, 6 ] -``` - -A callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint16Array.prototype.reduce( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint16Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn ); -// returns 12 -``` - -If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint16Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint16Array.prototype.reduceRight( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint16Array( [ 2, 1, 3 ] ); - -var v = arr.reduceRight( fcn ); -// returns 8 -``` - -If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint16Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint16Array.prototype.reverse() - -Reverses an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint16Array( [ 2, 0, 3 ] ); - -// Reverse the array: -arr.reverse(); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 0 - -v = arr[ 2 ]; -// returns 2 -``` - - - -#### Uint16Array.prototype.set( arr\[, offset] ) - -Sets array elements. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the first two array elements: -arr.set( [ 4, 5 ] ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the last two array elements: -arr.set( [ 4, 5 ], 1 ); - -var v = arr[ 1 ]; -// returns 4 - -v = arr[ 2 ]; -// returns 5 -``` - - - -#### Uint16Array.prototype.slice( \[begin\[, end]] ) - -Copies array elements to a new array with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice(); - -var bool = ( arr1 === arr2 ); -// returns false - -bool = ( arr1.buffer === arr2.buffer ); -// returns false - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 - -v = arr2[ 2 ]; -// returns 3 -``` - -By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 2 - -v = arr2[ 1 ]; -// returns 3 -``` - -By default, the method copies all array elements after `begin`. To specify an alternative array index at which to end copying, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 0, 2 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( -arr1.length, -1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - - - -#### Uint16Array.prototype.some( predicate\[, thisArg] ) - -Tests whether at least one array element passes a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr = new Uint16Array( [ 1, 2 ] ); - -var bool = arr.some( predicate ); -// returns true -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint16Array( [ 1, 1 ] ); - -var bool = arr.some( predicate, ctx ); -// returns false - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint16Array.prototype.sort( \[compareFunction] ) - -Sorts an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint16Array( [ 2, 3, 0 ] ); - -// Sort the array (in ascending order): -arr.sort(); - -var v = arr[ 0 ]; -// returns 0 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 3 -``` - -By default, the method sorts array elements in ascending order. To impose a custom order, provide a `compareFunction`. - - - -```javascript -function descending( a, b ) { - return b - a; -} - -var arr = new Uint16Array( [ 2, 3, 0 ] ); - -// Sort the array (in descending order): -arr.sort( descending ); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 0 -``` - -The comparison function is provided two array elements, `a` and `b`, per invocation, and its return value determines the sort order as follows: - -- If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`). -- If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`). -- If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged. - - - -#### Uint16Array.prototype.subarray( \[begin\[, end]] ) - -Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray(); -// returns [ 1, 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 1 ); -// returns [ 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 0, 2 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( -arr1.length, -1 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array. - - - -```javascript -var arr1 = new Uint16Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 10, -1 ); -// returns [] -``` - - - -#### Uint16Array.prototype.toLocaleString( \[locales\[, options]] ) - -Serializes an array as a locale-specific `string`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var str = arr.toLocaleString(); -// returns '1,2,3' -``` - - - -#### Uint16Array.prototype.toString() - -Serializes an array as a `string`. - - - -```javascript -var arr = new Uint16Array( [ 1, 2, 3 ] ); - -var str = arr.toString(); -// returns '1,2,3' -``` - - - -#### Uint16Array.prototype.values() - -Returns an iterator for iterating over array elements. - - - -```javascript -var arr = new Uint16Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.values(); - -// Iterate over array elements... -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -
- - - -* * * - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var ctor = require( '@stdlib/array/uint16' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/uint16/benchmark/benchmark.copy_within.js b/uint16/benchmark/benchmark.copy_within.js deleted file mode 100644 index 7c903c34..00000000 --- a/uint16/benchmark/benchmark.copy_within.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':copyWithin', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.copy_within.length.js b/uint16/benchmark/benchmark.copy_within.length.js deleted file mode 100644 index 84e9cd61..00000000 --- a/uint16/benchmark/benchmark.copy_within.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':copyWithin:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.data.js b/uint16/benchmark/benchmark.data.js deleted file mode 100644 index fb912ea2..00000000 --- a/uint16/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get,index', function benchmark( b ) { - var arr; - var N; - var v; - var i; - - arr = new Uint16Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr[ i%N ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,index', function benchmark( b ) { - var arr; - var N; - var i; - - arr = new Uint16Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%N ] = i; - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.entries.js b/uint16/benchmark/benchmark.entries.js deleted file mode 100644 index 072c7c53..00000000 --- a/uint16/benchmark/benchmark.entries.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':entries', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint16Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.entries(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.every.js b/uint16/benchmark/benchmark.every.js deleted file mode 100644 index 93a5d357..00000000 --- a/uint16/benchmark/benchmark.every.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint16/benchmark/benchmark.every.length.js b/uint16/benchmark/benchmark.every.length.js deleted file mode 100644 index 3340d983..00000000 --- a/uint16/benchmark/benchmark.every.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':every:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.fill.js b/uint16/benchmark/benchmark.fill.js deleted file mode 100644 index f0983e0d..00000000 --- a/uint16/benchmark/benchmark.fill.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':fill', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.fill.length.js b/uint16/benchmark/benchmark.fill.length.js deleted file mode 100644 index 33877794..00000000 --- a/uint16/benchmark/benchmark.fill.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':fill:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.filter.js b/uint16/benchmark/benchmark.filter.js deleted file mode 100644 index e9d36969..00000000 --- a/uint16/benchmark/benchmark.filter.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint16/benchmark/benchmark.filter.length.js b/uint16/benchmark/benchmark.filter.length.js deleted file mode 100644 index 6941c0a6..00000000 --- a/uint16/benchmark/benchmark.filter.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':filter:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.find.js b/uint16/benchmark/benchmark.find.js deleted file mode 100644 index 1d347e49..00000000 --- a/uint16/benchmark/benchmark.find.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate, {} ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint16/benchmark/benchmark.find.length.js b/uint16/benchmark/benchmark.find.length.js deleted file mode 100644 index b1cfa5ec..00000000 --- a/uint16/benchmark/benchmark.find.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - tuple length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':find:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.find_index.js b/uint16/benchmark/benchmark.find_index.js deleted file mode 100644 index c1e86611..00000000 --- a/uint16/benchmark/benchmark.find_index.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate, {} ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint16/benchmark/benchmark.find_index.length.js b/uint16/benchmark/benchmark.find_index.length.js deleted file mode 100644 index 83fd164a..00000000 --- a/uint16/benchmark/benchmark.find_index.length.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':findIndex:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.for_each.js b/uint16/benchmark/benchmark.for_each.js deleted file mode 100644 index 67594f8d..00000000 --- a/uint16/benchmark/benchmark.for_each.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint16Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); - -bench( pkg+'::this_context:forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint16Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn, {} ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); diff --git a/uint16/benchmark/benchmark.for_each.length.js b/uint16/benchmark/benchmark.for_each.length.js deleted file mode 100644 index ed6ad3f5..00000000 --- a/uint16/benchmark/benchmark.for_each.length.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var count; - var arr; - - arr = new Uint16Array( len ); - count = 0; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } - - /** - * Callback invoked for each tuple element. - * - * @private - */ - function fcn() { - count += 1; - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':forEach:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.from.js b/uint16/benchmark/benchmark.from.js deleted file mode 100644 index 44de0b6f..00000000 --- a/uint16/benchmark/benchmark.from.js +++ /dev/null @@ -1,237 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ITERATOR_SYMBOL === null ) -}; - - -// MAIN // - -bench( pkg+'::typed_array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint16Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint16Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::iterable:from', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( createIterable() ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 0, - 'done': false - }; - } - return { - 'done': true - }; - } - } -}); - -bench( pkg+'::iterable,clbk:from:', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.from( createIterable(), clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 1, - 'done': false - }; - } - return { - 'done': true - }; - } - } - - function clbk( v ) { - return v + 1; - } -}); diff --git a/uint16/benchmark/benchmark.includes.js b/uint16/benchmark/benchmark.includes.js deleted file mode 100644 index 45b77212..00000000 --- a/uint16/benchmark/benchmark.includes.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':includes', function benchmark( b ) { - var bool; - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.includes.length.js b/uint16/benchmark/benchmark.includes.length.js deleted file mode 100644 index 6bc43f18..00000000 --- a/uint16/benchmark/benchmark.includes.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':includes:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.index_of.js b/uint16/benchmark/benchmark.index_of.js deleted file mode 100644 index c3f4e865..00000000 --- a/uint16/benchmark/benchmark.index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':indexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.index_of.length.js b/uint16/benchmark/benchmark.index_of.length.js deleted file mode 100644 index 70ae6f9c..00000000 --- a/uint16/benchmark/benchmark.index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':indexOf:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.join.js b/uint16/benchmark/benchmark.join.js deleted file mode 100644 index bc8234cf..00000000 --- a/uint16/benchmark/benchmark.join.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':join', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.join.length.js b/uint16/benchmark/benchmark.join.length.js deleted file mode 100644 index 94f15eab..00000000 --- a/uint16/benchmark/benchmark.join.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':join:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.js b/uint16/benchmark/benchmark.js deleted file mode 100644 index 85f605e3..00000000 --- a/uint16/benchmark/benchmark.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.keys.js b/uint16/benchmark/benchmark.keys.js deleted file mode 100644 index d65e8f0f..00000000 --- a/uint16/benchmark/benchmark.keys.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':keys', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.keys(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.last_index_of.js b/uint16/benchmark/benchmark.last_index_of.js deleted file mode 100644 index 318584ae..00000000 --- a/uint16/benchmark/benchmark.last_index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':lastIndexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.last_index_of.length.js b/uint16/benchmark/benchmark.last_index_of.length.js deleted file mode 100644 index 2f711a73..00000000 --- a/uint16/benchmark/benchmark.last_index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':lastIndexOf:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.length.js b/uint16/benchmark/benchmark.length.js deleted file mode 100644 index a91be015..00000000 --- a/uint16/benchmark/benchmark.length.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( len ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.map.js b/uint16/benchmark/benchmark.map.js deleted file mode 100644 index a6389e1d..00000000 --- a/uint16/benchmark/benchmark.map.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); - -bench( pkg+'::this_context:map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint16/benchmark/benchmark.map.length.js b/uint16/benchmark/benchmark.map.length.js deleted file mode 100644 index 460ac068..00000000 --- a/uint16/benchmark/benchmark.map.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Maps an array element to a new value. -* -* @private -* @param {*} value - array element -* @returns {*} new value -*/ -function fcn( value ) { - return value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':map:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.of.js b/uint16/benchmark/benchmark.of.js deleted file mode 100644 index a82d4ffe..00000000 --- a/uint16/benchmark/benchmark.of.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':of', function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint16Array.of( i, 2 ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint16Array( arr ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.properties.js b/uint16/benchmark/benchmark.properties.js deleted file mode 100644 index 7805cb96..00000000 --- a/uint16/benchmark/benchmark.properties.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get:buffer', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.buffer; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArrayBuffer( v ) ) { - b.fail( 'should return an ArrayBuffer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteLength', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteLength; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteOffset', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteOffset; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.BYTES_PER_ELEMENT; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:length', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.length; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.reduce.js b/uint16/benchmark/benchmark.reduce.js deleted file mode 100644 index dd3dfdd1..00000000 --- a/uint16/benchmark/benchmark.reduce.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint16/benchmark/benchmark.reduce.length.js b/uint16/benchmark/benchmark.reduce.length.js deleted file mode 100644 index 1023c907..00000000 --- a/uint16/benchmark/benchmark.reduce.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduce:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.reduce_right.js b/uint16/benchmark/benchmark.reduce_right.js deleted file mode 100644 index ec3f69b9..00000000 --- a/uint16/benchmark/benchmark.reduce_right.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint16/benchmark/benchmark.reduce_right.length.js b/uint16/benchmark/benchmark.reduce_right.length.js deleted file mode 100644 index f2e544b7..00000000 --- a/uint16/benchmark/benchmark.reduce_right.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduceRight:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.reverse.js b/uint16/benchmark/benchmark.reverse.js deleted file mode 100644 index 4ead6ff8..00000000 --- a/uint16/benchmark/benchmark.reverse.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reverse', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.reverse.length.js b/uint16/benchmark/benchmark.reverse.length.js deleted file mode 100644 index 653f41a3..00000000 --- a/uint16/benchmark/benchmark.reverse.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reverse:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.set.js b/uint16/benchmark/benchmark.set.js deleted file mode 100644 index 1598ea32..00000000 --- a/uint16/benchmark/benchmark.set.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = []; - for ( i = 0; i < 10; i++ ) { - values.push( i ); - } - N = values.length; - - arr = new Uint16Array( 2 ); - buf = [ 0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = new Uint16Array( 20 ); - N = values.length; - for ( i = 0; i < N; i++ ) { - values[ i ] = i; - } - - arr = new Uint16Array( 2 ); - buf = new Uint16Array( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.set.length.js b/uint16/benchmark/benchmark.set.length.js deleted file mode 100644 index be2a0c9f..00000000 --- a/uint16/benchmark/benchmark.set.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var arr1; - var arr2; - var arr; - var N; - var i; - - arr1 = []; - arr2 = []; - for ( i = 0; i < len; i++ ) { - arr1.push( randi() ); - arr2.push( randi() ); - } - arr = new Uint16Array( len ); - - values = [ - arr1, - arr2 - ]; - N = values.length; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr.set( values[ i%N ] ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':set:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.slice.js b/uint16/benchmark/benchmark.slice.js deleted file mode 100644 index e5c0dbb5..00000000 --- a/uint16/benchmark/benchmark.slice.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':slice', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.slice.length.js b/uint16/benchmark/benchmark.slice.length.js deleted file mode 100644 index f5b60c8b..00000000 --- a/uint16/benchmark/benchmark.slice.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':slice:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.some.js b/uint16/benchmark/benchmark.some.js deleted file mode 100644 index 6a9ede19..00000000 --- a/uint16/benchmark/benchmark.some.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint16/benchmark/benchmark.some.length.js b/uint16/benchmark/benchmark.some.length.js deleted file mode 100644 index f5fc249e..00000000 --- a/uint16/benchmark/benchmark.some.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':some:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.sort.js b/uint16/benchmark/benchmark.sort.js deleted file mode 100644 index ce9f9124..00000000 --- a/uint16/benchmark/benchmark.sort.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':sort', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( [ randi(), randi() ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.sort.length.js b/uint16/benchmark/benchmark.sort.length.js deleted file mode 100644 index 5af89301..00000000 --- a/uint16/benchmark/benchmark.sort.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var data; - var arr; - var i; - - data = []; - for ( i = 0; i < len; i++ ) { - data.push( randi() ); - } - arr = new Uint16Array( data ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%len ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':sort:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.subarray.js b/uint16/benchmark/benchmark.subarray.js deleted file mode 100644 index ecfbb3e8..00000000 --- a/uint16/benchmark/benchmark.subarray.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':subarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.subarray.length.js b/uint16/benchmark/benchmark.subarray.length.js deleted file mode 100644 index b0931b06..00000000 --- a/uint16/benchmark/benchmark.subarray.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint16Array = require( '@stdlib/assert/is-uint16array' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint16Array( out ) ) { - b.fail( 'should return a Uint16Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':subarray:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.to_locale_string.js b/uint16/benchmark/benchmark.to_locale_string.js deleted file mode 100644 index 2afdc453..00000000 --- a/uint16/benchmark/benchmark.to_locale_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toLocaleString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.to_locale_string.length.js b/uint16/benchmark/benchmark.to_locale_string.length.js deleted file mode 100644 index f08d59c6..00000000 --- a/uint16/benchmark/benchmark.to_locale_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toLocaleString:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.to_string.js b/uint16/benchmark/benchmark.to_string.js deleted file mode 100644 index 4e731b56..00000000 --- a/uint16/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/benchmark/benchmark.to_string.length.js b/uint16/benchmark/benchmark.to_string.length.js deleted file mode 100644 index 94478a00..00000000 --- a/uint16/benchmark/benchmark.to_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint16Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toString:len='+len, f ); - } -} - -main(); diff --git a/uint16/benchmark/benchmark.values.js b/uint16/benchmark/benchmark.values.js deleted file mode 100644 index 5e39e6c1..00000000 --- a/uint16/benchmark/benchmark.values.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint16Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':values', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.values(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint16/docs/repl.txt b/uint16/docs/repl.txt deleted file mode 100644 index 26658c36..00000000 --- a/uint16/docs/repl.txt +++ /dev/null @@ -1,953 +0,0 @@ - -{{alias}}() - A typed array constructor which returns a typed array representing an array - of 16-bit unsigned integers in the platform byte order. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}() - - - -{{alias}}( length ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray ) - Creates a typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias:@stdlib/array/int32}}( [ 5, 5, 5 ] ); - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( obj ) - Creates a typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr1 = [ 5.0, 5.0, 5.0 ]; - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( buffer[, byteOffset[, length]] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 8 ); - > var arr = new {{alias}}( buf, 0, 4 ) - [ 0, 0, 0, 0 ] - - -{{alias}}.from( src[, map[, thisArg]] ) - Creates a new typed array from an array-like object or an iterable. - - A callback is provided the following arguments: - - - value: source value. - - index: source index. - - Parameters - ---------- - src: ArrayLike|Iterable - Source of array elements. - - map: Function (optional) - Callback to invoke for each source element. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > function mapFcn( v ) { return v * 2; }; - > var arr = {{alias}}.from( [ 1, 2 ], mapFcn ) - [ 2, 4 ] - - -{{alias}}.of( element0[, element1[, ...elementN]] ) - Creates a new typed array from a variable number of arguments. - - Parameters - ---------- - element0: number - Array element. - - element1: number (optional) - Array element. - - elementN: ...number (optional) - Array elements. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr = {{alias}}.of( 1, 2 ) - [ 1, 2 ] - - -{{alias}}.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > {{alias}}.BYTES_PER_ELEMENT - 2 - - -{{alias}}.name - Typed array constructor name. - - Examples - -------- - > {{alias}}.name - 'Uint16Array' - - -{{alias}}.prototype.buffer - Read-only property which returns the ArrayBuffer referenced by the typed - array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.buffer - - - -{{alias}}.prototype.byteLength - Read-only property which returns the length (in bytes) of the typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteLength - 10 - - -{{alias}}.prototype.byteOffset - Read-only property which returns the offset (in bytes) of the typed array - from the start of its ArrayBuffer. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteOffset - 0 - - -{{alias}}.prototype.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.BYTES_PER_ELEMENT - 2 - - -{{alias}}.prototype.length - Read-only property which returns the number of view elements. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.length - 5 - - -{{alias}}.prototype.copyWithin( target, start[, end] ) - Copies a sequence of elements within the array starting at `start` and - ending at `end` (non-inclusive) to the position starting at `target`. - - Parameters - ---------- - target: integer - Target start index position. - - start: integer - Source start index position. - - end: integer (optional) - Source end index position. Default: out.length. - - Returns - ------- - out: Uint16Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > arr.copyWithin( 3, 0, 2 ); - > arr[ 3 ] - 1 - > arr[ 4 ] - 2 - - -{{alias}}.prototype.entries() - Returns an iterator for iterating over array key-value pairs. - - Returns - ------- - iter: Iterator - Iterator for iterating over array key-value pairs. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.entries(); - > it.next().value - [ 0, 1 ] - > it.next().value - [ 1, 2 ] - > it.next().done - true - - -{{alias}}.prototype.every( predicate[, thisArg] ) - Tests whether all array elements pass a test implemented by a predicate - function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, an array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether all array elements pass. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v <= 1 ); }; - > arr.every( predicate ) - false - - -{{alias}}.prototype.fill( value[, start[, end]] ) - Fills an array from a start index to an end index (non-inclusive) with a - provided value. - - Parameters - ---------- - value: number - Fill value. - - start: integer (optional) - Start index. If less than zero, the start index is resolved relative to - the last array element. Default: 0. - - end: integer (optional) - End index (non-inclusive). If less than zero, the end index is resolved - relative to the last array element. Default: out.length. - - Returns - ------- - out: Uint16Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > arr.fill( 3 ); - > arr[ 0 ] - 3 - > arr[ 1 ] - 3 - - -{{alias}}.prototype.filter( predicate[, thisArg] ) - Creates a new array which includes those elements for which a predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - If a predicate function does not return a truthy value for any array - element, the method returns `null`. - - Parameters - ---------- - predicate: Function - Predicate function which filters array elements. If a predicate function - returns a truthy value, an array element is included in the output - array; otherwise, an array element is not included in the output array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > var arr2 = arr1.filter( predicate ); - > arr2.length - 2 - - -{{alias}}.prototype.find( predicate[, thisArg] ) - Returns the first array element for which a provided predicate function - returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `undefined`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - value: number|undefined - Array element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var v = arr.find( predicate ) - 3 - - -{{alias}}.prototype.findIndex( predicate[, thisArg] ) - Returns the index of the first array element for which a provided predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `-1`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var idx = arr.findIndex( predicate ) - 2 - - -{{alias}}.prototype.forEach( fcn[, thisArg] ) - Invokes a callback for each array element. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - fcn: Function - Function to invoke for each array element. - - thisArg: Any (optional) - Callback execution context. - - Examples - -------- - > var arr = new {{alias}}( [ 3, 2, 1 ] ); - > var str = ' '; - > function fcn( v, i ) { str += i + ':' + v + ' '; }; - > arr.forEach( fcn ); - > str - ' 0:3 1:2 2:1 ' - - -{{alias}}.prototype.includes( searchElement[, fromIndex] ) - Returns a boolean indicating whether an array includes a search element. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - bool: boolean - Boolean indicating whether an array includes a search element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var bool = arr.includes( 4 ) - false - > bool = arr.includes( 3 ) - true - - -{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) - Returns the index of the first array element strictly equal to a search - element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var idx = arr.indexOf( 4 ) - -1 - > idx = arr.indexOf( 3 ) - 2 - - -{{alias}}.prototype.join( [separator] ) - Serializes an array by joining all array elements as a string. - - Parameters - ---------- - separator: string (optional) - String delineating array elements. Default: ','. - - Returns - ------- - str: string - Array serialized as a string. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.join( '|' ) - '1|2|3' - - -{{alias}}.prototype.keys() - Returns an iterator for iterating over array keys. - - Returns - ------- - iter: Iterator - Iterator for iterating over array keys. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.keys(); - > it.next().value - 0 - > it.next().value - 1 - > it.next().done - true - - -{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) - Returns the index of the last array element strictly equal to a search - element. - - The method iterates from the last array element to the first array element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: -1. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 0, 2, 0, 1 ] ); - > var idx = arr.lastIndexOf( 3 ) - -1 - > idx = arr.lastIndexOf( 0 ) - 3 - - -{{alias}}.prototype.map( fcn[, thisArg] ) - Maps each array element to an element in a new typed array. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - Parameters - ---------- - fcn: Function - Function which maps array elements to elements in the new array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( v ) { return v * 2; }; - > var arr2 = arr1.map( fcn ) - [ 2, 4, 6 ] - - -{{alias}}.prototype.reduce( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the first array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the first array element as the first argument and the second array - element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduce( fcn, 0 ) - 14 - - -{{alias}}.prototype.reduceRight( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result, iterating from right to left. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the last array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the last array element as the first argument and the second-to-last - array element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduceRight( fcn, 0 ) - 14 - - -{{alias}}.prototype.reverse() - Reverses an array *in-place*. - - This method mutates the array on which the method is invoked. - - Returns - ------- - out: Uint16Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - - > arr.reverse() - [ 3, 2, 1 ] - - -{{alias}}.prototype.set( arr[, offset] ) - Sets array elements. - - Parameters - ---------- - arr: ArrayLike - Source array containing array values to set. - - offset: integer (optional) - Array index at which to start writing values. Default: 0. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.set( [ 4, 4 ], 1 ); - > arr[ 1 ] - 4 - > arr[ 2 ] - 4 - - -{{alias}}.prototype.slice( [begin[, end]] ) - Copies array elements to a new array with the same underlying data type as - the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns `null`. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint16Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > var arr2 = arr1.slice( 1 ); - > arr2.length - 2 - > arr2[ 0 ] - 2 - > arr2[ 1 ] - 3 - - -{{alias}}.prototype.some( predicate[, thisArg] ) - Tests whether at least one array element passes a test implemented by a - predicate function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, a array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether at least one array element passes. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > arr.some( predicate ) - true - - -{{alias}}.prototype.sort( [compareFunction] ) - Sorts an array *in-place*. - - The comparison function is provided two array elements per invocation: `a` - and `b`. - - The comparison function return value determines the sort order as follows: - - - If the comparison function returns a value less than zero, then the method - sorts `a` to an index lower than `b` (i.e., `a` should come *before* `b`). - - - If the comparison function returns a value greater than zero, then the - method sorts `a` to an index higher than `b` (i.e., `b` should come *before* - `a`). - - - If the comparison function returns zero, then the relative order of `a` - and `b` should remain unchanged. - - This method mutates the array on which the method is invoked. - - Parameters - ---------- - compareFunction: Function (optional) - Function which specifies the sort order. The default sort order is - ascending order. - - Returns - ------- - out: Uint16Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 0, 2, 1 ] ); - > arr.sort() - [ 0, 1, 1, 2, 2 ] - - -{{alias}}.prototype.subarray( [begin[, end]] ) - Creates a new typed array over the same underlying ArrayBuffer and with the - same underlying data type as the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns an empty typed array. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint16Array - A new typed array view. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > var arr2 = arr1.subarray( 2 ) - [ 3, 4, 5 ] - - -{{alias}}.prototype.toLocaleString( [locales[, options]] ) - Serializes an array as a locale-specific string. - - Parameters - ---------- - locales: string|Array (optional) - A BCP 47 language tag, or an array of such tags. - - options: Object (optional) - Options. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toLocaleString() - '1,2,3' - - -{{alias}}.prototype.toString() - Serializes an array as a string. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toString() - '1,2,3' - - -{{alias}}.prototype.values() - Returns an iterator for iterating over array elements. - - Returns - ------- - iter: Iterator - Iterator for iterating over array elements. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.values(); - > it.next().value - 1 - > it.next().value - 2 - > it.next().done - true - - - See Also - -------- - diff --git a/uint16/docs/types/index.d.ts b/uint16/docs/types/index.d.ts deleted file mode 100644 index fe62b616..00000000 --- a/uint16/docs/types/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -// EXPORTS // - -/** -* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order. -*/ -export = Uint16Array; diff --git a/uint16/docs/types/test.ts b/uint16/docs/types/test.ts deleted file mode 100644 index d6ec15ea..00000000 --- a/uint16/docs/types/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 @typescript-eslint/no-unused-expressions */ - -import Uint16Array = require( './index' ); - - -// TESTS // - -// The function returns a typed array instance... -{ - new Uint16Array( 10 ); // $ExpectType Uint16Array - new Uint16Array( [ 2, 5, 5, 7 ] ); // $ExpectType Uint16Array -} - -// The constructor function has to be invoked with `new`... -{ - Uint16Array( 10 ); // $ExpectError - Uint16Array( [ 2, 5, 5, 7 ] ); // $ExpectError -} diff --git a/uint16/examples/index.js b/uint16/examples/index.js deleted file mode 100644 index d0978bec..00000000 --- a/uint16/examples/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 round = require( '@stdlib/math/base/special/round' ); -var ctor = require( './../lib' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); diff --git a/uint16/lib/index.js b/uint16/lib/index.js deleted file mode 100644 index ce7e7ccb..00000000 --- a/uint16/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order. -* -* @module @stdlib/array/uint16 -* -* @example -* var ctor = require( '@stdlib/array/uint16' ); -* -* var arr = new ctor( 10 ); -* // returns -*/ - -// MODULES // - -var hasUint16ArraySupport = require( '@stdlib/assert/has-uint16array-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var ctor; -if ( hasUint16ArraySupport() ) { - ctor = builtin; -} else { - ctor = polyfill; -} - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint16/lib/main.js b/uint16/lib/main.js deleted file mode 100644 index c6c4bcd9..00000000 --- a/uint16/lib/main.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -var ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint16/lib/polyfill.js b/uint16/lib/polyfill.js deleted file mode 100644 index 0d55e2b7..00000000 --- a/uint16/lib/polyfill.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// TODO: write polyfill - -// MAIN // - -/** -* Typed array which represents an array of 16-bit unsigned integers in the platform byte order. -* -* @throws {Error} not implemented -*/ -function polyfill() { - throw new Error( 'not implemented' ); -} - - -// EXPORTS // - -module.exports = polyfill; diff --git a/uint16/package.json b/uint16/package.json deleted file mode 100644 index 67a4a877..00000000 --- a/uint16/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@stdlib/array/uint16", - "version": "0.0.0", - "description": "Uint16Array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "array", - "typed", - "typed array", - "typed-array", - "uint16array", - "uint16", - "uint16_t", - "integer", - "int", - "uint", - "unsigned", - "short" - ] -} diff --git a/uint16/test/test.copy_within.js b/uint16/test/test.copy_within.js deleted file mode 100644 index c8c3ab20..00000000 --- a/uint16/test/test.copy_within.js +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasProp = require( '@stdlib/assert/has-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var Uint16Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Uint16Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'a typed array instance has a `copyWithin` method for copying a sequence of elements within a typed array', function test( t ) { - var arr = new Uint16Array( 2 ); - t.strictEqual( hasProp( arr, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( arr.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint16Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within a typed array', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 0, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative target)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( -p.length, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 0, -2 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (end=length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 0, 3, p.length ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (non-inclusive end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 2, 0, 2 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 2, 0, -3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target >= length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( p.length, 3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target > start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint16Array( arr ); - p.copyWithin( 2, 0 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - t.strictEqual( p[ 4 ], 2, 'returns expected value' ); - - t.end(); -}); diff --git a/uint16/test/test.js b/uint16/test/test.js deleted file mode 100644 index 4b021746..00000000 --- a/uint16/test/test.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'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var hasUint16ArraySupport = require( '@stdlib/assert/has-uint16array-support' ); -var polyfill = require( './../lib/polyfill.js' ); -var ctor = require( './../lib' ); - - -// VARIABLES // - -var hasUint16Arrays = hasUint16ArraySupport(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment supports `Uint16Array`, the export is an alias for `Uint16Array`', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint16array-support': isTrue, - './main.js': Mock - }); - t.strictEqual( Foo, Mock, 'returns builtin' ); - - if ( hasUint16Arrays ) { - t.strictEqual( ctor, Uint16Array, 'is alias' ); // eslint-disable-line stdlib/require-globals - } - - t.end(); - - function Mock() { - return this; - } - - function isTrue() { - return true; - } -}); - -tape( 'if an environment does not support `Uint16Array`, the export is a polyfill', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint16array-support': isFalse - }); - - t.strictEqual( Foo, polyfill, 'returns polyfill' ); - t.end(); - - function isFalse() { - return false; - } -}); diff --git a/uint16/test/test.polyfill.js b/uint16/test/test.polyfill.js deleted file mode 100644 index 9d6fcb19..00000000 --- a/uint16/test/test.polyfill.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'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib/polyfill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error when invoked', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var f = new ctor(); // eslint-disable-line no-unused-vars - } -}); - -// TODO: tests diff --git a/uint32/README.md b/uint32/README.md deleted file mode 100644 index 668230d0..00000000 --- a/uint32/README.md +++ /dev/null @@ -1,1473 +0,0 @@ - - -# Uint32Array - -> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 32-bit unsigned integers in the platform byte order. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var Uint32Array = require( '@stdlib/array/uint32' ); -``` - -#### Uint32Array() - -A [typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 32-bit unsigned integers in the platform byte order. - - - -```javascript -var arr = new Uint32Array(); -// returns -``` - -#### Uint32Array( length ) - -Returns a [typed array][mdn-typed-array] having a specified length. - - - -```javascript -var arr = new Uint32Array( 5 ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### Uint32Array( typedarray ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var arr1 = new Float32Array( [ 5.0, 5.0, 5.0 ] ); -var arr2 = new Uint32Array( arr1 ); -// returns [ 5, 5, 5 ] -``` - -#### Uint32Array( obj ) - -Creates a [typed array][mdn-typed-array] from an array-like `object` or iterable. - - - -```javascript -var arr = new Uint32Array( [ 5.0, 5.0, 5.0 ] ); -// returns [ 5, 5, 5 ] -``` - -#### Uint32Array( buffer\[, byteOffset\[, length]] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); - -var buf = new ArrayBuffer( 16 ); -var arr = new Uint32Array( buf, 0, 4 ); -// returns [ 0, 0, 0, 0 ] -``` - -* * * - -### Properties - - - -#### Uint32Array.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var nbytes = Uint32Array.BYTES_PER_ELEMENT; -// returns 4 -``` - - - -#### Uint32Array.name - -[Typed array][mdn-typed-array] constructor name. - - - -```javascript -var str = Uint32Array.name; -// returns 'Uint32Array' -``` - - - -#### Uint32Array.prototype.buffer - -**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint32Array( 5 ); -var buf = arr.buffer; -// returns -``` - - - -#### Uint32Array.prototype.byteLength - -**Read-only** property which returns the length (in bytes) of the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint32Array( 5 ); -var byteLength = arr.byteLength; -// returns 20 -``` - - - -#### Uint32Array.prototype.byteOffset - -**Read-only** property which returns the offset (in bytes) of the [typed array][mdn-typed-array] from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var arr = new Uint32Array( 5 ); -var byteOffset = arr.byteOffset; -// returns 0 -``` - - - -#### Uint32Array.prototype.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var arr = new Uint32Array( 5 ); -var nbytes = arr.BYTES_PER_ELEMENT; -// returns 4 -``` - - - -#### Uint32Array.prototype.length - -**Read-only** property which returns the number of view elements. - - - -```javascript -var arr = new Uint32Array( 5 ); -var len = arr.length; -// returns 5 -``` - -* * * - -### Methods - - - -#### Uint32Array.from( src\[, map\[, thisArg]] ) - -Creates a new typed array from an array-like `object` or an iterable. - -```javascript -var arr = Uint32Array.from( [ 1, 2 ] ); -// returns [ 1, 2 ] -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function mapFcn( v ) { - return v * 2; -} - -var arr = Uint32Array.from( [ 1, 2 ], mapFcn ); -// returns [ 2, 4 ] -``` - -A callback function is provided two arguments: - -- `value`: source value -- `index`: source index - -To set the callback execution context, provide a `thisArg`. - -```javascript -function mapFcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr = Uint32Array.from( [ 1, 2 ], mapFcn, ctx ); -// returns [ 2, 4 ] - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint32Array.of( element0\[, element1\[, ...elementN]] ) - -Creates a new typed array from a variable number of arguments. - -```javascript -var arr = Uint32Array.of( 1, 2 ); -// returns [ 1, 2 ] -``` - - - -#### Uint32Array.prototype.copyWithin( target, start\[, end] ) - -Copies a sequence of elements within an array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the last two elements to the first two elements: -arr.copyWithin( 0, 3 ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( 3, 0, 2 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - -When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( -2, -5, -3 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - - - -#### Uint32Array.prototype.entries() - -Returns an iterator for iterating over array key-value pairs. - - - -```javascript -var arr = new Uint32Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.entries(); - -// Iterate over key-value pairs... -var v = it.next().value; -// returns [ 0, 1 ] - -v = it.next().value; -// returns [ 1, 2 ] - -var bool = it.next().done; -// returns true -``` - - - -#### Uint32Array.prototype.every( predicate\[, thisArg] ) - -Tests whether all array elements pass a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v <= 1 ); -} - -var arr = new Uint32Array( [ 1, 2 ] ); - -var bool = arr.every( predicate ); -// returns false -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 1 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint32Array( [ 1, 2 ] ); - -var bool = arr.every( predicate, ctx ); -// returns true - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint32Array.prototype.fill( value\[, start\[, end]] ) - -Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `value`. - - - -```javascript -var arr = new Uint32Array( 2 ); - -// Set all array elements to the same value: -arr.fill( 2 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 2 - -// Set all array elements starting from the first index to the same value: -arr.fill( 3, 1 ); - -v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 3 - -// Set all array elements, except the last element, to the same value: -arr.fill( 4, 0, arr.length-1 ); - -v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 3 -``` - -When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr = new Uint32Array( 2 ); - -// Set all array elements, except the last element, to the same value: -arr.fill( 2, -arr.length, -1 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 0 -``` - - - -#### Uint32Array.prototype.filter( predicate\[, thisArg] ) - -Creates a new array (of the same data type as the host array) which includes those elements for which a `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [ 2, 3 ] -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns an empty array. - - - -```javascript -function predicate( v ) { - return ( v >= 10 ); -} - -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [] -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint32Array.prototype.find( predicate\[, thisArg] ) - -Returns the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v > 2 ); -} - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns 3 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `undefined`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns undefined -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v > 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate, ctx ); -// returns 3 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint32Array.prototype.findIndex( predicate\[, thisArg] ) - -Returns the index of the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 3 ); -} - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns 2 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `-1`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns -1 -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 3 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate, ctx ); -// returns 2 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint32Array.prototype.forEach( fcn\[, thisArg] ) - -Invokes a callback for each array element. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var str = ''; - -function fcn( v, i ) { - str += i + ':' + v; - if ( i < arr.length-1 ) { - str += ' '; - } -} - -arr.forEach( fcn ); - -console.log( str ); -// => '0:1 1:2 2:3' -``` - -The callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn() { - this.count += 1; -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -arr.forEach( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint32Array.prototype.includes( searchElement\[, fromIndex] ) - -Returns a `boolean` indicating whether an array includes a search element. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 3 ); -// returns true - -bool = arr.includes( 0 ); -// returns false -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, 1 ); -// returns false -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, -2 ); -// returns false -``` - - - -#### Uint32Array.prototype.indexOf( searchElement\[, fromIndex] ) - -Returns the index of the first array element strictly equal to a search element. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 3 ); -// returns 2 - -idx = arr.indexOf( 0 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, 1 ); -// returns -1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, -2 ); -// returns -1 -``` - - - -#### Uint32Array.prototype.join( \[separator] ) - -Serializes an array by joining all array elements as a string. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var str = arr.join(); -// returns '1,2,3' -``` - -By default, the method delineates array elements using a comma `,`. To specify a custom separator, provide a `separator` string. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var str = arr.join( '|' ); -// returns '1|2|3' -``` - - - -#### Uint32Array.prototype.keys() - -Returns an iterator for iterating over array keys. - - - -```javascript -var arr = new Uint32Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.keys(); - -// Iterate over keys... -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - - - -#### Uint32Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) - -Returns the index of the last array element strictly equal to a search element, iterating from right to left. - - - -```javascript -var arr = new Uint32Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0 ); -// returns 3 - -idx = arr.lastIndexOf( 3 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = -1`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint32Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, 2 ); -// returns 1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint32Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, -3 ); -// returns 1 -``` - - - -#### Uint32Array.prototype.map( fcn\[, thisArg] ) - -Maps each array element to an element in a new array having the same data type as the host array. - - - -```javascript -function fcn( v ) { - return v * 2; -} - -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn ); -// returns [ 2, 4, 6 ] -``` - -A callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint32Array.prototype.reduce( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint32Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn ); -// returns 12 -``` - -If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint32Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint32Array.prototype.reduceRight( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint32Array( [ 2, 1, 3 ] ); - -var v = arr.reduceRight( fcn ); -// returns 8 -``` - -If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint32Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint32Array.prototype.reverse() - -Reverses an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint32Array( [ 2, 0, 3 ] ); - -// Reverse the array: -arr.reverse(); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 0 - -v = arr[ 2 ]; -// returns 2 -``` - - - -#### Uint32Array.prototype.set( arr\[, offset] ) - -Sets array elements. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the first two array elements: -arr.set( [ 4, 5 ] ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the last two array elements: -arr.set( [ 4, 5 ], 1 ); - -var v = arr[ 1 ]; -// returns 4 - -v = arr[ 2 ]; -// returns 5 -``` - - - -#### Uint32Array.prototype.slice( \[begin\[, end]] ) - -Copies array elements to a new array with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice(); - -var bool = ( arr1 === arr2 ); -// returns false - -bool = ( arr1.buffer === arr2.buffer ); -// returns false - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 - -v = arr2[ 2 ]; -// returns 3 -``` - -By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 2 - -v = arr2[ 1 ]; -// returns 3 -``` - -By default, the method copies all array elements after `begin`. To specify an alternative array index at which to end copying, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 0, 2 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( -arr1.length, -1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - - - -#### Uint32Array.prototype.some( predicate\[, thisArg] ) - -Tests whether at least one array element passes a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr = new Uint32Array( [ 1, 2 ] ); - -var bool = arr.some( predicate ); -// returns true -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint32Array( [ 1, 1 ] ); - -var bool = arr.some( predicate, ctx ); -// returns false - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint32Array.prototype.sort( \[compareFunction] ) - -Sorts an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint32Array( [ 2, 3, 0 ] ); - -// Sort the array (in ascending order): -arr.sort(); - -var v = arr[ 0 ]; -// returns 0 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 3 -``` - -By default, the method sorts array elements in ascending order. To impose a custom order, provide a `compareFunction`. - - - -```javascript -function descending( a, b ) { - return b - a; -} - -var arr = new Uint32Array( [ 2, 3, 0 ] ); - -// Sort the array (in descending order): -arr.sort( descending ); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 0 -``` - -The comparison function is provided two array elements, `a` and `b`, per invocation, and its return value determines the sort order as follows: - -- If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`). -- If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`). -- If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged. - - - -#### Uint32Array.prototype.subarray( \[begin\[, end]] ) - -Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray(); -// returns [ 1, 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 1 ); -// returns [ 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 0, 2 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( -arr1.length, -1 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array. - - - -```javascript -var arr1 = new Uint32Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 10, -1 ); -// returns [] -``` - - - -#### Uint32Array.prototype.toLocaleString( \[locales\[, options]] ) - -Serializes an array as a locale-specific `string`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var str = arr.toLocaleString(); -// returns '1,2,3' -``` - - - -#### Uint32Array.prototype.toString() - -Serializes an array as a `string`. - - - -```javascript -var arr = new Uint32Array( [ 1, 2, 3 ] ); - -var str = arr.toString(); -// returns '1,2,3' -``` - - - -#### Uint32Array.prototype.values() - -Returns an iterator for iterating over array elements. - - - -```javascript -var arr = new Uint32Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.values(); - -// Iterate over array elements... -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -
- - - -* * * - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var ctor = require( '@stdlib/array/uint32' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/uint32/benchmark/benchmark.copy_within.js b/uint32/benchmark/benchmark.copy_within.js deleted file mode 100644 index c9ddce74..00000000 --- a/uint32/benchmark/benchmark.copy_within.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':copyWithin', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.copy_within.length.js b/uint32/benchmark/benchmark.copy_within.length.js deleted file mode 100644 index 1822878d..00000000 --- a/uint32/benchmark/benchmark.copy_within.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':copyWithin:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.data.js b/uint32/benchmark/benchmark.data.js deleted file mode 100644 index e2999221..00000000 --- a/uint32/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get,index', function benchmark( b ) { - var arr; - var N; - var v; - var i; - - arr = new Uint32Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr[ i%N ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,index', function benchmark( b ) { - var arr; - var N; - var i; - - arr = new Uint32Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%N ] = i; - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.entries.js b/uint32/benchmark/benchmark.entries.js deleted file mode 100644 index b14d89bd..00000000 --- a/uint32/benchmark/benchmark.entries.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':entries', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint32Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.entries(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.every.js b/uint32/benchmark/benchmark.every.js deleted file mode 100644 index 27e2f00d..00000000 --- a/uint32/benchmark/benchmark.every.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint32/benchmark/benchmark.every.length.js b/uint32/benchmark/benchmark.every.length.js deleted file mode 100644 index 92bc5336..00000000 --- a/uint32/benchmark/benchmark.every.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':every:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.fill.js b/uint32/benchmark/benchmark.fill.js deleted file mode 100644 index ad81b7bf..00000000 --- a/uint32/benchmark/benchmark.fill.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':fill', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.fill.length.js b/uint32/benchmark/benchmark.fill.length.js deleted file mode 100644 index cd975c94..00000000 --- a/uint32/benchmark/benchmark.fill.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':fill:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.filter.js b/uint32/benchmark/benchmark.filter.js deleted file mode 100644 index 2482f798..00000000 --- a/uint32/benchmark/benchmark.filter.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint32/benchmark/benchmark.filter.length.js b/uint32/benchmark/benchmark.filter.length.js deleted file mode 100644 index 9f0be6f7..00000000 --- a/uint32/benchmark/benchmark.filter.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':filter:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.find.js b/uint32/benchmark/benchmark.find.js deleted file mode 100644 index ed2e4fd0..00000000 --- a/uint32/benchmark/benchmark.find.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate, {} ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint32/benchmark/benchmark.find.length.js b/uint32/benchmark/benchmark.find.length.js deleted file mode 100644 index 594f6f3a..00000000 --- a/uint32/benchmark/benchmark.find.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - tuple length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':find:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.find_index.js b/uint32/benchmark/benchmark.find_index.js deleted file mode 100644 index e724bed5..00000000 --- a/uint32/benchmark/benchmark.find_index.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate, {} ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint32/benchmark/benchmark.find_index.length.js b/uint32/benchmark/benchmark.find_index.length.js deleted file mode 100644 index 6cbba8ce..00000000 --- a/uint32/benchmark/benchmark.find_index.length.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':findIndex:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.for_each.js b/uint32/benchmark/benchmark.for_each.js deleted file mode 100644 index 8b5ae015..00000000 --- a/uint32/benchmark/benchmark.for_each.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint32Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); - -bench( pkg+'::this_context:forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint32Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn, {} ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); diff --git a/uint32/benchmark/benchmark.for_each.length.js b/uint32/benchmark/benchmark.for_each.length.js deleted file mode 100644 index d888fdf7..00000000 --- a/uint32/benchmark/benchmark.for_each.length.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var count; - var arr; - - arr = new Uint32Array( len ); - count = 0; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } - - /** - * Callback invoked for each tuple element. - * - * @private - */ - function fcn() { - count += 1; - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':forEach:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.from.js b/uint32/benchmark/benchmark.from.js deleted file mode 100644 index 4ff139df..00000000 --- a/uint32/benchmark/benchmark.from.js +++ /dev/null @@ -1,237 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ITERATOR_SYMBOL === null ) -}; - - -// MAIN // - -bench( pkg+'::typed_array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint32Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint32Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::iterable:from', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( createIterable() ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 0, - 'done': false - }; - } - return { - 'done': true - }; - } - } -}); - -bench( pkg+'::iterable,clbk:from:', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.from( createIterable(), clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 1, - 'done': false - }; - } - return { - 'done': true - }; - } - } - - function clbk( v ) { - return v + 1; - } -}); diff --git a/uint32/benchmark/benchmark.includes.js b/uint32/benchmark/benchmark.includes.js deleted file mode 100644 index e161e273..00000000 --- a/uint32/benchmark/benchmark.includes.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':includes', function benchmark( b ) { - var bool; - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.includes.length.js b/uint32/benchmark/benchmark.includes.length.js deleted file mode 100644 index 3472fabb..00000000 --- a/uint32/benchmark/benchmark.includes.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':includes:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.index_of.js b/uint32/benchmark/benchmark.index_of.js deleted file mode 100644 index 7f04d965..00000000 --- a/uint32/benchmark/benchmark.index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':indexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.index_of.length.js b/uint32/benchmark/benchmark.index_of.length.js deleted file mode 100644 index 9adbbeec..00000000 --- a/uint32/benchmark/benchmark.index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':indexOf:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.join.js b/uint32/benchmark/benchmark.join.js deleted file mode 100644 index 74605f53..00000000 --- a/uint32/benchmark/benchmark.join.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':join', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.join.length.js b/uint32/benchmark/benchmark.join.length.js deleted file mode 100644 index 8533a129..00000000 --- a/uint32/benchmark/benchmark.join.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':join:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.js b/uint32/benchmark/benchmark.js deleted file mode 100644 index bcdf8691..00000000 --- a/uint32/benchmark/benchmark.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.keys.js b/uint32/benchmark/benchmark.keys.js deleted file mode 100644 index e3d8e656..00000000 --- a/uint32/benchmark/benchmark.keys.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':keys', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.keys(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.last_index_of.js b/uint32/benchmark/benchmark.last_index_of.js deleted file mode 100644 index dd0e5847..00000000 --- a/uint32/benchmark/benchmark.last_index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':lastIndexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.last_index_of.length.js b/uint32/benchmark/benchmark.last_index_of.length.js deleted file mode 100644 index 03ab92e9..00000000 --- a/uint32/benchmark/benchmark.last_index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':lastIndexOf:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.length.js b/uint32/benchmark/benchmark.length.js deleted file mode 100644 index 75638104..00000000 --- a/uint32/benchmark/benchmark.length.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( len ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.map.js b/uint32/benchmark/benchmark.map.js deleted file mode 100644 index b57414a6..00000000 --- a/uint32/benchmark/benchmark.map.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); - -bench( pkg+'::this_context:map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint32/benchmark/benchmark.map.length.js b/uint32/benchmark/benchmark.map.length.js deleted file mode 100644 index 0fed7073..00000000 --- a/uint32/benchmark/benchmark.map.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Maps an array element to a new value. -* -* @private -* @param {*} value - array element -* @returns {*} new value -*/ -function fcn( value ) { - return value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':map:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.of.js b/uint32/benchmark/benchmark.of.js deleted file mode 100644 index 4b7f085c..00000000 --- a/uint32/benchmark/benchmark.of.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':of', function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint32Array.of( i, 2 ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint32Array( arr ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.properties.js b/uint32/benchmark/benchmark.properties.js deleted file mode 100644 index 75282035..00000000 --- a/uint32/benchmark/benchmark.properties.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get:buffer', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.buffer; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArrayBuffer( v ) ) { - b.fail( 'should return an ArrayBuffer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteLength', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteLength; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteOffset', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteOffset; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.BYTES_PER_ELEMENT; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:length', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.length; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.reduce.js b/uint32/benchmark/benchmark.reduce.js deleted file mode 100644 index 1a8a0858..00000000 --- a/uint32/benchmark/benchmark.reduce.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint32/benchmark/benchmark.reduce.length.js b/uint32/benchmark/benchmark.reduce.length.js deleted file mode 100644 index 36d875fb..00000000 --- a/uint32/benchmark/benchmark.reduce.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduce:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.reduce_right.js b/uint32/benchmark/benchmark.reduce_right.js deleted file mode 100644 index 22685d20..00000000 --- a/uint32/benchmark/benchmark.reduce_right.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint32/benchmark/benchmark.reduce_right.length.js b/uint32/benchmark/benchmark.reduce_right.length.js deleted file mode 100644 index fcba6798..00000000 --- a/uint32/benchmark/benchmark.reduce_right.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduceRight:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.reverse.js b/uint32/benchmark/benchmark.reverse.js deleted file mode 100644 index 49e486c3..00000000 --- a/uint32/benchmark/benchmark.reverse.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reverse', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.reverse.length.js b/uint32/benchmark/benchmark.reverse.length.js deleted file mode 100644 index bc78f719..00000000 --- a/uint32/benchmark/benchmark.reverse.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reverse:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.set.js b/uint32/benchmark/benchmark.set.js deleted file mode 100644 index fdcd920d..00000000 --- a/uint32/benchmark/benchmark.set.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = []; - for ( i = 0; i < 10; i++ ) { - values.push( i ); - } - N = values.length; - - arr = new Uint32Array( 2 ); - buf = [ 0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = new Uint32Array( 20 ); - N = values.length; - for ( i = 0; i < N; i++ ) { - values[ i ] = i; - } - - arr = new Uint32Array( 2 ); - buf = new Uint32Array( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.set.length.js b/uint32/benchmark/benchmark.set.length.js deleted file mode 100644 index 8d28e826..00000000 --- a/uint32/benchmark/benchmark.set.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var arr1; - var arr2; - var arr; - var N; - var i; - - arr1 = []; - arr2 = []; - for ( i = 0; i < len; i++ ) { - arr1.push( randi() ); - arr2.push( randi() ); - } - arr = new Uint32Array( len ); - - values = [ - arr1, - arr2 - ]; - N = values.length; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr.set( values[ i%N ] ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':set:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.slice.js b/uint32/benchmark/benchmark.slice.js deleted file mode 100644 index 00e73452..00000000 --- a/uint32/benchmark/benchmark.slice.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':slice', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.slice.length.js b/uint32/benchmark/benchmark.slice.length.js deleted file mode 100644 index e46ac89f..00000000 --- a/uint32/benchmark/benchmark.slice.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':slice:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.some.js b/uint32/benchmark/benchmark.some.js deleted file mode 100644 index 3abaeec2..00000000 --- a/uint32/benchmark/benchmark.some.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint32/benchmark/benchmark.some.length.js b/uint32/benchmark/benchmark.some.length.js deleted file mode 100644 index 8b8b2a53..00000000 --- a/uint32/benchmark/benchmark.some.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':some:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.sort.js b/uint32/benchmark/benchmark.sort.js deleted file mode 100644 index dd4f6a24..00000000 --- a/uint32/benchmark/benchmark.sort.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':sort', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( [ randi(), randi() ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.sort.length.js b/uint32/benchmark/benchmark.sort.length.js deleted file mode 100644 index c40b6ec9..00000000 --- a/uint32/benchmark/benchmark.sort.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var data; - var arr; - var i; - - data = []; - for ( i = 0; i < len; i++ ) { - data.push( randi() ); - } - arr = new Uint32Array( data ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%len ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':sort:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.subarray.js b/uint32/benchmark/benchmark.subarray.js deleted file mode 100644 index 5014eb4d..00000000 --- a/uint32/benchmark/benchmark.subarray.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':subarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.subarray.length.js b/uint32/benchmark/benchmark.subarray.length.js deleted file mode 100644 index 1bca9ab4..00000000 --- a/uint32/benchmark/benchmark.subarray.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint32Array = require( '@stdlib/assert/is-uint32array' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint32Array( out ) ) { - b.fail( 'should return a Uint32Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':subarray:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.to_locale_string.js b/uint32/benchmark/benchmark.to_locale_string.js deleted file mode 100644 index e947d2ad..00000000 --- a/uint32/benchmark/benchmark.to_locale_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toLocaleString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.to_locale_string.length.js b/uint32/benchmark/benchmark.to_locale_string.length.js deleted file mode 100644 index a4da2c18..00000000 --- a/uint32/benchmark/benchmark.to_locale_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toLocaleString:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.to_string.js b/uint32/benchmark/benchmark.to_string.js deleted file mode 100644 index 78c524a4..00000000 --- a/uint32/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/benchmark/benchmark.to_string.length.js b/uint32/benchmark/benchmark.to_string.length.js deleted file mode 100644 index af13a8cc..00000000 --- a/uint32/benchmark/benchmark.to_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint32Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toString:len='+len, f ); - } -} - -main(); diff --git a/uint32/benchmark/benchmark.values.js b/uint32/benchmark/benchmark.values.js deleted file mode 100644 index 3854804a..00000000 --- a/uint32/benchmark/benchmark.values.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint32Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':values', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.values(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint32/docs/repl.txt b/uint32/docs/repl.txt deleted file mode 100644 index e8a0ace1..00000000 --- a/uint32/docs/repl.txt +++ /dev/null @@ -1,953 +0,0 @@ - -{{alias}}() - A typed array constructor which returns a typed array representing an array - of 32-bit unsigned integers in the platform byte order. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}() - - - -{{alias}}( length ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray ) - Creates a typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias:@stdlib/array/int32}}( [ 5, 5, 5 ] ); - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( obj ) - Creates a typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr1 = [ 5.0, 5.0, 5.0 ]; - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( buffer[, byteOffset[, length]] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 16 ); - > var arr = new {{alias}}( buf, 0, 4 ) - [ 0, 0, 0, 0 ] - - -{{alias}}.from( src[, map[, thisArg]] ) - Creates a new typed array from an array-like object or an iterable. - - A callback is provided the following arguments: - - - value: source value. - - index: source index. - - Parameters - ---------- - src: ArrayLike|Iterable - Source of array elements. - - map: Function (optional) - Callback to invoke for each source element. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > function mapFcn( v ) { return v * 2; }; - > var arr = {{alias}}.from( [ 1, 2 ], mapFcn ) - [ 2, 4 ] - - -{{alias}}.of( element0[, element1[, ...elementN]] ) - Creates a new typed array from a variable number of arguments. - - Parameters - ---------- - element0: number - Array element. - - element1: number (optional) - Array element. - - elementN: ...number (optional) - Array elements. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr = {{alias}}.of( 1, 2 ) - [ 1, 2 ] - - -{{alias}}.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > {{alias}}.BYTES_PER_ELEMENT - 4 - - -{{alias}}.name - Typed array constructor name. - - Examples - -------- - > {{alias}}.name - 'Uint32Array' - - -{{alias}}.prototype.buffer - Read-only property which returns the ArrayBuffer referenced by the typed - array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.buffer - - - -{{alias}}.prototype.byteLength - Read-only property which returns the length (in bytes) of the typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteLength - 20 - - -{{alias}}.prototype.byteOffset - Read-only property which returns the offset (in bytes) of the typed array - from the start of its ArrayBuffer. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteOffset - 0 - - -{{alias}}.prototype.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.BYTES_PER_ELEMENT - 4 - - -{{alias}}.prototype.length - Read-only property which returns the number of view elements. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.length - 5 - - -{{alias}}.prototype.copyWithin( target, start[, end] ) - Copies a sequence of elements within the array starting at `start` and - ending at `end` (non-inclusive) to the position starting at `target`. - - Parameters - ---------- - target: integer - Target start index position. - - start: integer - Source start index position. - - end: integer (optional) - Source end index position. Default: out.length. - - Returns - ------- - out: Uint32Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > arr.copyWithin( 3, 0, 2 ); - > arr[ 3 ] - 1 - > arr[ 4 ] - 2 - - -{{alias}}.prototype.entries() - Returns an iterator for iterating over array key-value pairs. - - Returns - ------- - iter: Iterator - Iterator for iterating over array key-value pairs. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.entries(); - > it.next().value - [ 0, 1 ] - > it.next().value - [ 1, 2 ] - > it.next().done - true - - -{{alias}}.prototype.every( predicate[, thisArg] ) - Tests whether all array elements pass a test implemented by a predicate - function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, an array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether all array elements pass. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v <= 1 ); }; - > arr.every( predicate ) - false - - -{{alias}}.prototype.fill( value[, start[, end]] ) - Fills an array from a start index to an end index (non-inclusive) with a - provided value. - - Parameters - ---------- - value: number - Fill value. - - start: integer (optional) - Start index. If less than zero, the start index is resolved relative to - the last array element. Default: 0. - - end: integer (optional) - End index (non-inclusive). If less than zero, the end index is resolved - relative to the last array element. Default: out.length. - - Returns - ------- - out: Uint32Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > arr.fill( 3 ); - > arr[ 0 ] - 3 - > arr[ 1 ] - 3 - - -{{alias}}.prototype.filter( predicate[, thisArg] ) - Creates a new array which includes those elements for which a predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - If a predicate function does not return a truthy value for any array - element, the method returns `null`. - - Parameters - ---------- - predicate: Function - Predicate function which filters array elements. If a predicate function - returns a truthy value, an array element is included in the output - array; otherwise, an array element is not included in the output array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > var arr2 = arr1.filter( predicate ); - > arr2.length - 2 - - -{{alias}}.prototype.find( predicate[, thisArg] ) - Returns the first array element for which a provided predicate function - returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `undefined`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - value: number|undefined - Array element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var v = arr.find( predicate ) - 3 - - -{{alias}}.prototype.findIndex( predicate[, thisArg] ) - Returns the index of the first array element for which a provided predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `-1`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var idx = arr.findIndex( predicate ) - 2 - - -{{alias}}.prototype.forEach( fcn[, thisArg] ) - Invokes a callback for each array element. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - fcn: Function - Function to invoke for each array element. - - thisArg: Any (optional) - Callback execution context. - - Examples - -------- - > var arr = new {{alias}}( [ 3, 2, 1 ] ); - > var str = ' '; - > function fcn( v, i ) { str += i + ':' + v + ' '; }; - > arr.forEach( fcn ); - > str - ' 0:3 1:2 2:1 ' - - -{{alias}}.prototype.includes( searchElement[, fromIndex] ) - Returns a boolean indicating whether an array includes a search element. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - bool: boolean - Boolean indicating whether an array includes a search element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var bool = arr.includes( 4 ) - false - > bool = arr.includes( 3 ) - true - - -{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) - Returns the index of the first array element strictly equal to a search - element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var idx = arr.indexOf( 4 ) - -1 - > idx = arr.indexOf( 3 ) - 2 - - -{{alias}}.prototype.join( [separator] ) - Serializes an array by joining all array elements as a string. - - Parameters - ---------- - separator: string (optional) - String delineating array elements. Default: ','. - - Returns - ------- - str: string - Array serialized as a string. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.join( '|' ) - '1|2|3' - - -{{alias}}.prototype.keys() - Returns an iterator for iterating over array keys. - - Returns - ------- - iter: Iterator - Iterator for iterating over array keys. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.keys(); - > it.next().value - 0 - > it.next().value - 1 - > it.next().done - true - - -{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) - Returns the index of the last array element strictly equal to a search - element. - - The method iterates from the last array element to the first array element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: -1. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 0, 2, 0, 1 ] ); - > var idx = arr.lastIndexOf( 3 ) - -1 - > idx = arr.lastIndexOf( 0 ) - 3 - - -{{alias}}.prototype.map( fcn[, thisArg] ) - Maps each array element to an element in a new typed array. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - Parameters - ---------- - fcn: Function - Function which maps array elements to elements in the new array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( v ) { return v * 2; }; - > var arr2 = arr1.map( fcn ) - [ 2, 4, 6 ] - - -{{alias}}.prototype.reduce( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the first array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the first array element as the first argument and the second array - element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduce( fcn, 0 ) - 14 - - -{{alias}}.prototype.reduceRight( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result, iterating from right to left. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the last array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the last array element as the first argument and the second-to-last - array element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduceRight( fcn, 0 ) - 14 - - -{{alias}}.prototype.reverse() - Reverses an array *in-place*. - - This method mutates the array on which the method is invoked. - - Returns - ------- - out: Uint32Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - - > arr.reverse() - [ 3, 2, 1 ] - - -{{alias}}.prototype.set( arr[, offset] ) - Sets array elements. - - Parameters - ---------- - arr: ArrayLike - Source array containing array values to set. - - offset: integer (optional) - Array index at which to start writing values. Default: 0. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.set( [ 4, 4 ], 1 ); - > arr[ 1 ] - 4 - > arr[ 2 ] - 4 - - -{{alias}}.prototype.slice( [begin[, end]] ) - Copies array elements to a new array with the same underlying data type as - the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns `null`. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint32Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > var arr2 = arr1.slice( 1 ); - > arr2.length - 2 - > arr2[ 0 ] - 2 - > arr2[ 1 ] - 3 - - -{{alias}}.prototype.some( predicate[, thisArg] ) - Tests whether at least one array element passes a test implemented by a - predicate function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, a array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether at least one array element passes. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > arr.some( predicate ) - true - - -{{alias}}.prototype.sort( [compareFunction] ) - Sorts an array *in-place*. - - The comparison function is provided two array elements per invocation: `a` - and `b`. - - The comparison function return value determines the sort order as follows: - - - If the comparison function returns a value less than zero, then the method - sorts `a` to an index lower than `b` (i.e., `a` should come *before* `b`). - - - If the comparison function returns a value greater than zero, then the - method sorts `a` to an index higher than `b` (i.e., `b` should come *before* - `a`). - - - If the comparison function returns zero, then the relative order of `a` - and `b` should remain unchanged. - - This method mutates the array on which the method is invoked. - - Parameters - ---------- - compareFunction: Function (optional) - Function which specifies the sort order. The default sort order is - ascending order. - - Returns - ------- - out: Uint32Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 0, 2, 1 ] ); - > arr.sort() - [ 0, 1, 1, 2, 2 ] - - -{{alias}}.prototype.subarray( [begin[, end]] ) - Creates a new typed array over the same underlying ArrayBuffer and with the - same underlying data type as the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns an empty typed array. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint32Array - A new typed array view. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > var arr2 = arr1.subarray( 2 ) - [ 3, 4, 5 ] - - -{{alias}}.prototype.toLocaleString( [locales[, options]] ) - Serializes an array as a locale-specific string. - - Parameters - ---------- - locales: string|Array (optional) - A BCP 47 language tag, or an array of such tags. - - options: Object (optional) - Options. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toLocaleString() - '1,2,3' - - -{{alias}}.prototype.toString() - Serializes an array as a string. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toString() - '1,2,3' - - -{{alias}}.prototype.values() - Returns an iterator for iterating over array elements. - - Returns - ------- - iter: Iterator - Iterator for iterating over array elements. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.values(); - > it.next().value - 1 - > it.next().value - 2 - > it.next().done - true - - - See Also - -------- - diff --git a/uint32/docs/types/index.d.ts b/uint32/docs/types/index.d.ts deleted file mode 100644 index e6977523..00000000 --- a/uint32/docs/types/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -// EXPORTS // - -/** -* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order. -*/ -export = Uint32Array; diff --git a/uint32/docs/types/test.ts b/uint32/docs/types/test.ts deleted file mode 100644 index da155025..00000000 --- a/uint32/docs/types/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 @typescript-eslint/no-unused-expressions */ - -import Uint32Array = require( './index' ); - - -// TESTS // - -// The function returns a typed array instance... -{ - new Uint32Array( 10 ); // $ExpectType Uint32Array - new Uint32Array( [ 2, 5, 5, 7 ] ); // $ExpectType Uint32Array -} - -// The constructor function has to be invoked with `new`... -{ - Uint32Array( 10 ); // $ExpectError - Uint32Array( [ 2, 5, 5, 7 ] ); // $ExpectError -} diff --git a/uint32/examples/index.js b/uint32/examples/index.js deleted file mode 100644 index d0978bec..00000000 --- a/uint32/examples/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 round = require( '@stdlib/math/base/special/round' ); -var ctor = require( './../lib' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); diff --git a/uint32/lib/index.js b/uint32/lib/index.js deleted file mode 100644 index bf04214d..00000000 --- a/uint32/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order. -* -* @module @stdlib/array/uint32 -* -* @example -* var ctor = require( '@stdlib/array/uint32' ); -* -* var arr = new ctor( 10 ); -* // returns -*/ - -// MODULES // - -var hasUint32ArraySupport = require( '@stdlib/assert/has-uint32array-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var ctor; -if ( hasUint32ArraySupport() ) { - ctor = builtin; -} else { - ctor = polyfill; -} - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint32/lib/main.js b/uint32/lib/main.js deleted file mode 100644 index 9ac4e62c..00000000 --- a/uint32/lib/main.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -var ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint32/lib/polyfill.js b/uint32/lib/polyfill.js deleted file mode 100644 index c20fe2ed..00000000 --- a/uint32/lib/polyfill.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// TODO: write polyfill - -// MAIN // - -/** -* Typed array which represents an array of 32-bit unsigned integers in the platform byte order. -* -* @throws {Error} not implemented -*/ -function polyfill() { - throw new Error( 'not implemented' ); -} - - -// EXPORTS // - -module.exports = polyfill; diff --git a/uint32/package.json b/uint32/package.json deleted file mode 100644 index c306da1d..00000000 --- a/uint32/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "@stdlib/array/uint32", - "version": "0.0.0", - "description": "Uint32Array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "array", - "typed", - "typed array", - "typed-array", - "uint32array", - "uint32", - "uint32_t", - "integer", - "int", - "uint", - "unsigned", - "long" - ] -} diff --git a/uint32/test/test.copy_within.js b/uint32/test/test.copy_within.js deleted file mode 100644 index a02b4a21..00000000 --- a/uint32/test/test.copy_within.js +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasProp = require( '@stdlib/assert/has-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var Uint32Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Uint32Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'a typed array instance has a `copyWithin` method for copying a sequence of elements within a typed array', function test( t ) { - var arr = new Uint32Array( 2 ); - t.strictEqual( hasProp( arr, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( arr.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint32Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within a typed array', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 0, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative target)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( -p.length, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 0, -2 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (end=length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 0, 3, p.length ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (non-inclusive end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 2, 0, 2 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 2, 0, -3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target >= length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( p.length, 3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target > start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint32Array( arr ); - p.copyWithin( 2, 0 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - t.strictEqual( p[ 4 ], 2, 'returns expected value' ); - - t.end(); -}); diff --git a/uint32/test/test.js b/uint32/test/test.js deleted file mode 100644 index 20fad8de..00000000 --- a/uint32/test/test.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'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var hasUint32ArraySupport = require( '@stdlib/assert/has-uint32array-support' ); -var polyfill = require( './../lib/polyfill.js' ); -var ctor = require( './../lib' ); - - -// VARIABLES // - -var hasUint32Arrays = hasUint32ArraySupport(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment supports `Uint32Array`, the export is an alias for `Uint32Array`', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint32array-support': isTrue, - './main.js': Mock - }); - t.strictEqual( Foo, Mock, 'returns builtin' ); - - if ( hasUint32Arrays ) { - t.strictEqual( ctor, Uint32Array, 'is alias' ); // eslint-disable-line stdlib/require-globals - } - - t.end(); - - function Mock() { - return this; - } - - function isTrue() { - return true; - } -}); - -tape( 'if an environment does not support `Uint32Array`, the export is a polyfill', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint32array-support': isFalse - }); - - t.strictEqual( Foo, polyfill, 'returns polyfill' ); - t.end(); - - function isFalse() { - return false; - } -}); diff --git a/uint32/test/test.polyfill.js b/uint32/test/test.polyfill.js deleted file mode 100644 index 9d6fcb19..00000000 --- a/uint32/test/test.polyfill.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'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib/polyfill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error when invoked', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var f = new ctor(); // eslint-disable-line no-unused-vars - } -}); - -// TODO: tests diff --git a/uint8/README.md b/uint8/README.md deleted file mode 100644 index e58e5829..00000000 --- a/uint8/README.md +++ /dev/null @@ -1,1473 +0,0 @@ - - -# Uint8Array - -> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 8-bit unsigned integers in the platform byte order. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var Uint8Array = require( '@stdlib/array/uint8' ); -``` - -#### Uint8Array() - -A [typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 8-bit unsigned integers in the platform byte order. - - - -```javascript -var arr = new Uint8Array(); -// returns -``` - -#### Uint8Array( length ) - -Returns a [typed array][mdn-typed-array] having a specified length. - - - -```javascript -var arr = new Uint8Array( 5 ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### Uint8Array( typedarray ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var arr1 = new Float32Array( [ 5.0, 5.0, 5.0 ] ); -var arr2 = new Uint8Array( arr1 ); -// returns [ 5, 5, 5 ] -``` - -#### Uint8Array( obj ) - -Creates a [typed array][mdn-typed-array] from an array-like `object` or iterable. - - - -```javascript -var arr = new Uint8Array( [ 5.0, 5.0, 5.0 ] ); -// returns [ 5, 5, 5 ] -``` - -#### Uint8Array( buffer\[, byteOffset\[, length]] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); - -var buf = new ArrayBuffer( 4 ); -var arr = new Uint8Array( buf, 0, 4 ); -// returns [ 0, 0, 0, 0 ] -``` - -* * * - -### Properties - - - -#### Uint8Array.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var nbytes = Uint8Array.BYTES_PER_ELEMENT; -// returns 1 -``` - - - -#### Uint8Array.name - -[Typed array][mdn-typed-array] constructor name. - - - -```javascript -var str = Uint8Array.name; -// returns 'Uint8Array' -``` - - - -#### Uint8Array.prototype.buffer - -**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint8Array( 5 ); -var buf = arr.buffer; -// returns -``` - - - -#### Uint8Array.prototype.byteLength - -**Read-only** property which returns the length (in bytes) of the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint8Array( 5 ); -var byteLength = arr.byteLength; -// returns 5 -``` - - - -#### Uint8Array.prototype.byteOffset - -**Read-only** property which returns the offset (in bytes) of the [typed array][mdn-typed-array] from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var arr = new Uint8Array( 5 ); -var byteOffset = arr.byteOffset; -// returns 0 -``` - - - -#### Uint8Array.prototype.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var arr = new Uint8Array( 5 ); -var nbytes = arr.BYTES_PER_ELEMENT; -// returns 1 -``` - - - -#### Uint8Array.prototype.length - -**Read-only** property which returns the number of view elements. - - - -```javascript -var arr = new Uint8Array( 5 ); -var len = arr.length; -// returns 5 -``` - -* * * - -### Methods - - - -#### Uint8Array.from( src\[, map\[, thisArg]] ) - -Creates a new typed array from an array-like `object` or an iterable. - -```javascript -var arr = Uint8Array.from( [ 1, 2 ] ); -// returns [ 1, 2 ] -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function mapFcn( v ) { - return v * 2; -} - -var arr = Uint8Array.from( [ 1, 2 ], mapFcn ); -// returns [ 2, 4 ] -``` - -A callback function is provided two arguments: - -- `value`: source value -- `index`: source index - -To set the callback execution context, provide a `thisArg`. - -```javascript -function mapFcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr = Uint8Array.from( [ 1, 2 ], mapFcn, ctx ); -// returns [ 2, 4 ] - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8Array.of( element0\[, element1\[, ...elementN]] ) - -Creates a new typed array from a variable number of arguments. - -```javascript -var arr = Uint8Array.of( 1, 2 ); -// returns [ 1, 2 ] -``` - - - -#### Uint8Array.prototype.copyWithin( target, start\[, end] ) - -Copies a sequence of elements within an array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the last two elements to the first two elements: -arr.copyWithin( 0, 3 ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( 3, 0, 2 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - -When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( -2, -5, -3 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - - - -#### Uint8Array.prototype.entries() - -Returns an iterator for iterating over array key-value pairs. - - - -```javascript -var arr = new Uint8Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.entries(); - -// Iterate over key-value pairs... -var v = it.next().value; -// returns [ 0, 1 ] - -v = it.next().value; -// returns [ 1, 2 ] - -var bool = it.next().done; -// returns true -``` - - - -#### Uint8Array.prototype.every( predicate\[, thisArg] ) - -Tests whether all array elements pass a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v <= 1 ); -} - -var arr = new Uint8Array( [ 1, 2 ] ); - -var bool = arr.every( predicate ); -// returns false -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 1 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8Array( [ 1, 2 ] ); - -var bool = arr.every( predicate, ctx ); -// returns true - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8Array.prototype.fill( value\[, start\[, end]] ) - -Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `value`. - - - -```javascript -var arr = new Uint8Array( 2 ); - -// Set all array elements to the same value: -arr.fill( 2 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 2 - -// Set all array elements starting from the first index to the same value: -arr.fill( 3, 1 ); - -v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 3 - -// Set all array elements, except the last element, to the same value: -arr.fill( 4, 0, arr.length-1 ); - -v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 3 -``` - -When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr = new Uint8Array( 2 ); - -// Set all array elements, except the last element, to the same value: -arr.fill( 2, -arr.length, -1 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 0 -``` - - - -#### Uint8Array.prototype.filter( predicate\[, thisArg] ) - -Creates a new array (of the same data type as the host array) which includes those elements for which a `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [ 2, 3 ] -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns an empty array. - - - -```javascript -function predicate( v ) { - return ( v >= 10 ); -} - -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [] -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8Array.prototype.find( predicate\[, thisArg] ) - -Returns the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v > 2 ); -} - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns 3 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `undefined`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns undefined -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v > 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var v = arr.find( predicate, ctx ); -// returns 3 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8Array.prototype.findIndex( predicate\[, thisArg] ) - -Returns the index of the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 3 ); -} - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns 2 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `-1`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns -1 -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 3 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate, ctx ); -// returns 2 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8Array.prototype.forEach( fcn\[, thisArg] ) - -Invokes a callback for each array element. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var str = ''; - -function fcn( v, i ) { - str += i + ':' + v; - if ( i < arr.length-1 ) { - str += ' '; - } -} - -arr.forEach( fcn ); - -console.log( str ); -// => '0:1 1:2 2:3' -``` - -The callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn() { - this.count += 1; -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -arr.forEach( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8Array.prototype.includes( searchElement\[, fromIndex] ) - -Returns a `boolean` indicating whether an array includes a search element. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 3 ); -// returns true - -bool = arr.includes( 0 ); -// returns false -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, 1 ); -// returns false -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, -2 ); -// returns false -``` - - - -#### Uint8Array.prototype.indexOf( searchElement\[, fromIndex] ) - -Returns the index of the first array element strictly equal to a search element. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 3 ); -// returns 2 - -idx = arr.indexOf( 0 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, 1 ); -// returns -1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, -2 ); -// returns -1 -``` - - - -#### Uint8Array.prototype.join( \[separator] ) - -Serializes an array by joining all array elements as a string. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var str = arr.join(); -// returns '1,2,3' -``` - -By default, the method delineates array elements using a comma `,`. To specify a custom separator, provide a `separator` string. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var str = arr.join( '|' ); -// returns '1|2|3' -``` - - - -#### Uint8Array.prototype.keys() - -Returns an iterator for iterating over array keys. - - - -```javascript -var arr = new Uint8Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.keys(); - -// Iterate over keys... -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - - - -#### Uint8Array.prototype.lastIndexOf( searchElement\[, fromIndex] ) - -Returns the index of the last array element strictly equal to a search element, iterating from right to left. - - - -```javascript -var arr = new Uint8Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0 ); -// returns 3 - -idx = arr.lastIndexOf( 3 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = -1`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, 2 ); -// returns 1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8Array( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, -3 ); -// returns 1 -``` - - - -#### Uint8Array.prototype.map( fcn\[, thisArg] ) - -Maps each array element to an element in a new array having the same data type as the host array. - - - -```javascript -function fcn( v ) { - return v * 2; -} - -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn ); -// returns [ 2, 4, 6 ] -``` - -A callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8Array.prototype.reduce( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn ); -// returns 12 -``` - -If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint8Array.prototype.reduceRight( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8Array( [ 2, 1, 3 ] ); - -var v = arr.reduceRight( fcn ); -// returns 8 -``` - -If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8Array( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint8Array.prototype.reverse() - -Reverses an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint8Array( [ 2, 0, 3 ] ); - -// Reverse the array: -arr.reverse(); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 0 - -v = arr[ 2 ]; -// returns 2 -``` - - - -#### Uint8Array.prototype.set( arr\[, offset] ) - -Sets array elements. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the first two array elements: -arr.set( [ 4, 5 ] ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the last two array elements: -arr.set( [ 4, 5 ], 1 ); - -var v = arr[ 1 ]; -// returns 4 - -v = arr[ 2 ]; -// returns 5 -``` - - - -#### Uint8Array.prototype.slice( \[begin\[, end]] ) - -Copies array elements to a new array with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice(); - -var bool = ( arr1 === arr2 ); -// returns false - -bool = ( arr1.buffer === arr2.buffer ); -// returns false - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 - -v = arr2[ 2 ]; -// returns 3 -``` - -By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 2 - -v = arr2[ 1 ]; -// returns 3 -``` - -By default, the method copies all array elements after `begin`. To specify an alternative array index at which to end copying, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 0, 2 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( -arr1.length, -1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - - - -#### Uint8Array.prototype.some( predicate\[, thisArg] ) - -Tests whether at least one array element passes a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr = new Uint8Array( [ 1, 2 ] ); - -var bool = arr.some( predicate ); -// returns true -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8Array( [ 1, 1 ] ); - -var bool = arr.some( predicate, ctx ); -// returns false - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8Array.prototype.sort( \[compareFunction] ) - -Sorts an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint8Array( [ 2, 3, 0 ] ); - -// Sort the array (in ascending order): -arr.sort(); - -var v = arr[ 0 ]; -// returns 0 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 3 -``` - -By default, the method sorts array elements in ascending order. To impose a custom order, provide a `compareFunction`. - - - -```javascript -function descending( a, b ) { - return b - a; -} - -var arr = new Uint8Array( [ 2, 3, 0 ] ); - -// Sort the array (in descending order): -arr.sort( descending ); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 0 -``` - -The comparison function is provided two array elements, `a` and `b`, per invocation, and its return value determines the sort order as follows: - -- If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`). -- If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`). -- If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged. - - - -#### Uint8Array.prototype.subarray( \[begin\[, end]] ) - -Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray(); -// returns [ 1, 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 1 ); -// returns [ 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 0, 2 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( -arr1.length, -1 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array. - - - -```javascript -var arr1 = new Uint8Array( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 10, -1 ); -// returns [] -``` - - - -#### Uint8Array.prototype.toLocaleString( \[locales\[, options]] ) - -Serializes an array as a locale-specific `string`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var str = arr.toLocaleString(); -// returns '1,2,3' -``` - - - -#### Uint8Array.prototype.toString() - -Serializes an array as a `string`. - - - -```javascript -var arr = new Uint8Array( [ 1, 2, 3 ] ); - -var str = arr.toString(); -// returns '1,2,3' -``` - - - -#### Uint8Array.prototype.values() - -Returns an iterator for iterating over array elements. - - - -```javascript -var arr = new Uint8Array( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.values(); - -// Iterate over array elements... -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -
- - - -* * * - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var ctor = require( '@stdlib/array/uint8' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/uint8/benchmark/benchmark.copy_within.js b/uint8/benchmark/benchmark.copy_within.js deleted file mode 100644 index fd94b254..00000000 --- a/uint8/benchmark/benchmark.copy_within.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':copyWithin', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.copy_within.length.js b/uint8/benchmark/benchmark.copy_within.length.js deleted file mode 100644 index 7dd8aae0..00000000 --- a/uint8/benchmark/benchmark.copy_within.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':copyWithin:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.data.js b/uint8/benchmark/benchmark.data.js deleted file mode 100644 index c494b681..00000000 --- a/uint8/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get,index', function benchmark( b ) { - var arr; - var N; - var v; - var i; - - arr = new Uint8Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr[ i%N ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,index', function benchmark( b ) { - var arr; - var N; - var i; - - arr = new Uint8Array( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%N ] = i; - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.entries.js b/uint8/benchmark/benchmark.entries.js deleted file mode 100644 index fefbd578..00000000 --- a/uint8/benchmark/benchmark.entries.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':entries', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.entries(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.every.js b/uint8/benchmark/benchmark.every.js deleted file mode 100644 index d22cc45d..00000000 --- a/uint8/benchmark/benchmark.every.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint8/benchmark/benchmark.every.length.js b/uint8/benchmark/benchmark.every.length.js deleted file mode 100644 index f89c9abb..00000000 --- a/uint8/benchmark/benchmark.every.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':every:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.fill.js b/uint8/benchmark/benchmark.fill.js deleted file mode 100644 index ba36b131..00000000 --- a/uint8/benchmark/benchmark.fill.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':fill', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.fill.length.js b/uint8/benchmark/benchmark.fill.length.js deleted file mode 100644 index 010fbc57..00000000 --- a/uint8/benchmark/benchmark.fill.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':fill:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.filter.js b/uint8/benchmark/benchmark.filter.js deleted file mode 100644 index 1dae0041..00000000 --- a/uint8/benchmark/benchmark.filter.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint8/benchmark/benchmark.filter.length.js b/uint8/benchmark/benchmark.filter.length.js deleted file mode 100644 index 37014c67..00000000 --- a/uint8/benchmark/benchmark.filter.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':filter:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.find.js b/uint8/benchmark/benchmark.find.js deleted file mode 100644 index 5327e0eb..00000000 --- a/uint8/benchmark/benchmark.find.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate, {} ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8/benchmark/benchmark.find.length.js b/uint8/benchmark/benchmark.find.length.js deleted file mode 100644 index c3628e40..00000000 --- a/uint8/benchmark/benchmark.find.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - tuple length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':find:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.find_index.js b/uint8/benchmark/benchmark.find_index.js deleted file mode 100644 index b4d8cd42..00000000 --- a/uint8/benchmark/benchmark.find_index.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate, {} ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8/benchmark/benchmark.find_index.length.js b/uint8/benchmark/benchmark.find_index.length.js deleted file mode 100644 index bf124a99..00000000 --- a/uint8/benchmark/benchmark.find_index.length.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':findIndex:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.for_each.js b/uint8/benchmark/benchmark.for_each.js deleted file mode 100644 index 404a9c9d..00000000 --- a/uint8/benchmark/benchmark.for_each.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint8Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); - -bench( pkg+'::this_context:forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint8Array( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn, {} ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); diff --git a/uint8/benchmark/benchmark.for_each.length.js b/uint8/benchmark/benchmark.for_each.length.js deleted file mode 100644 index a7ef3a42..00000000 --- a/uint8/benchmark/benchmark.for_each.length.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var count; - var arr; - - arr = new Uint8Array( len ); - count = 0; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } - - /** - * Callback invoked for each tuple element. - * - * @private - */ - function fcn() { - count += 1; - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':forEach:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.from.js b/uint8/benchmark/benchmark.from.js deleted file mode 100644 index abe60a05..00000000 --- a/uint8/benchmark/benchmark.from.js +++ /dev/null @@ -1,237 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ITERATOR_SYMBOL === null ) -}; - - -// MAIN // - -bench( pkg+'::typed_array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint8Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint8Array( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::iterable:from', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( createIterable() ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 0, - 'done': false - }; - } - return { - 'done': true - }; - } - } -}); - -bench( pkg+'::iterable,clbk:from:', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.from( createIterable(), clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 1, - 'done': false - }; - } - return { - 'done': true - }; - } - } - - function clbk( v ) { - return v + 1; - } -}); diff --git a/uint8/benchmark/benchmark.includes.js b/uint8/benchmark/benchmark.includes.js deleted file mode 100644 index 12a1656c..00000000 --- a/uint8/benchmark/benchmark.includes.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':includes', function benchmark( b ) { - var bool; - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.includes.length.js b/uint8/benchmark/benchmark.includes.length.js deleted file mode 100644 index fdb98c85..00000000 --- a/uint8/benchmark/benchmark.includes.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':includes:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.index_of.js b/uint8/benchmark/benchmark.index_of.js deleted file mode 100644 index 8fa6d85b..00000000 --- a/uint8/benchmark/benchmark.index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':indexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.index_of.length.js b/uint8/benchmark/benchmark.index_of.length.js deleted file mode 100644 index dd76a68a..00000000 --- a/uint8/benchmark/benchmark.index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':indexOf:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.join.js b/uint8/benchmark/benchmark.join.js deleted file mode 100644 index 958aa548..00000000 --- a/uint8/benchmark/benchmark.join.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':join', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.join.length.js b/uint8/benchmark/benchmark.join.length.js deleted file mode 100644 index c25d2121..00000000 --- a/uint8/benchmark/benchmark.join.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':join:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.js b/uint8/benchmark/benchmark.js deleted file mode 100644 index f2514f53..00000000 --- a/uint8/benchmark/benchmark.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.keys.js b/uint8/benchmark/benchmark.keys.js deleted file mode 100644 index 2c70df05..00000000 --- a/uint8/benchmark/benchmark.keys.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':keys', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.keys(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.last_index_of.js b/uint8/benchmark/benchmark.last_index_of.js deleted file mode 100644 index 0e80fc65..00000000 --- a/uint8/benchmark/benchmark.last_index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':lastIndexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.last_index_of.length.js b/uint8/benchmark/benchmark.last_index_of.length.js deleted file mode 100644 index b36aa4c7..00000000 --- a/uint8/benchmark/benchmark.last_index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':lastIndexOf:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.length.js b/uint8/benchmark/benchmark.length.js deleted file mode 100644 index e40be57e..00000000 --- a/uint8/benchmark/benchmark.length.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( len ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.map.js b/uint8/benchmark/benchmark.map.js deleted file mode 100644 index 106bc120..00000000 --- a/uint8/benchmark/benchmark.map.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); - -bench( pkg+'::this_context:map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8/benchmark/benchmark.map.length.js b/uint8/benchmark/benchmark.map.length.js deleted file mode 100644 index f0200bd5..00000000 --- a/uint8/benchmark/benchmark.map.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Maps an array element to a new value. -* -* @private -* @param {*} value - array element -* @returns {*} new value -*/ -function fcn( value ) { - return value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':map:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.of.js b/uint8/benchmark/benchmark.of.js deleted file mode 100644 index 6aaa2bf4..00000000 --- a/uint8/benchmark/benchmark.of.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':of', function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8Array.of( i, 2 ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8Array( arr ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.properties.js b/uint8/benchmark/benchmark.properties.js deleted file mode 100644 index 891b634f..00000000 --- a/uint8/benchmark/benchmark.properties.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get:buffer', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.buffer; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArrayBuffer( v ) ) { - b.fail( 'should return an ArrayBuffer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteLength', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteLength; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteOffset', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteOffset; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.BYTES_PER_ELEMENT; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:length', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.length; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.reduce.js b/uint8/benchmark/benchmark.reduce.js deleted file mode 100644 index 21498da8..00000000 --- a/uint8/benchmark/benchmark.reduce.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8/benchmark/benchmark.reduce.length.js b/uint8/benchmark/benchmark.reduce.length.js deleted file mode 100644 index 82c3ceb4..00000000 --- a/uint8/benchmark/benchmark.reduce.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduce:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.reduce_right.js b/uint8/benchmark/benchmark.reduce_right.js deleted file mode 100644 index e452af1d..00000000 --- a/uint8/benchmark/benchmark.reduce_right.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8/benchmark/benchmark.reduce_right.length.js b/uint8/benchmark/benchmark.reduce_right.length.js deleted file mode 100644 index 6e1b422e..00000000 --- a/uint8/benchmark/benchmark.reduce_right.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduceRight:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.reverse.js b/uint8/benchmark/benchmark.reverse.js deleted file mode 100644 index 84bcc28b..00000000 --- a/uint8/benchmark/benchmark.reverse.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reverse', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.reverse.length.js b/uint8/benchmark/benchmark.reverse.length.js deleted file mode 100644 index e5e360ee..00000000 --- a/uint8/benchmark/benchmark.reverse.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reverse:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.set.js b/uint8/benchmark/benchmark.set.js deleted file mode 100644 index 59827e1e..00000000 --- a/uint8/benchmark/benchmark.set.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = []; - for ( i = 0; i < 10; i++ ) { - values.push( i ); - } - N = values.length; - - arr = new Uint8Array( 2 ); - buf = [ 0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = new Uint8Array( 20 ); - N = values.length; - for ( i = 0; i < N; i++ ) { - values[ i ] = i; - } - - arr = new Uint8Array( 2 ); - buf = new Uint8Array( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.set.length.js b/uint8/benchmark/benchmark.set.length.js deleted file mode 100644 index 052293f4..00000000 --- a/uint8/benchmark/benchmark.set.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var arr1; - var arr2; - var arr; - var N; - var i; - - arr1 = []; - arr2 = []; - for ( i = 0; i < len; i++ ) { - arr1.push( randi() ); - arr2.push( randi() ); - } - arr = new Uint8Array( len ); - - values = [ - arr1, - arr2 - ]; - N = values.length; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr.set( values[ i%N ] ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':set:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.slice.js b/uint8/benchmark/benchmark.slice.js deleted file mode 100644 index 874b535e..00000000 --- a/uint8/benchmark/benchmark.slice.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':slice', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.slice.length.js b/uint8/benchmark/benchmark.slice.length.js deleted file mode 100644 index 78e2b7e1..00000000 --- a/uint8/benchmark/benchmark.slice.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':slice:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.some.js b/uint8/benchmark/benchmark.some.js deleted file mode 100644 index f20c59ca..00000000 --- a/uint8/benchmark/benchmark.some.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8/benchmark/benchmark.some.length.js b/uint8/benchmark/benchmark.some.length.js deleted file mode 100644 index 647c0768..00000000 --- a/uint8/benchmark/benchmark.some.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':some:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.sort.js b/uint8/benchmark/benchmark.sort.js deleted file mode 100644 index 4d36b9d6..00000000 --- a/uint8/benchmark/benchmark.sort.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':sort', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( [ randi(), randi() ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.sort.length.js b/uint8/benchmark/benchmark.sort.length.js deleted file mode 100644 index ca66eda0..00000000 --- a/uint8/benchmark/benchmark.sort.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var data; - var arr; - var i; - - data = []; - for ( i = 0; i < len; i++ ) { - data.push( randi() ); - } - arr = new Uint8Array( data ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%len ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':sort:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.subarray.js b/uint8/benchmark/benchmark.subarray.js deleted file mode 100644 index 2c91017e..00000000 --- a/uint8/benchmark/benchmark.subarray.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':subarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.subarray.length.js b/uint8/benchmark/benchmark.subarray.length.js deleted file mode 100644 index e353f017..00000000 --- a/uint8/benchmark/benchmark.subarray.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8Array = require( '@stdlib/assert/is-uint8array' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8Array( out ) ) { - b.fail( 'should return a Uint8Array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':subarray:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.to_locale_string.js b/uint8/benchmark/benchmark.to_locale_string.js deleted file mode 100644 index 7631518a..00000000 --- a/uint8/benchmark/benchmark.to_locale_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toLocaleString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.to_locale_string.length.js b/uint8/benchmark/benchmark.to_locale_string.length.js deleted file mode 100644 index 824ebc29..00000000 --- a/uint8/benchmark/benchmark.to_locale_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toLocaleString:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.to_string.js b/uint8/benchmark/benchmark.to_string.js deleted file mode 100644 index 75f8bcb2..00000000 --- a/uint8/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/benchmark/benchmark.to_string.length.js b/uint8/benchmark/benchmark.to_string.length.js deleted file mode 100644 index de8020da..00000000 --- a/uint8/benchmark/benchmark.to_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8Array( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toString:len='+len, f ); - } -} - -main(); diff --git a/uint8/benchmark/benchmark.values.js b/uint8/benchmark/benchmark.values.js deleted file mode 100644 index f5932384..00000000 --- a/uint8/benchmark/benchmark.values.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8Array = require( './../lib' ); - - -// MAIN // - -bench( pkg+':values', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.values(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8/docs/repl.txt b/uint8/docs/repl.txt deleted file mode 100644 index d27af9be..00000000 --- a/uint8/docs/repl.txt +++ /dev/null @@ -1,953 +0,0 @@ - -{{alias}}() - A typed array constructor which returns a typed array representing an array - of 8-bit unsigned integers in the platform byte order. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}() - - - -{{alias}}( length ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray ) - Creates a typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias:@stdlib/array/int32}}( [ 5, 5, 5 ] ); - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( obj ) - Creates a typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr1 = [ 5.0, 5.0, 5.0 ]; - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( buffer[, byteOffset[, length]] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 4 ); - > var arr = new {{alias}}( buf, 0, 4 ) - [ 0, 0, 0, 0 ] - - -{{alias}}.from( src[, map[, thisArg]] ) - Creates a new typed array from an array-like object or an iterable. - - A callback is provided the following arguments: - - - value: source value. - - index: source index. - - Parameters - ---------- - src: ArrayLike|Iterable - Source of array elements. - - map: Function (optional) - Callback to invoke for each source element. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > function mapFcn( v ) { return v * 2; }; - > var arr = {{alias}}.from( [ 1, 2 ], mapFcn ) - [ 2, 4 ] - - -{{alias}}.of( element0[, element1[, ...elementN]] ) - Creates a new typed array from a variable number of arguments. - - Parameters - ---------- - element0: number - Array element. - - element1: number (optional) - Array element. - - elementN: ...number (optional) - Array elements. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr = {{alias}}.of( 1, 2 ) - [ 1, 2 ] - - -{{alias}}.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > {{alias}}.BYTES_PER_ELEMENT - 1 - - -{{alias}}.name - Typed array constructor name. - - Examples - -------- - > {{alias}}.name - 'Uint8Array' - - -{{alias}}.prototype.buffer - Read-only property which returns the ArrayBuffer referenced by the typed - array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.buffer - - - -{{alias}}.prototype.byteLength - Read-only property which returns the length (in bytes) of the typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteLength - 5 - - -{{alias}}.prototype.byteOffset - Read-only property which returns the offset (in bytes) of the typed array - from the start of its ArrayBuffer. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteOffset - 0 - - -{{alias}}.prototype.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.BYTES_PER_ELEMENT - 1 - - -{{alias}}.prototype.length - Read-only property which returns the number of view elements. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.length - 5 - - -{{alias}}.prototype.copyWithin( target, start[, end] ) - Copies a sequence of elements within the array starting at `start` and - ending at `end` (non-inclusive) to the position starting at `target`. - - Parameters - ---------- - target: integer - Target start index position. - - start: integer - Source start index position. - - end: integer (optional) - Source end index position. Default: out.length. - - Returns - ------- - out: Uint8Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > arr.copyWithin( 3, 0, 2 ); - > arr[ 3 ] - 1 - > arr[ 4 ] - 2 - - -{{alias}}.prototype.entries() - Returns an iterator for iterating over array key-value pairs. - - Returns - ------- - iter: Iterator - Iterator for iterating over array key-value pairs. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.entries(); - > it.next().value - [ 0, 1 ] - > it.next().value - [ 1, 2 ] - > it.next().done - true - - -{{alias}}.prototype.every( predicate[, thisArg] ) - Tests whether all array elements pass a test implemented by a predicate - function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, an array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether all array elements pass. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v <= 1 ); }; - > arr.every( predicate ) - false - - -{{alias}}.prototype.fill( value[, start[, end]] ) - Fills an array from a start index to an end index (non-inclusive) with a - provided value. - - Parameters - ---------- - value: number - Fill value. - - start: integer (optional) - Start index. If less than zero, the start index is resolved relative to - the last array element. Default: 0. - - end: integer (optional) - End index (non-inclusive). If less than zero, the end index is resolved - relative to the last array element. Default: out.length. - - Returns - ------- - out: Uint8Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > arr.fill( 3 ); - > arr[ 0 ] - 3 - > arr[ 1 ] - 3 - - -{{alias}}.prototype.filter( predicate[, thisArg] ) - Creates a new array which includes those elements for which a predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - If a predicate function does not return a truthy value for any array - element, the method returns `null`. - - Parameters - ---------- - predicate: Function - Predicate function which filters array elements. If a predicate function - returns a truthy value, an array element is included in the output - array; otherwise, an array element is not included in the output array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > var arr2 = arr1.filter( predicate ); - > arr2.length - 2 - - -{{alias}}.prototype.find( predicate[, thisArg] ) - Returns the first array element for which a provided predicate function - returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `undefined`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - value: number|undefined - Array element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var v = arr.find( predicate ) - 3 - - -{{alias}}.prototype.findIndex( predicate[, thisArg] ) - Returns the index of the first array element for which a provided predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `-1`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var idx = arr.findIndex( predicate ) - 2 - - -{{alias}}.prototype.forEach( fcn[, thisArg] ) - Invokes a callback for each array element. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - fcn: Function - Function to invoke for each array element. - - thisArg: Any (optional) - Callback execution context. - - Examples - -------- - > var arr = new {{alias}}( [ 3, 2, 1 ] ); - > var str = ' '; - > function fcn( v, i ) { str += i + ':' + v + ' '; }; - > arr.forEach( fcn ); - > str - ' 0:3 1:2 2:1 ' - - -{{alias}}.prototype.includes( searchElement[, fromIndex] ) - Returns a boolean indicating whether an array includes a search element. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - bool: boolean - Boolean indicating whether an array includes a search element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var bool = arr.includes( 4 ) - false - > bool = arr.includes( 3 ) - true - - -{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) - Returns the index of the first array element strictly equal to a search - element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var idx = arr.indexOf( 4 ) - -1 - > idx = arr.indexOf( 3 ) - 2 - - -{{alias}}.prototype.join( [separator] ) - Serializes an array by joining all array elements as a string. - - Parameters - ---------- - separator: string (optional) - String delineating array elements. Default: ','. - - Returns - ------- - str: string - Array serialized as a string. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.join( '|' ) - '1|2|3' - - -{{alias}}.prototype.keys() - Returns an iterator for iterating over array keys. - - Returns - ------- - iter: Iterator - Iterator for iterating over array keys. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.keys(); - > it.next().value - 0 - > it.next().value - 1 - > it.next().done - true - - -{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) - Returns the index of the last array element strictly equal to a search - element. - - The method iterates from the last array element to the first array element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: -1. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 0, 2, 0, 1 ] ); - > var idx = arr.lastIndexOf( 3 ) - -1 - > idx = arr.lastIndexOf( 0 ) - 3 - - -{{alias}}.prototype.map( fcn[, thisArg] ) - Maps each array element to an element in a new typed array. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - Parameters - ---------- - fcn: Function - Function which maps array elements to elements in the new array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( v ) { return v * 2; }; - > var arr2 = arr1.map( fcn ) - [ 2, 4, 6 ] - - -{{alias}}.prototype.reduce( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the first array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the first array element as the first argument and the second array - element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduce( fcn, 0 ) - 14 - - -{{alias}}.prototype.reduceRight( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result, iterating from right to left. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the last array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the last array element as the first argument and the second-to-last - array element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduceRight( fcn, 0 ) - 14 - - -{{alias}}.prototype.reverse() - Reverses an array *in-place*. - - This method mutates the array on which the method is invoked. - - Returns - ------- - out: Uint8Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - - > arr.reverse() - [ 3, 2, 1 ] - - -{{alias}}.prototype.set( arr[, offset] ) - Sets array elements. - - Parameters - ---------- - arr: ArrayLike - Source array containing array values to set. - - offset: integer (optional) - Array index at which to start writing values. Default: 0. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.set( [ 4, 4 ], 1 ); - > arr[ 1 ] - 4 - > arr[ 2 ] - 4 - - -{{alias}}.prototype.slice( [begin[, end]] ) - Copies array elements to a new array with the same underlying data type as - the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns `null`. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint8Array - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > var arr2 = arr1.slice( 1 ); - > arr2.length - 2 - > arr2[ 0 ] - 2 - > arr2[ 1 ] - 3 - - -{{alias}}.prototype.some( predicate[, thisArg] ) - Tests whether at least one array element passes a test implemented by a - predicate function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, a array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether at least one array element passes. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > arr.some( predicate ) - true - - -{{alias}}.prototype.sort( [compareFunction] ) - Sorts an array *in-place*. - - The comparison function is provided two array elements per invocation: `a` - and `b`. - - The comparison function return value determines the sort order as follows: - - - If the comparison function returns a value less than zero, then the method - sorts `a` to an index lower than `b` (i.e., `a` should come *before* `b`). - - - If the comparison function returns a value greater than zero, then the - method sorts `a` to an index higher than `b` (i.e., `b` should come *before* - `a`). - - - If the comparison function returns zero, then the relative order of `a` - and `b` should remain unchanged. - - This method mutates the array on which the method is invoked. - - Parameters - ---------- - compareFunction: Function (optional) - Function which specifies the sort order. The default sort order is - ascending order. - - Returns - ------- - out: Uint8Array - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 0, 2, 1 ] ); - > arr.sort() - [ 0, 1, 1, 2, 2 ] - - -{{alias}}.prototype.subarray( [begin[, end]] ) - Creates a new typed array over the same underlying ArrayBuffer and with the - same underlying data type as the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns an empty typed array. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint8Array - A new typed array view. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > var arr2 = arr1.subarray( 2 ) - [ 3, 4, 5 ] - - -{{alias}}.prototype.toLocaleString( [locales[, options]] ) - Serializes an array as a locale-specific string. - - Parameters - ---------- - locales: string|Array (optional) - A BCP 47 language tag, or an array of such tags. - - options: Object (optional) - Options. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toLocaleString() - '1,2,3' - - -{{alias}}.prototype.toString() - Serializes an array as a string. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toString() - '1,2,3' - - -{{alias}}.prototype.values() - Returns an iterator for iterating over array elements. - - Returns - ------- - iter: Iterator - Iterator for iterating over array elements. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.values(); - > it.next().value - 1 - > it.next().value - 2 - > it.next().done - true - - - See Also - -------- - diff --git a/uint8/docs/types/index.d.ts b/uint8/docs/types/index.d.ts deleted file mode 100644 index e55ca0b0..00000000 --- a/uint8/docs/types/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -// EXPORTS // - -/** -* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order. -*/ -export = Uint8Array; diff --git a/uint8/docs/types/test.ts b/uint8/docs/types/test.ts deleted file mode 100644 index 9b5061df..00000000 --- a/uint8/docs/types/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 @typescript-eslint/no-unused-expressions */ - -import Uint8Array = require( './index' ); - - -// TESTS // - -// The function returns a typed array instance... -{ - new Uint8Array( 10 ); // $ExpectType Uint8Array - new Uint8Array( [ 2, 5, 5, 7 ] ); // $ExpectType Uint8Array -} - -// The constructor function has to be invoked with `new`... -{ - Uint8Array( 10 ); // $ExpectError - Uint8Array( [ 2, 5, 5, 7 ] ); // $ExpectError -} diff --git a/uint8/examples/index.js b/uint8/examples/index.js deleted file mode 100644 index d0978bec..00000000 --- a/uint8/examples/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 round = require( '@stdlib/math/base/special/round' ); -var ctor = require( './../lib' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); diff --git a/uint8/lib/index.js b/uint8/lib/index.js deleted file mode 100644 index 84bbddea..00000000 --- a/uint8/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order. -* -* @module @stdlib/array/uint8 -* -* @example -* var ctor = require( '@stdlib/array/uint8' ); -* -* var arr = new ctor( 10 ); -* // returns -*/ - -// MODULES // - -var hasUint8ArraySupport = require( '@stdlib/assert/has-uint8array-support' ); -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var ctor; -if ( hasUint8ArraySupport() ) { - ctor = builtin; -} else { - ctor = polyfill; -} - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint8/lib/main.js b/uint8/lib/main.js deleted file mode 100644 index c19ff14e..00000000 --- a/uint8/lib/main.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -var ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint8/lib/polyfill.js b/uint8/lib/polyfill.js deleted file mode 100644 index 6b806341..00000000 --- a/uint8/lib/polyfill.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// TODO: write polyfill - -// MAIN // - -/** -* Typed array which represents an array of 8-bit unsigned integers in the platform byte order. -* -* @throws {Error} not implemented -*/ -function polyfill() { - throw new Error( 'not implemented' ); -} - - -// EXPORTS // - -module.exports = polyfill; diff --git a/uint8/package.json b/uint8/package.json deleted file mode 100644 index 49ec4b62..00000000 --- a/uint8/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "@stdlib/array/uint8", - "version": "0.0.0", - "description": "Uint8Array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "array", - "typed", - "typed array", - "typed-array", - "uint8array", - "uint8", - "uint8_t", - "integer", - "int", - "uint", - "unsigned", - "byte", - "octet" - ] -} diff --git a/uint8/test/test.copy_within.js b/uint8/test/test.copy_within.js deleted file mode 100644 index 56d67eea..00000000 --- a/uint8/test/test.copy_within.js +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasProp = require( '@stdlib/assert/has-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var Uint8Array = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Uint8Array, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'a typed array instance has a `copyWithin` method for copying a sequence of elements within a typed array', function test( t ) { - var arr = new Uint8Array( 2 ); - t.strictEqual( hasProp( arr, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( arr.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint8Array( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within a typed array', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 0, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative target)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( -p.length, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 0, -2 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (end=length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 0, 3, p.length ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (non-inclusive end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 2, 0, 2 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 2, 0, -3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target >= length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( p.length, 3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target > start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8Array( arr ); - p.copyWithin( 2, 0 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - t.strictEqual( p[ 4 ], 2, 'returns expected value' ); - - t.end(); -}); diff --git a/uint8/test/test.js b/uint8/test/test.js deleted file mode 100644 index 12f6f7e4..00000000 --- a/uint8/test/test.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'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var hasUint8ArraySupport = require( '@stdlib/assert/has-uint8array-support' ); -var polyfill = require( './../lib/polyfill.js' ); -var ctor = require( './../lib' ); - - -// VARIABLES // - -var hasUint8Arrays = hasUint8ArraySupport(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment supports `Uint8Array`, the export is an alias for `Uint8Array`', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint8array-support': isTrue, - './main.js': Mock - }); - t.strictEqual( Foo, Mock, 'returns builtin' ); - - if ( hasUint8Arrays ) { - t.strictEqual( ctor, Uint8Array, 'is alias' ); // eslint-disable-line stdlib/require-globals - } - - t.end(); - - function Mock() { - return this; - } - - function isTrue() { - return true; - } -}); - -tape( 'if an environment does not support `Uint8Array`, the export is a polyfill', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint8array-support': isFalse - }); - - t.strictEqual( Foo, polyfill, 'returns polyfill' ); - t.end(); - - function isFalse() { - return false; - } -}); diff --git a/uint8/test/test.polyfill.js b/uint8/test/test.polyfill.js deleted file mode 100644 index 9d6fcb19..00000000 --- a/uint8/test/test.polyfill.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'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib/polyfill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error when invoked', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var f = new ctor(); // eslint-disable-line no-unused-vars - } -}); - -// TODO: tests diff --git a/uint8c/README.md b/uint8c/README.md deleted file mode 100644 index 3fe658da..00000000 --- a/uint8c/README.md +++ /dev/null @@ -1,1473 +0,0 @@ - - -# Uint8ClampedArray - -> [Typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); -``` - -#### Uint8ClampedArray() - -A [typed array][mdn-typed-array] constructor which returns a [typed array][mdn-typed-array] representing an array of 8-bit unsigned integers in the platform byte order clamped to `0-255`. - - - -```javascript -var arr = new Uint8ClampedArray(); -// returns -``` - -#### Uint8ClampedArray( length ) - -Returns a [typed array][mdn-typed-array] having a specified length. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -#### Uint8ClampedArray( typedarray ) - -Creates a [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var arr1 = new Float32Array( [ 5.0, 5.0, 5.0 ] ); -var arr2 = new Uint8ClampedArray( arr1 ); -// returns [ 5, 5, 5 ] -``` - -#### Uint8ClampedArray( obj ) - -Creates a [typed array][mdn-typed-array] from an array-like `object` or iterable. - - - -```javascript -var arr = new Uint8ClampedArray( [ 5.0, 5.0, 5.0 ] ); -// returns [ 5, 5, 5 ] -``` - -#### Uint8ClampedArray( buffer\[, byteOffset\[, length]] ) - -Returns a [typed array][mdn-typed-array] view of an [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var ArrayBuffer = require( '@stdlib/array/buffer' ); - -var buf = new ArrayBuffer( 4 ); -var arr = new Uint8ClampedArray( buf, 0, 4 ); -// returns [ 0, 0, 0, 0 ] -``` - -* * * - -### Properties - - - -#### Uint8ClampedArray.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var nbytes = Uint8ClampedArray.BYTES_PER_ELEMENT; -// returns 1 -``` - - - -#### Uint8ClampedArray.name - -[Typed array][mdn-typed-array] constructor name. - - - -```javascript -var str = Uint8ClampedArray.name; -// returns 'Uint8ClampedArray' -``` - - - -#### Uint8ClampedArray.prototype.buffer - -**Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -var buf = arr.buffer; -// returns -``` - - - -#### Uint8ClampedArray.prototype.byteLength - -**Read-only** property which returns the length (in bytes) of the [typed array][mdn-typed-array]. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -var byteLength = arr.byteLength; -// returns 5 -``` - - - -#### Uint8ClampedArray.prototype.byteOffset - -**Read-only** property which returns the offset (in bytes) of the [typed array][mdn-typed-array] from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -var byteOffset = arr.byteOffset; -// returns 0 -``` - - - -#### Uint8ClampedArray.prototype.BYTES_PER_ELEMENT - -Number of bytes per view element. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -var nbytes = arr.BYTES_PER_ELEMENT; -// returns 1 -``` - - - -#### Uint8ClampedArray.prototype.length - -**Read-only** property which returns the number of view elements. - - - -```javascript -var arr = new Uint8ClampedArray( 5 ); -var len = arr.length; -// returns 5 -``` - -* * * - -### Methods - - - -#### Uint8ClampedArray.from( src\[, map\[, thisArg]] ) - -Creates a new typed array from an array-like `object` or an iterable. - -```javascript -var arr = Uint8ClampedArray.from( [ 1, 2 ] ); -// returns [ 1, 2 ] -``` - -To invoke a function for each `src` value, provide a callback function. - -```javascript -function mapFcn( v ) { - return v * 2; -} - -var arr = Uint8ClampedArray.from( [ 1, 2 ], mapFcn ); -// returns [ 2, 4 ] -``` - -A callback function is provided two arguments: - -- `value`: source value -- `index`: source index - -To set the callback execution context, provide a `thisArg`. - -```javascript -function mapFcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr = Uint8ClampedArray.from( [ 1, 2 ], mapFcn, ctx ); -// returns [ 2, 4 ] - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8ClampedArray.of( element0\[, element1\[, ...elementN]] ) - -Creates a new typed array from a variable number of arguments. - -```javascript -var arr = Uint8ClampedArray.of( 1, 2 ); -// returns [ 1, 2 ] -``` - - - -#### Uint8ClampedArray.prototype.copyWithin( target, start\[, end] ) - -Copies a sequence of elements within an array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3, 4, 5 ] ); - -// Copy the last two elements to the first two elements: -arr.copyWithin( 0, 3 ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( 3, 0, 2 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - -When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3, 4, 5 ] ); - -// Copy the first two elements to the last two elements: -arr.copyWithin( -2, -5, -3 ); - -var v = arr[ 3 ]; -// returns 1 - -v = arr[ 4 ]; -// returns 2 -``` - - - -#### Uint8ClampedArray.prototype.entries() - -Returns an iterator for iterating over array key-value pairs. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.entries(); - -// Iterate over key-value pairs... -var v = it.next().value; -// returns [ 0, 1 ] - -v = it.next().value; -// returns [ 1, 2 ] - -var bool = it.next().done; -// returns true -``` - - - -#### Uint8ClampedArray.prototype.every( predicate\[, thisArg] ) - -Tests whether all array elements pass a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v <= 1 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -var bool = arr.every( predicate ); -// returns false -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 1 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -var bool = arr.every( predicate, ctx ); -// returns true - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8ClampedArray.prototype.fill( value\[, start\[, end]] ) - -Fills an array from a `start` index to an `end` index (non-inclusive) with a provided `value`. - - - -```javascript -var arr = new Uint8ClampedArray( 2 ); - -// Set all array elements to the same value: -arr.fill( 2 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 2 - -// Set all array elements starting from the first index to the same value: -arr.fill( 3, 1 ); - -v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 3 - -// Set all array elements, except the last element, to the same value: -arr.fill( 4, 0, arr.length-1 ); - -v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 3 -``` - -When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr = new Uint8ClampedArray( 2 ); - -// Set all array elements, except the last element, to the same value: -arr.fill( 2, -arr.length, -1 ); - -var v = arr[ 0 ]; -// returns 2 - -v = arr[ 1 ]; -// returns 0 -``` - - - -#### Uint8ClampedArray.prototype.filter( predicate\[, thisArg] ) - -Creates a new array (of the same data type as the host array) which includes those elements for which a `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [ 2, 3 ] -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns an empty array. - - - -```javascript -function predicate( v ) { - return ( v >= 10 ); -} - -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate ); -// returns [] -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.filter( predicate, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8ClampedArray.prototype.find( predicate\[, thisArg] ) - -Returns the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v > 2 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns 3 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `undefined`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var v = arr.find( predicate ); -// returns undefined -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v > 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var v = arr.find( predicate, ctx ); -// returns 3 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8ClampedArray.prototype.findIndex( predicate\[, thisArg] ) - -Returns the index of the first array element for which a provided `predicate` function returns a truthy value. - - - -```javascript -function predicate( v ) { - return ( v >= 3 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns 2 -``` - -If a `predicate` function does not return a truthy value for any array element, the method returns `-1`. - - - -```javascript -function predicate( v ) { - return ( v < 1 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate ); -// returns -1 -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 3 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.findIndex( predicate, ctx ); -// returns 2 - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8ClampedArray.prototype.forEach( fcn\[, thisArg] ) - -Invokes a callback for each array element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var str = ''; - -function fcn( v, i ) { - str += i + ':' + v; - if ( i < arr.length-1 ) { - str += ' '; - } -} - -arr.forEach( fcn ); - -console.log( str ); -// => '0:1 1:2 2:3' -``` - -The callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn() { - this.count += 1; -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -arr.forEach( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8ClampedArray.prototype.includes( searchElement\[, fromIndex] ) - -Returns a `boolean` indicating whether an array includes a search element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var bool = arr.includes( 3 ); -// returns true - -bool = arr.includes( 0 ); -// returns false -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, 1 ); -// returns false -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var bool = arr.includes( 1, -2 ); -// returns false -``` - - - -#### Uint8ClampedArray.prototype.indexOf( searchElement\[, fromIndex] ) - -Returns the index of the first array element strictly equal to a search element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 3 ); -// returns 2 - -idx = arr.indexOf( 0 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = 0`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, 1 ); -// returns -1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var idx = arr.indexOf( 1, -2 ); -// returns -1 -``` - - - -#### Uint8ClampedArray.prototype.join( \[separator] ) - -Serializes an array by joining all array elements as a string. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var str = arr.join(); -// returns '1,2,3' -``` - -By default, the method delineates array elements using a comma `,`. To specify a custom separator, provide a `separator` string. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var str = arr.join( '|' ); -// returns '1|2|3' -``` - - - -#### Uint8ClampedArray.prototype.keys() - -Returns an iterator for iterating over array keys. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.keys(); - -// Iterate over keys... -var v = it.next().value; -// returns 0 - -v = it.next().value; -// returns 1 - -var bool = it.next().done; -// returns true -``` - - - -#### Uint8ClampedArray.prototype.lastIndexOf( searchElement\[, fromIndex] ) - -Returns the index of the last array element strictly equal to a search element, iterating from right to left. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0 ); -// returns 3 - -idx = arr.lastIndexOf( 3 ); -// returns -1 -``` - -By default, the method searches the entire array (`fromIndex = -1`). To begin searching from a specific array index, provide a `fromIndex`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, 2 ); -// returns 1 -``` - -When a `fromIndex` is negative, the starting index is resolved relative to the last array element. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 0, 2, 0, 1 ] ); - -var idx = arr.lastIndexOf( 0, -3 ); -// returns 1 -``` - - - -#### Uint8ClampedArray.prototype.map( fcn\[, thisArg] ) - -Maps each array element to an element in a new array having the same data type as the host array. - - - -```javascript -function fcn( v ) { - return v * 2; -} - -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn ); -// returns [ 2, 4, 6 ] -``` - -A callback is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function fcn( v ) { - this.count += 1; - return v * 2; -} - -var ctx = { - 'count': 0 -}; - -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.map( fcn, ctx ); - -var n = ctx.count; -// returns 3 -``` - - - -#### Uint8ClampedArray.prototype.reduce( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8ClampedArray( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn ); -// returns 12 -``` - -If not provided an initial value, the method invokes a provided function with the first array element as the first argument and the second array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8ClampedArray( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint8ClampedArray.prototype.reduceRight( fcn\[, initialValue] ) - -Applies a function against an accumulator and each element in an array and returns the accumulated result, iterating from right to left. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8ClampedArray( [ 2, 1, 3 ] ); - -var v = arr.reduceRight( fcn ); -// returns 8 -``` - -If not provided an initial value, the method invokes a provided function with the last array element as the first argument and the second-to-last array element as the second argument. - -If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last array element as the second argument. - - - -```javascript -function fcn( acc, v ) { - return acc + ( v*v ); -} - -var arr = new Uint8ClampedArray( [ 2, 1, 3 ] ); - -var v = arr.reduce( fcn, 0 ); -// returns 14 -``` - -A callback is provided four arguments: - -- `acc`: accumulated result -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - - - -#### Uint8ClampedArray.prototype.reverse() - -Reverses an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint8ClampedArray( [ 2, 0, 3 ] ); - -// Reverse the array: -arr.reverse(); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 0 - -v = arr[ 2 ]; -// returns 2 -``` - - - -#### Uint8ClampedArray.prototype.set( arr\[, offset] ) - -Sets array elements. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the first two array elements: -arr.set( [ 4, 5 ] ); - -var v = arr[ 0 ]; -// returns 4 - -v = arr[ 1 ]; -// returns 5 -``` - -By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); -// returns [ 1, 2, 3 ] - -// Set the last two array elements: -arr.set( [ 4, 5 ], 1 ); - -var v = arr[ 1 ]; -// returns 4 - -v = arr[ 2 ]; -// returns 5 -``` - - - -#### Uint8ClampedArray.prototype.slice( \[begin\[, end]] ) - -Copies array elements to a new array with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice(); - -var bool = ( arr1 === arr2 ); -// returns false - -bool = ( arr1.buffer === arr2.buffer ); -// returns false - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 - -v = arr2[ 2 ]; -// returns 3 -``` - -By default, the method copies elements beginning with the first array element. To specify an alternative array index at which to begin copying, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 2 - -v = arr2[ 1 ]; -// returns 3 -``` - -By default, the method copies all array elements after `begin`. To specify an alternative array index at which to end copying, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( 0, 2 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.slice( -arr1.length, -1 ); - -var len = arr2.length; -// returns 2 - -var v = arr2[ 0 ]; -// returns 1 - -v = arr2[ 1 ]; -// returns 2 -``` - - - -#### Uint8ClampedArray.prototype.some( predicate\[, thisArg] ) - -Tests whether at least one array element passes a test implemented by a `predicate` function. - - - -```javascript -function predicate( v ) { - return ( v >= 2 ); -} - -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -var bool = arr.some( predicate ); -// returns true -``` - -A `predicate` function is provided three arguments: - -- `value`: array element -- `index`: array index -- `arr`: array on which the method is invoked - -To set the callback execution context, provide a `thisArg`. - - - -```javascript -function predicate( v ) { - this.count += 1; - return ( v >= 2 ); -} - -var ctx = { - 'count': 0 -}; - -var arr = new Uint8ClampedArray( [ 1, 1 ] ); - -var bool = arr.some( predicate, ctx ); -// returns false - -var n = ctx.count; -// returns 2 -``` - - - -#### Uint8ClampedArray.prototype.sort( \[compareFunction] ) - -Sorts an array **in-place** (thus mutating the array on which the method is invoked). - - - -```javascript -var arr = new Uint8ClampedArray( [ 2, 3, 0 ] ); - -// Sort the array (in ascending order): -arr.sort(); - -var v = arr[ 0 ]; -// returns 0 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 3 -``` - -By default, the method sorts array elements in ascending order. To impose a custom order, provide a `compareFunction`. - - - -```javascript -function descending( a, b ) { - return b - a; -} - -var arr = new Uint8ClampedArray( [ 2, 3, 0 ] ); - -// Sort the array (in descending order): -arr.sort( descending ); - -var v = arr[ 0 ]; -// returns 3 - -v = arr[ 1 ]; -// returns 2 - -v = arr[ 2 ]; -// returns 0 -``` - -The comparison function is provided two array elements, `a` and `b`, per invocation, and its return value determines the sort order as follows: - -- If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`). -- If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`). -- If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged. - - - -#### Uint8ClampedArray.prototype.subarray( \[begin\[, end]] ) - -Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray(); -// returns [ 1, 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 1 ); -// returns [ 2, 3 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 0, 2 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -When a `begin` and/or `end` index is negative, the respective index is determined relative to the last array element. - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( -arr1.length, -1 ); -// returns [ 1, 2 ] - -var bool = ( arr1.buffer === arr2.buffer ); -// returns true -``` - -If the method is unable to resolve indices to a non-empty array subsequence, the method returns an empty typed array. - - - -```javascript -var arr1 = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var arr2 = arr1.subarray( 10, -1 ); -// returns [] -``` - - - -#### Uint8ClampedArray.prototype.toLocaleString( \[locales\[, options]] ) - -Serializes an array as a locale-specific `string`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var str = arr.toLocaleString(); -// returns '1,2,3' -``` - - - -#### Uint8ClampedArray.prototype.toString() - -Serializes an array as a `string`. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2, 3 ] ); - -var str = arr.toString(); -// returns '1,2,3' -``` - - - -#### Uint8ClampedArray.prototype.values() - -Returns an iterator for iterating over array elements. - - - -```javascript -var arr = new Uint8ClampedArray( [ 1, 2 ] ); - -// Create an iterator: -var it = arr.values(); - -// Iterate over array elements... -var v = it.next().value; -// returns 1 - -v = it.next().value; -// returns 2 - -var bool = it.next().done; -// returns true -``` - -
- - - -* * * - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var ctor = require( '@stdlib/array/uint8c' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/uint8c/benchmark/benchmark.copy_within.js b/uint8c/benchmark/benchmark.copy_within.js deleted file mode 100644 index e2731bd2..00000000 --- a/uint8c/benchmark/benchmark.copy_within.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':copyWithin', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.copy_within.length.js b/uint8c/benchmark/benchmark.copy_within.length.js deleted file mode 100644 index bd70626c..00000000 --- a/uint8c/benchmark/benchmark.copy_within.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr[ 0 ] = v; - arr = arr.copyWithin( 1, 0 ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':copyWithin:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.data.js b/uint8c/benchmark/benchmark.data.js deleted file mode 100644 index 5cbb9007..00000000 --- a/uint8c/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get,index', function benchmark( b ) { - var arr; - var N; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr[ i%N ]; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::set,index', function benchmark( b ) { - var arr; - var N; - var i; - - arr = new Uint8ClampedArray( 2 ); - N = arr.length; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%N ] = i; - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] || arr[ 1 ] !== arr[ 1 ] ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.entries.js b/uint8c/benchmark/benchmark.entries.js deleted file mode 100644 index 0b2af25f..00000000 --- a/uint8c/benchmark/benchmark.entries.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':entries', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8ClampedArray( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.entries(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.every.js b/uint8c/benchmark/benchmark.every.js deleted file mode 100644 index c2dea91d..00000000 --- a/uint8c/benchmark/benchmark.every.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:every', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint8c/benchmark/benchmark.every.length.js b/uint8c/benchmark/benchmark.every.length.js deleted file mode 100644 index 0ec67464..00000000 --- a/uint8c/benchmark/benchmark.every.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.every( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':every:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.fill.js b/uint8c/benchmark/benchmark.fill.js deleted file mode 100644 index d9810959..00000000 --- a/uint8c/benchmark/benchmark.fill.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':fill', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.fill.length.js b/uint8c/benchmark/benchmark.fill.length.js deleted file mode 100644 index 60c5757a..00000000 --- a/uint8c/benchmark/benchmark.fill.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i % 128; - arr = arr.fill( v ); - if ( arr[ 0 ] !== v ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( arr[ 0 ] !== arr[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':fill:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.filter.js b/uint8c/benchmark/benchmark.filter.js deleted file mode 100644 index e1c52ee7..00000000 --- a/uint8c/benchmark/benchmark.filter.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); - -bench( pkg+'::this_context:filter', function benchmark( b ) { - var arr; - var out; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v >= 0; - } -}); diff --git a/uint8c/benchmark/benchmark.filter.length.js b/uint8c/benchmark/benchmark.filter.length.js deleted file mode 100644 index dffa04ec..00000000 --- a/uint8c/benchmark/benchmark.filter.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value >= 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.filter( predicate ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':filter:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.find.js b/uint8c/benchmark/benchmark.find.js deleted file mode 100644 index d1f8b343..00000000 --- a/uint8c/benchmark/benchmark.find.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:find', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate, {} ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8c/benchmark/benchmark.find.length.js b/uint8c/benchmark/benchmark.find.length.js deleted file mode 100644 index bbdca594..00000000 --- a/uint8c/benchmark/benchmark.find.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - tuple length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.find( predicate ); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof out !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':find:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.find_index.js b/uint8c/benchmark/benchmark.find_index.js deleted file mode 100644 index 439909a4..00000000 --- a/uint8c/benchmark/benchmark.find_index.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:findIndex', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate, {} ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8c/benchmark/benchmark.find_index.length.js b/uint8c/benchmark/benchmark.find_index.length.js deleted file mode 100644 index 5aadd9b1..00000000 --- a/uint8c/benchmark/benchmark.find_index.length.js +++ /dev/null @@ -1,104 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.findIndex( predicate ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':findIndex:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.for_each.js b/uint8c/benchmark/benchmark.for_each.js deleted file mode 100644 index 0666c43c..00000000 --- a/uint8c/benchmark/benchmark.for_each.js +++ /dev/null @@ -1,88 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint8ClampedArray( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); - -bench( pkg+'::this_context:forEach', function benchmark( b ) { - var count; - var arr; - var N; - var i; - - arr = new Uint8ClampedArray( 2 ); - N = arr.length; - - count = 0; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn, {} ); - if ( count !== N*(i+1) ) { - b.fail( 'unexpected result' ); - } - } - b.toc(); - if ( count !== N*i ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn() { - count += 1; - } -}); diff --git a/uint8c/benchmark/benchmark.for_each.length.js b/uint8c/benchmark/benchmark.for_each.length.js deleted file mode 100644 index e24aed6a..00000000 --- a/uint8c/benchmark/benchmark.for_each.length.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var count; - var arr; - - arr = new Uint8ClampedArray( len ); - count = 0; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr.forEach( fcn ); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( count !== count ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } - - /** - * Callback invoked for each tuple element. - * - * @private - */ - function fcn() { - count += 1; - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':forEach:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.from.js b/uint8c/benchmark/benchmark.from.js deleted file mode 100644 index 9ed431a3..00000000 --- a/uint8c/benchmark/benchmark.from.js +++ /dev/null @@ -1,237 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': ( ITERATOR_SYMBOL === null ) -}; - - -// MAIN // - -bench( pkg+'::typed_array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint8ClampedArray( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = new Uint8ClampedArray( [ 1, 2 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::array:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( buf ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::array,clbk:from', function benchmark( b ) { - var buf; - var arr; - var i; - - buf = [ 1, 2 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( buf, clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function clbk( v ) { - return v + 1; - } -}); - -bench( pkg+'::iterable:from', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( createIterable() ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 0, - 'done': false - }; - } - return { - 'done': true - }; - } - } -}); - -bench( pkg+'::iterable,clbk:from:', opts, function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.from( createIterable(), clbk ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function createIterable() { - var out; - var i; - - out = {}; - out[ ITERATOR_SYMBOL ] = iterator; - - i = 0; - - return out; - - function iterator() { - return { - 'next': next - }; - } - - function next() { - i += 1; - if ( i <= 2 ) { - return { - 'value': 1, - 'done': false - }; - } - return { - 'done': true - }; - } - } - - function clbk( v ) { - return v + 1; - } -}); diff --git a/uint8c/benchmark/benchmark.includes.js b/uint8c/benchmark/benchmark.includes.js deleted file mode 100644 index b709e50c..00000000 --- a/uint8c/benchmark/benchmark.includes.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':includes', function benchmark( b ) { - var bool; - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.includes.length.js b/uint8c/benchmark/benchmark.includes.length.js deleted file mode 100644 index d6ff5c71..00000000 --- a/uint8c/benchmark/benchmark.includes.length.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - bool = arr.includes( v ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':includes:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.index_of.js b/uint8c/benchmark/benchmark.index_of.js deleted file mode 100644 index 8cb37832..00000000 --- a/uint8c/benchmark/benchmark.index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':indexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.index_of.length.js b/uint8c/benchmark/benchmark.index_of.length.js deleted file mode 100644 index 9b55a7f8..00000000 --- a/uint8c/benchmark/benchmark.index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.indexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':indexOf:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.join.js b/uint8c/benchmark/benchmark.join.js deleted file mode 100644 index ee4ac625..00000000 --- a/uint8c/benchmark/benchmark.join.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':join', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.join.length.js b/uint8c/benchmark/benchmark.join.length.js deleted file mode 100644 index 7b7c9d89..00000000 --- a/uint8c/benchmark/benchmark.join.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i % 127; - out = arr.join(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':join:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.js b/uint8c/benchmark/benchmark.js deleted file mode 100644 index 19af7aad..00000000 --- a/uint8c/benchmark/benchmark.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.keys.js b/uint8c/benchmark/benchmark.keys.js deleted file mode 100644 index 9f472e0b..00000000 --- a/uint8c/benchmark/benchmark.keys.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':keys', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.keys(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.last_index_of.js b/uint8c/benchmark/benchmark.last_index_of.js deleted file mode 100644 index 97746402..00000000 --- a/uint8c/benchmark/benchmark.last_index_of.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':lastIndexOf', function benchmark( b ) { - var out; - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - // Benchmark worst case scenario... - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.last_index_of.length.js b/uint8c/benchmark/benchmark.last_index_of.length.js deleted file mode 100644 index e509fd02..00000000 --- a/uint8c/benchmark/benchmark.last_index_of.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = (i%127) + 1; - out = arr.lastIndexOf( v ); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - } - b.toc(); - if ( out !== -1 ) { - b.fail( 'should return -1' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':lastIndexOf:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.length.js b/uint8c/benchmark/benchmark.length.js deleted file mode 100644 index faf73d88..00000000 --- a/uint8c/benchmark/benchmark.length.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var ctor = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = new ctor( len ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.map.js b/uint8c/benchmark/benchmark.map.js deleted file mode 100644 index a28681c8..00000000 --- a/uint8c/benchmark/benchmark.map.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); - -bench( pkg+'::this_context:map', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn, {} ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8c/benchmark/benchmark.map.length.js b/uint8c/benchmark/benchmark.map.length.js deleted file mode 100644 index 40011ea5..00000000 --- a/uint8c/benchmark/benchmark.map.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Maps an array element to a new value. -* -* @private -* @param {*} value - array element -* @returns {*} new value -*/ -function fcn( value ) { - return value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.map( fcn ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':map:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.of.js b/uint8c/benchmark/benchmark.of.js deleted file mode 100644 index 41b32ac8..00000000 --- a/uint8c/benchmark/benchmark.of.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':of', function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = Uint8ClampedArray.of( i, 2 ); - if ( arr.length !== 2 ) { - b.fail( 'should have length 2' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( arr ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.properties.js b/uint8c/benchmark/benchmark.properties.js deleted file mode 100644 index ca8f308c..00000000 --- a/uint8c/benchmark/benchmark.properties.js +++ /dev/null @@ -1,145 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::get:buffer', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.buffer; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArrayBuffer( v ) ) { - b.fail( 'should return an ArrayBuffer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteLength', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteLength; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteOffset', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.byteOffset; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.BYTES_PER_ELEMENT; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:length', function benchmark( b ) { - var arr; - var v; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - // Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless... - v = arr.length; - if ( v !== v ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isNonNegativeInteger( v ) ) { - b.fail( 'should return a nonnegative integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.reduce.js b/uint8c/benchmark/benchmark.reduce.js deleted file mode 100644 index b28a5ddb..00000000 --- a/uint8c/benchmark/benchmark.reduce.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduce', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8c/benchmark/benchmark.reduce.length.js b/uint8c/benchmark/benchmark.reduce.length.js deleted file mode 100644 index eb3e2e50..00000000 --- a/uint8c/benchmark/benchmark.reduce.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduce( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduce:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.reduce_right.js b/uint8c/benchmark/benchmark.reduce_right.js deleted file mode 100644 index 0e2cefa2..00000000 --- a/uint8c/benchmark/benchmark.reduce_right.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'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( acc, v ) { - return acc + v + 1; - } -}); - -bench( pkg+'::initial_value:reduceRight', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn, 3 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function fcn( v ) { - return v + 1; - } -}); diff --git a/uint8c/benchmark/benchmark.reduce_right.length.js b/uint8c/benchmark/benchmark.reduce_right.length.js deleted file mode 100644 index cd48ec9e..00000000 --- a/uint8c/benchmark/benchmark.reduce_right.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Updates an accumulated value. -* -* @private -* @param {*} acc - accumulated value -* @param {*} value - array element -* @returns {*} accumulated value -*/ -function fcn( acc, value ) { - return acc + value + 1; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.reduceRight( fcn ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reduceRight:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.reverse.js b/uint8c/benchmark/benchmark.reverse.js deleted file mode 100644 index 17e6ec0e..00000000 --- a/uint8c/benchmark/benchmark.reverse.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':reverse', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.reverse.length.js b/uint8c/benchmark/benchmark.reverse.length.js deleted file mode 100644 index 6e77be0c..00000000 --- a/uint8c/benchmark/benchmark.reverse.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.reverse(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':reverse:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.set.js b/uint8c/benchmark/benchmark.set.js deleted file mode 100644 index f4076722..00000000 --- a/uint8c/benchmark/benchmark.set.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = []; - for ( i = 0; i < 10; i++ ) { - values.push( i ); - } - N = values.length; - - arr = new Uint8ClampedArray( 2 ); - buf = [ 0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::typed_array:set', function benchmark( b ) { - var values; - var buf; - var arr; - var N; - var v; - var i; - - values = new Uint8ClampedArray( 20 ); - N = values.length; - for ( i = 0; i < N; i++ ) { - values[ i ] = i; - } - - arr = new Uint8ClampedArray( 2 ); - buf = new Uint8ClampedArray( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buf[ 0 ] = values[ i%N ]; - v = arr.set( buf ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.set.length.js b/uint8c/benchmark/benchmark.set.length.js deleted file mode 100644 index 8aa89388..00000000 --- a/uint8c/benchmark/benchmark.set.length.js +++ /dev/null @@ -1,114 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var values; - var arr1; - var arr2; - var arr; - var N; - var i; - - arr1 = []; - arr2 = []; - for ( i = 0; i < len; i++ ) { - arr1.push( randi() ); - arr2.push( randi() ); - } - arr = new Uint8ClampedArray( len ); - - values = [ - arr1, - arr2 - ]; - N = values.length; - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = arr.set( values[ i%N ] ); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - } - b.toc(); - if ( typeof v !== 'undefined' ) { - b.fail( 'should return undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':set:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.slice.js b/uint8c/benchmark/benchmark.slice.js deleted file mode 100644 index d1e0cda9..00000000 --- a/uint8c/benchmark/benchmark.slice.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':slice', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.slice.length.js b/uint8c/benchmark/benchmark.slice.length.js deleted file mode 100644 index 82e5f691..00000000 --- a/uint8c/benchmark/benchmark.slice.length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.slice(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':slice:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.some.js b/uint8c/benchmark/benchmark.some.js deleted file mode 100644 index ad545e25..00000000 --- a/uint8c/benchmark/benchmark.some.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); - -bench( pkg+'::this_context:some', function benchmark( b ) { - var bool; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate, {} ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function predicate( v ) { - return v > 0; - } -}); diff --git a/uint8c/benchmark/benchmark.some.length.js b/uint8c/benchmark/benchmark.some.length.js deleted file mode 100644 index 79f4623f..00000000 --- a/uint8c/benchmark/benchmark.some.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Returns a boolean indicating whether an array element passes a test. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating whether an array element passes a test -*/ -function predicate( value ) { - return value > 0; -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var bool; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = arr.some( predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':some:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.sort.js b/uint8c/benchmark/benchmark.sort.js deleted file mode 100644 index 291a1735..00000000 --- a/uint8c/benchmark/benchmark.sort.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':sort', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( [ randi(), randi() ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.sort.length.js b/uint8c/benchmark/benchmark.sort.length.js deleted file mode 100644 index cc519786..00000000 --- a/uint8c/benchmark/benchmark.sort.length.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var randi = require( '@stdlib/random/base/randi' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var data; - var arr; - var i; - - data = []; - for ( i = 0; i < len; i++ ) { - data.push( randi() ); - } - arr = new Uint8ClampedArray( data ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ i%len ] = randi(); - out = arr.sort(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':sort:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.subarray.js b/uint8c/benchmark/benchmark.subarray.js deleted file mode 100644 index 6fac854f..00000000 --- a/uint8c/benchmark/benchmark.subarray.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':subarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.subarray.length.js b/uint8c/benchmark/benchmark.subarray.length.js deleted file mode 100644 index 70c5d0c4..00000000 --- a/uint8c/benchmark/benchmark.subarray.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isUint8ClampedArray = require( '@stdlib/assert/is-uint8clampedarray' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arr.subarray(); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isUint8ClampedArray( out ) ) { - b.fail( 'should return a Uint8ClampedArray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':subarray:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.to_locale_string.js b/uint8c/benchmark/benchmark.to_locale_string.js deleted file mode 100644 index d214048e..00000000 --- a/uint8c/benchmark/benchmark.to_locale_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toLocaleString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.to_locale_string.length.js b/uint8c/benchmark/benchmark.to_locale_string.length.js deleted file mode 100644 index 0963f1db..00000000 --- a/uint8c/benchmark/benchmark.to_locale_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toLocaleString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toLocaleString:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.to_string.js b/uint8c/benchmark/benchmark.to_string.js deleted file mode 100644 index 0eb5fa46..00000000 --- a/uint8c/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/benchmark/benchmark.to_string.length.js b/uint8c/benchmark/benchmark.to_string.length.js deleted file mode 100644 index d0eaa01f..00000000 --- a/uint8c/benchmark/benchmark.to_string.length.js +++ /dev/null @@ -1,94 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var arr = new Uint8ClampedArray( len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 0 ] = i; - out = arr.toString(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 5; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':toString:len='+len, f ); - } -} - -main(); diff --git a/uint8c/benchmark/benchmark.values.js b/uint8c/benchmark/benchmark.values.js deleted file mode 100644 index 64345b08..00000000 --- a/uint8c/benchmark/benchmark.values.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pkg = require( './../package.json' ).name; -var Uint8ClampedArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':values', function benchmark( b ) { - var iter; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = arr.values(); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof iter !== 'object' || typeof iter.next !== 'function' ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/uint8c/docs/repl.txt b/uint8c/docs/repl.txt deleted file mode 100644 index 461c9fb8..00000000 --- a/uint8c/docs/repl.txt +++ /dev/null @@ -1,953 +0,0 @@ - -{{alias}}() - A typed array constructor which returns a typed array representing an array - of 8-bit unsigned integers in the platform byte order clamped to 0-255. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr = new {{alias}}() - - - -{{alias}}( length ) - Returns a typed array having a specified length. - - Parameters - ---------- - length: integer - Typed array length. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}( typedarray ) - Creates a typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr1 = new {{alias:@stdlib/array/int32}}( [ 5, 5, 5 ] ); - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( obj ) - Creates a typed array from an array-like object or iterable. - - Parameters - ---------- - obj: Object - Array-like object or iterable from which to generate a typed array. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr1 = [ 5.0, 5.0, 5.0 ]; - > var arr2 = new {{alias}}( arr1 ) - [ 5, 5, 5 ] - - -{{alias}}( buffer[, byteOffset[, length]] ) - Returns a typed array view of an ArrayBuffer. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 4 ); - > var arr = new {{alias}}( buf, 0, 4 ) - [ 0, 0, 0, 0 ] - - -{{alias}}.from( src[, map[, thisArg]] ) - Creates a new typed array from an array-like object or an iterable. - - A callback is provided the following arguments: - - - value: source value. - - index: source index. - - Parameters - ---------- - src: ArrayLike|Iterable - Source of array elements. - - map: Function (optional) - Callback to invoke for each source element. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > function mapFcn( v ) { return v * 2; }; - > var arr = {{alias}}.from( [ 1, 2 ], mapFcn ) - [ 2, 4 ] - - -{{alias}}.of( element0[, element1[, ...elementN]] ) - Creates a new typed array from a variable number of arguments. - - Parameters - ---------- - element0: number - Array element. - - element1: number (optional) - Array element. - - elementN: ...number (optional) - Array elements. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr = {{alias}}.of( 1, 2 ) - [ 1, 2 ] - - -{{alias}}.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > {{alias}}.BYTES_PER_ELEMENT - 1 - - -{{alias}}.name - Typed array constructor name. - - Examples - -------- - > {{alias}}.name - 'Uint8ClampedArray' - - -{{alias}}.prototype.buffer - Read-only property which returns the ArrayBuffer referenced by the typed - array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.buffer - - - -{{alias}}.prototype.byteLength - Read-only property which returns the length (in bytes) of the typed array. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteLength - 5 - - -{{alias}}.prototype.byteOffset - Read-only property which returns the offset (in bytes) of the typed array - from the start of its ArrayBuffer. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.byteOffset - 0 - - -{{alias}}.prototype.BYTES_PER_ELEMENT - Number of bytes per view element. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.BYTES_PER_ELEMENT - 1 - - -{{alias}}.prototype.length - Read-only property which returns the number of view elements. - - Examples - -------- - > var arr = new {{alias}}( 5 ); - > arr.length - 5 - - -{{alias}}.prototype.copyWithin( target, start[, end] ) - Copies a sequence of elements within the array starting at `start` and - ending at `end` (non-inclusive) to the position starting at `target`. - - Parameters - ---------- - target: integer - Target start index position. - - start: integer - Source start index position. - - end: integer (optional) - Source end index position. Default: out.length. - - Returns - ------- - out: Uint8ClampedArray - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > arr.copyWithin( 3, 0, 2 ); - > arr[ 3 ] - 1 - > arr[ 4 ] - 2 - - -{{alias}}.prototype.entries() - Returns an iterator for iterating over array key-value pairs. - - Returns - ------- - iter: Iterator - Iterator for iterating over array key-value pairs. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.entries(); - > it.next().value - [ 0, 1 ] - > it.next().value - [ 1, 2 ] - > it.next().done - true - - -{{alias}}.prototype.every( predicate[, thisArg] ) - Tests whether all array elements pass a test implemented by a predicate - function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, an array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether all array elements pass. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v <= 1 ); }; - > arr.every( predicate ) - false - - -{{alias}}.prototype.fill( value[, start[, end]] ) - Fills an array from a start index to an end index (non-inclusive) with a - provided value. - - Parameters - ---------- - value: number - Fill value. - - start: integer (optional) - Start index. If less than zero, the start index is resolved relative to - the last array element. Default: 0. - - end: integer (optional) - End index (non-inclusive). If less than zero, the end index is resolved - relative to the last array element. Default: out.length. - - Returns - ------- - out: Uint8ClampedArray - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > arr.fill( 3 ); - > arr[ 0 ] - 3 - > arr[ 1 ] - 3 - - -{{alias}}.prototype.filter( predicate[, thisArg] ) - Creates a new array which includes those elements for which a predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - If a predicate function does not return a truthy value for any array - element, the method returns `null`. - - Parameters - ---------- - predicate: Function - Predicate function which filters array elements. If a predicate function - returns a truthy value, an array element is included in the output - array; otherwise, an array element is not included in the output array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > var arr2 = arr1.filter( predicate ); - > arr2.length - 2 - - -{{alias}}.prototype.find( predicate[, thisArg] ) - Returns the first array element for which a provided predicate function - returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `undefined`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - value: number|undefined - Array element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var v = arr.find( predicate ) - 3 - - -{{alias}}.prototype.findIndex( predicate[, thisArg] ) - Returns the index of the first array element for which a provided predicate - function returns a truthy value. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - If a predicate function never returns a truthy value, the method returns - `-1`. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function predicate( v ) { return ( v > 2 ); }; - > var idx = arr.findIndex( predicate ) - 2 - - -{{alias}}.prototype.forEach( fcn[, thisArg] ) - Invokes a callback for each array element. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - fcn: Function - Function to invoke for each array element. - - thisArg: Any (optional) - Callback execution context. - - Examples - -------- - > var arr = new {{alias}}( [ 3, 2, 1 ] ); - > var str = ' '; - > function fcn( v, i ) { str += i + ':' + v + ' '; }; - > arr.forEach( fcn ); - > str - ' 0:3 1:2 2:1 ' - - -{{alias}}.prototype.includes( searchElement[, fromIndex] ) - Returns a boolean indicating whether an array includes a search element. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - bool: boolean - Boolean indicating whether an array includes a search element. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var bool = arr.includes( 4 ) - false - > bool = arr.includes( 3 ) - true - - -{{alias}}.prototype.indexOf( searchElement[, fromIndex] ) - Returns the index of the first array element strictly equal to a search - element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: 0. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > var idx = arr.indexOf( 4 ) - -1 - > idx = arr.indexOf( 3 ) - 2 - - -{{alias}}.prototype.join( [separator] ) - Serializes an array by joining all array elements as a string. - - Parameters - ---------- - separator: string (optional) - String delineating array elements. Default: ','. - - Returns - ------- - str: string - Array serialized as a string. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.join( '|' ) - '1|2|3' - - -{{alias}}.prototype.keys() - Returns an iterator for iterating over array keys. - - Returns - ------- - iter: Iterator - Iterator for iterating over array keys. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.keys(); - > it.next().value - 0 - > it.next().value - 1 - > it.next().done - true - - -{{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) - Returns the index of the last array element strictly equal to a search - element. - - The method iterates from the last array element to the first array element. - - If unable to locate a search element, the method returns `-1`. - - Parameters - ---------- - searchElement: number - Search element. - - fromIndex: integer (optional) - Array index from which to begin searching. If provided a negative value, - the method resolves the start index relative to the last array element. - Default: -1. - - Returns - ------- - idx: integer - Array index. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 0, 2, 0, 1 ] ); - > var idx = arr.lastIndexOf( 3 ) - -1 - > idx = arr.lastIndexOf( 0 ) - 3 - - -{{alias}}.prototype.map( fcn[, thisArg] ) - Maps each array element to an element in a new typed array. - - A provided function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - The returned array has the same data type as the host array. - - Parameters - ---------- - fcn: Function - Function which maps array elements to elements in the new array. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( v ) { return v * 2; }; - > var arr2 = arr1.map( fcn ) - [ 2, 4, 6 ] - - -{{alias}}.prototype.reduce( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the first array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the first array element as the first argument and the second array - element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduce( fcn, 0 ) - 14 - - -{{alias}}.prototype.reduceRight( fcn[, initialValue] ) - Applies a function against an accumulator and each element in an array and - returns the accumulated result, iterating from right to left. - - The provided function is provided the following arguments: - - - acc: accumulated result. - - value: current array element. - - index: index of the current array element. - - arr: array on which the method is invoked. - - If provided an initial value, the method invokes a provided function with - the initial value as the first argument and the last array element as the - second argument. - - If not provided an initial value, the method invokes a provided function - with the last array element as the first argument and the second-to-last - array element as the second argument. - - Parameters - ---------- - fcn: Function - Function to apply. - - initialValue: Any (optional) - Initial accumulation value. - - Returns - ------- - out: Any - Accumulated result. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > function fcn( acc, v ) { return acc + (v*v); }; - > var v = arr.reduceRight( fcn, 0 ) - 14 - - -{{alias}}.prototype.reverse() - Reverses an array *in-place*. - - This method mutates the array on which the method is invoked. - - Returns - ------- - out: Uint8ClampedArray - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - - > arr.reverse() - [ 3, 2, 1 ] - - -{{alias}}.prototype.set( arr[, offset] ) - Sets array elements. - - Parameters - ---------- - arr: ArrayLike - Source array containing array values to set. - - offset: integer (optional) - Array index at which to start writing values. Default: 0. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.set( [ 4, 4 ], 1 ); - > arr[ 1 ] - 4 - > arr[ 2 ] - 4 - - -{{alias}}.prototype.slice( [begin[, end]] ) - Copies array elements to a new array with the same underlying data type as - the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns `null`. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint8ClampedArray - A typed array. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3 ] ); - > var arr2 = arr1.slice( 1 ); - > arr2.length - 2 - > arr2[ 0 ] - 2 - > arr2[ 1 ] - 3 - - -{{alias}}.prototype.some( predicate[, thisArg] ) - Tests whether at least one array element passes a test implemented by a - predicate function. - - A predicate function is provided the following arguments: - - - value: array element. - - index: array index. - - arr: array on which the method is invoked. - - Parameters - ---------- - predicate: Function - Predicate function which tests array elements. If a predicate function - returns a truthy value, a array element passes; otherwise, an array - element fails. - - thisArg: Any (optional) - Callback execution context. - - Returns - ------- - bool: boolean - Boolean indicating whether at least one array element passes. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > function predicate( v ) { return ( v > 1 ); }; - > arr.some( predicate ) - true - - -{{alias}}.prototype.sort( [compareFunction] ) - Sorts an array *in-place*. - - The comparison function is provided two array elements per invocation: `a` - and `b`. - - The comparison function return value determines the sort order as follows: - - - If the comparison function returns a value less than zero, then the method - sorts `a` to an index lower than `b` (i.e., `a` should come *before* `b`). - - - If the comparison function returns a value greater than zero, then the - method sorts `a` to an index higher than `b` (i.e., `b` should come *before* - `a`). - - - If the comparison function returns zero, then the relative order of `a` - and `b` should remain unchanged. - - This method mutates the array on which the method is invoked. - - Parameters - ---------- - compareFunction: Function (optional) - Function which specifies the sort order. The default sort order is - ascending order. - - Returns - ------- - out: Uint8ClampedArray - Modified array. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 0, 2, 1 ] ); - > arr.sort() - [ 0, 1, 1, 2, 2 ] - - -{{alias}}.prototype.subarray( [begin[, end]] ) - Creates a new typed array over the same underlying ArrayBuffer and with the - same underlying data type as the host array. - - If the method is unable to resolve indices to a non-empty array subsequence, - the method returns an empty typed array. - - Parameters - ---------- - begin: integer (optional) - Start element index (inclusive). If less than zero, the start index is - resolved relative to the last array element. Default: 0. - - end: integer (optional) - End element index (exclusive). If less than zero, the end index is - resolved relative to the last array element. Default: arr.length. - - Returns - ------- - out: Uint8ClampedArray - A new typed array view. - - Examples - -------- - > var arr1 = new {{alias}}( [ 1, 2, 3, 4, 5 ] ); - > var arr2 = arr1.subarray( 2 ) - [ 3, 4, 5 ] - - -{{alias}}.prototype.toLocaleString( [locales[, options]] ) - Serializes an array as a locale-specific string. - - Parameters - ---------- - locales: string|Array (optional) - A BCP 47 language tag, or an array of such tags. - - options: Object (optional) - Options. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toLocaleString() - '1,2,3' - - -{{alias}}.prototype.toString() - Serializes an array as a string. - - Returns - ------- - str: string - A typed array string representation. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ); - > arr.toString() - '1,2,3' - - -{{alias}}.prototype.values() - Returns an iterator for iterating over array elements. - - Returns - ------- - iter: Iterator - Iterator for iterating over array elements. - - Examples - -------- - > var arr = new {{alias}}( [ 1, 2 ] ); - > it = arr.values(); - > it.next().value - 1 - > it.next().value - 2 - > it.next().done - true - - - See Also - -------- - diff --git a/uint8c/docs/types/index.d.ts b/uint8c/docs/types/index.d.ts deleted file mode 100644 index 516251ee..00000000 --- a/uint8c/docs/types/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -// EXPORTS // - -/** -* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255. -*/ -export = Uint8ClampedArray; diff --git a/uint8c/docs/types/test.ts b/uint8c/docs/types/test.ts deleted file mode 100644 index 3a113feb..00000000 --- a/uint8c/docs/types/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 @typescript-eslint/no-unused-expressions */ - -import Uint8ClampedArray = require( './index' ); - - -// TESTS // - -// The function returns a typed array instance... -{ - new Uint8ClampedArray( 10 ); // $ExpectType Uint8ClampedArray - new Uint8ClampedArray( [ 2, 5, 5, 7 ] ); // $ExpectType Uint8ClampedArray -} - -// The constructor function has to be invoked with `new`... -{ - Uint8ClampedArray( 10 ); // $ExpectError - Uint8ClampedArray( [ 2, 5, 5, 7 ] ); // $ExpectError -} diff --git a/uint8c/examples/index.js b/uint8c/examples/index.js deleted file mode 100644 index d0978bec..00000000 --- a/uint8c/examples/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 round = require( '@stdlib/math/base/special/round' ); -var ctor = require( './../lib' ); - -var arr; -var i; - -arr = new ctor( 10 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} -console.log( arr ); diff --git a/uint8c/lib/index.js b/uint8c/lib/index.js deleted file mode 100644 index 2d7e79f2..00000000 --- a/uint8c/lib/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255. -* -* @module @stdlib/array/uint8c -* -* @example -* var ctor = require( '@stdlib/array/uint8c' ); -* -* var arr = new ctor( 10 ); -* // returns -*/ - -// MODULES // - -var hasUint8ClampedArraySupport = require( '@stdlib/assert/has-uint8clampedarray-support' ); // eslint-disable-line id-length -var builtin = require( './main.js' ); -var polyfill = require( './polyfill.js' ); - - -// MAIN // - -var ctor; -if ( hasUint8ClampedArraySupport() ) { - ctor = builtin; -} else { - ctor = polyfill; -} - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint8c/lib/main.js b/uint8c/lib/main.js deleted file mode 100644 index ea97aa45..00000000 --- a/uint8c/lib/main.js +++ /dev/null @@ -1,28 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -var ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals - - -// EXPORTS // - -module.exports = ctor; diff --git a/uint8c/lib/polyfill.js b/uint8c/lib/polyfill.js deleted file mode 100644 index 76e599e0..00000000 --- a/uint8c/lib/polyfill.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// TODO: write polyfill - -// MAIN // - -/** -* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255. -* -* @throws {Error} not implemented -*/ -function polyfill() { - throw new Error( 'not implemented' ); -} - - -// EXPORTS // - -module.exports = polyfill; diff --git a/uint8c/package.json b/uint8c/package.json deleted file mode 100644 index 1ac54931..00000000 --- a/uint8c/package.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "name": "@stdlib/array/uint8c", - "version": "0.0.0", - "description": "Uint8ClampedArray.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "array", - "typed", - "typed array", - "typed-array", - "uint8clampedarray", - "uint8clamped", - "clamped", - "uint8", - "uint8_t", - "integer", - "int", - "uint", - "unsigned", - "byte", - "octet" - ] -} diff --git a/uint8c/test/test.copy_within.js b/uint8c/test/test.copy_within.js deleted file mode 100644 index 386560bf..00000000 --- a/uint8c/test/test.copy_within.js +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasProp = require( '@stdlib/assert/has-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var Uint8ClampedArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof Uint8ClampedArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'a typed array instance has a `copyWithin` method for copying a sequence of elements within a typed array', function test( t ) { - var arr = new Uint8ClampedArray( 2 ); - t.strictEqual( hasProp( arr, 'copyWithin' ), true, 'has property' ); - t.strictEqual( isFunction( arr.copyWithin ), true, 'has method' ); - t.end(); -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0 ); - }; - } -}); - -tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance (end)', function test( t ) { - var values; - var arr; - var i; - - arr = new Uint8ClampedArray( 2 ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - return arr.copyWithin.call( value, 3, 0, 5 ); - }; - } -}); - -tape( 'the method copies a sequence of elements within a typed array', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 0, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative target)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( -p.length, 3 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 0, -2 ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (end=length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 0, 3, p.length ); - - // Overwritten: - t.strictEqual( p[ 0 ], 3, 'returns expected value' ); - t.strictEqual( p[ 1 ], 4, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (non-inclusive end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 2, 0, 2 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (negative end)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 2, 0, -3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - - // Remain the same: - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target >= length)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( p.length, 3 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - t.strictEqual( p[ 2 ], 2, 'returns expected value' ); - t.strictEqual( p[ 3 ], 3, 'returns expected value' ); - t.strictEqual( p[ 4 ], 4, 'returns expected value' ); - - t.end(); -}); - -tape( 'the method copies a sequence of elements within a typed array (target > start)', function test( t ) { - var arr; - var p; - - arr = [ - 0, - 1, - 2, - 3, - 4 - ]; - - p = new Uint8ClampedArray( arr ); - p.copyWithin( 2, 0 ); - - // Remain the same: - t.strictEqual( p[ 0 ], 0, 'returns expected value' ); - t.strictEqual( p[ 1 ], 1, 'returns expected value' ); - - // Overwritten: - t.strictEqual( p[ 2 ], 0, 'returns expected value' ); - t.strictEqual( p[ 3 ], 1, 'returns expected value' ); - t.strictEqual( p[ 4 ], 2, 'returns expected value' ); - - t.end(); -}); diff --git a/uint8c/test/test.js b/uint8c/test/test.js deleted file mode 100644 index 4da60c6c..00000000 --- a/uint8c/test/test.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'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var hasUint8ClampedArraySupport = require( '@stdlib/assert/has-uint8clampedarray-support' ); -var polyfill = require( './../lib/polyfill.js' ); -var ctor = require( './../lib' ); - - -// VARIABLES // - -var hasUint8ClampedArrays = hasUint8ClampedArraySupport(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'if an environment supports `Uint8ClampedArray`, the export is an alias for `Uint8ClampedArray`', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint8clampedarray-support': isTrue, - './main.js': Mock - }); - t.strictEqual( Foo, Mock, 'returns builtin' ); - - if ( hasUint8ClampedArrays ) { - t.strictEqual( ctor, Uint8ClampedArray, 'is alias' ); // eslint-disable-line stdlib/require-globals - } - - t.end(); - - function Mock() { - return this; - } - - function isTrue() { - return true; - } -}); - -tape( 'if an environment does not support `Uint8ClampedArray`, the export is a polyfill', function test( t ) { - var Foo; - - Foo = proxyquire( './../lib', { - '@stdlib/assert/has-uint8clampedarray-support': isFalse - }); - - t.strictEqual( Foo, polyfill, 'returns polyfill' ); - t.end(); - - function isFalse() { - return false; - } -}); diff --git a/uint8c/test/test.polyfill.js b/uint8c/test/test.polyfill.js deleted file mode 100644 index 9d6fcb19..00000000 --- a/uint8c/test/test.polyfill.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'; - -// MODULES // - -var tape = require( 'tape' ); -var ctor = require( './../lib/polyfill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ctor, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error when invoked', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var f = new ctor(); // eslint-disable-line no-unused-vars - } -}); - -// TODO: tests diff --git a/zero-to-like/README.md b/zero-to-like/README.md deleted file mode 100644 index 633f65c0..00000000 --- a/zero-to-like/README.md +++ /dev/null @@ -1,178 +0,0 @@ - - -# zeroToLike - -> Generate a linearly spaced numeric array whose elements increment by `1` starting from zero and having the same length and data type as a provided input array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var zeroToLike = require( '@stdlib/array/zero-to-like' ); -``` - -#### zeroToLike( x\[, dtype] ) - -Generates a linearly spaced numeric array whose elements increment by `1` starting from zero and having the same length and data type as a provided input array `x`. - -```javascript -var arr = zeroToLike( [ 0, 0, 0, 0, 0 ] ); -// returns [ 0, 1, 2, 3, 4 ] -``` - -The function recognizes the following data types: - -- `float64`: double-precision floating-point numbers (IEEE 754) -- `float32`: single-precision floating-point numbers (IEEE 754) -- `complex128`: double-precision complex floating-point numbers -- `complex64`: single-precision complex floating-point numbers -- `int32`: 32-bit two's complement signed integers -- `uint32`: 32-bit unsigned integers -- `int16`: 16-bit two's complement signed integers -- `uint16`: 16-bit unsigned integers -- `int8`: 8-bit two's complement signed integers -- `uint8`: 8-bit unsigned integers -- `uint8c`: 8-bit unsigned integers clamped to `0-255` -- `generic`: generic JavaScript values - -By default, the output array data type is inferred from the provided array `x`. To return an array having a different data type, provide a `dtype` argument. - -```javascript -var arr = zeroToLike( [ 0, 0, 0, 0, 0 ], 'int32' ); -// returns [ 0, 1, 2, 3, 4 ] -``` - -
- - - - - -
- -## Notes - -- For complex number arrays, each element of the returned array has an imaginary component equal to `0`. - -
- - - - - -
- -## Examples - - - -```javascript -var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var zeroToLike = require( '@stdlib/array/zero-to-like' ); - -// Generate an array of random numbers: -var opts = { - 'dtype': 'generic' -}; -var x = discreteUniform( 10, 100, 200, opts ); - -// Generate an array of indices: -var idx = zeroToLike( x ); - -// Create a temporary array to avoid mutation: -var tmp = x.slice(); - -// Sort the index array according to the sort order of `x`: -sort2hp( x.length, 1, tmp, 1, idx, 1 ); - -console.log( x ); -console.log( idx ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/zero-to-like/benchmark/benchmark.js b/zero-to-like/benchmark/benchmark.js deleted file mode 100644 index 467e2cb9..00000000 --- a/zero-to-like/benchmark/benchmark.js +++ /dev/null @@ -1,317 +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' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var isArray = require( '@stdlib/assert/is-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'complex128' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'complex64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int16' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint16' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int8' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint8' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint8c' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'generic' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/zero-to-like/benchmark/benchmark.length.complex128.js b/zero-to-like/benchmark/benchmark.length.complex128.js deleted file mode 100644 index cf4a4ac8..00000000 --- a/zero-to-like/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'complex128' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.complex64.js b/zero-to-like/benchmark/benchmark.length.complex64.js deleted file mode 100644 index f4f6c80a..00000000 --- a/zero-to-like/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'complex64' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.float32.js b/zero-to-like/benchmark/benchmark.length.float32.js deleted file mode 100644 index 3a3a1209..00000000 --- a/zero-to-like/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'float32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.float64.js b/zero-to-like/benchmark/benchmark.length.float64.js deleted file mode 100644 index 89d95fc6..00000000 --- a/zero-to-like/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'float64' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.generic.js b/zero-to-like/benchmark/benchmark.length.generic.js deleted file mode 100644 index 85332bab..00000000 --- a/zero-to-like/benchmark/benchmark.length.generic.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isArray = require( '@stdlib/assert/is-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'generic' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.int16.js b/zero-to-like/benchmark/benchmark.length.int16.js deleted file mode 100644 index 0eca96e6..00000000 --- a/zero-to-like/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int16' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.int32.js b/zero-to-like/benchmark/benchmark.length.int32.js deleted file mode 100644 index 50f6a77f..00000000 --- a/zero-to-like/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.int8.js b/zero-to-like/benchmark/benchmark.length.int8.js deleted file mode 100644 index 18f9ea55..00000000 --- a/zero-to-like/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int8' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.uint16.js b/zero-to-like/benchmark/benchmark.length.uint16.js deleted file mode 100644 index df29c977..00000000 --- a/zero-to-like/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint16' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.uint32.js b/zero-to-like/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 02bd2060..00000000 --- a/zero-to-like/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.uint8.js b/zero-to-like/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ec101076..00000000 --- a/zero-to-like/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint8' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/benchmark/benchmark.length.uint8c.js b/zero-to-like/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8d67dd6b..00000000 --- a/zero-to-like/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,95 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zeroToLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint8c' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroToLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/zero-to-like/docs/repl.txt b/zero-to-like/docs/repl.txt deleted file mode 100644 index 4445fa7c..00000000 --- a/zero-to-like/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( x[, dtype] ) - Generates a linearly spaced numeric array whose elements increment by 1 - starting from zero and having the same length and data type as a provided - input array. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values - - Parameters - ---------- - x: TypedArray|Array - Input array. - - dtype: string (optional) - Data type. If not provided, the output array data type is inferred from - the input array. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr = {{alias}}( [ 0, 0 ] ) - [ 0, 1 ] - > arr = {{alias}}( [ 0, 0 ], 'float32' ) - [ 0.0, 1.0 ] - - See Also - -------- - diff --git a/zero-to-like/docs/types/index.d.ts b/zero-to-like/docs/types/index.d.ts deleted file mode 100644 index 88f15b24..00000000 --- a/zero-to-like/docs/types/index.d.ts +++ /dev/null @@ -1,494 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Complex128Array, Complex64Array, AnyArray, NumericDataType } from '@stdlib/types/array'; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'float64' ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'float64' ): Float64Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float64' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'float32' ): Float32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* ## Notes -* -* - Each element has an imaginary component equal to `0`. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'complex128' ); -* // returns -*/ -declare function zeroToLike( x: AnyArray, dtype: 'complex128' ): Complex128Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* ## Notes -* -* - Each element has an imaginary component equal to `0`. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'complex64' ); -* // returns -*/ -declare function zeroToLike( x: AnyArray, dtype: 'complex64' ): Complex64Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'int32' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'int32' ): Int32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'int16' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'int16' ): Int16Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'int8' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'int8' ): Int8Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'uint32' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'uint32' ): Uint32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'uint16' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'uint16' ): Uint16Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'uint8' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'uint8' ): Uint8Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'uint8c' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'uint8c' ): Uint8ClampedArray; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x, 'generic' ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: AnyArray, dtype: 'generic' ): Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float64' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroToLike( x: Float64Array, dtype?: NumericDataType ): Float64Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroToLike( x: Float32Array, dtype?: NumericDataType ): Float32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* ## Notes -* -* - Each element has an imaginary component equal to `0`. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'complex128' ); -* // returns -* -* var y = zeroToLike( x ); -* // returns -*/ -declare function zeroToLike( x: Complex128Array, dtype?: NumericDataType ): Complex128Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* ## Notes -* -* - Each element has an imaginary component equal to `0`. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'complex64' ); -* // returns -* -* var y = zeroToLike( x ); -* // returns -*/ -declare function zeroToLike( x: Complex64Array, dtype?: NumericDataType ): Complex64Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'int32' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Int32Array, dtype?: NumericDataType ): Int32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'int16' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Int16Array, dtype?: NumericDataType ): Int16Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'int8' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Int8Array, dtype?: NumericDataType ): Int8Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'uint32' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Uint32Array, dtype?: NumericDataType ): Uint32Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'uint16' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Uint16Array, dtype?: NumericDataType ): Uint16Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'uint8' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Uint8Array, dtype?: NumericDataType ): Uint8Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'uint8c' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Uint8ClampedArray, dtype?: NumericDataType ): Uint8ClampedArray; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'generic' ); -* // returns [ 0, 0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0, 1 ] -*/ -declare function zeroToLike( x: Array, dtype?: NumericDataType ): Array; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns linearly spaced numeric array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zeroToLike( x ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroToLike( x: AnyArray, dtype?: NumericDataType ): AnyArray; - - -// EXPORTS // - -export = zeroToLike; diff --git a/zero-to-like/docs/types/test.ts b/zero-to-like/docs/types/test.ts deleted file mode 100644 index 7e351992..00000000 --- a/zero-to-like/docs/types/test.ts +++ /dev/null @@ -1,89 +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. -*/ - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); -import zeroToLike = require( './index' ); - - -// TESTS // - -// The function returns an array or typed array... -{ - zeroToLike( [ 0, 0 ] ); // $ExpectType number[] - zeroToLike( new Float64Array( [ 0, 0 ] ) ); // $ExpectType Float64Array - zeroToLike( new Float32Array( [ 0, 0 ] ) ); // $ExpectType Float32Array - zeroToLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array - zeroToLike( new Complex64Array( [ 0, 0 ] ) ); // $ExpectType Complex64Array - zeroToLike( new Int32Array( [ 0, 0 ] ) ); // $ExpectType Int32Array - zeroToLike( new Int16Array( [ 0, 0 ] ) ); // $ExpectType Int16Array - zeroToLike( new Int8Array( [ 0, 0 ] ) ); // $ExpectType Int8Array - zeroToLike( new Uint32Array( [ 0, 0 ] ) ); // $ExpectType Uint32Array - zeroToLike( new Uint16Array( [ 0, 0 ] ) ); // $ExpectType Uint16Array - zeroToLike( new Uint8Array( [ 0, 0 ] ) ); // $ExpectType Uint8Array - zeroToLike( new Uint8ClampedArray( [ 0, 0 ] ) ); // $ExpectType Uint8ClampedArray - - zeroToLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array - zeroToLike( [ 0, 0 ], 'float32' ); // $ExpectType Float32Array - zeroToLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array - zeroToLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array - zeroToLike( [ 0, 0 ], 'int32' ); // $ExpectType Int32Array - zeroToLike( [ 0, 0 ], 'int16' ); // $ExpectType Int16Array - zeroToLike( [ 0, 0 ], 'int8' ); // $ExpectType Int8Array - zeroToLike( [ 0, 0 ], 'uint32' ); // $ExpectType Uint32Array - zeroToLike( [ 0, 0 ], 'uint16' ); // $ExpectType Uint16Array - zeroToLike( [ 0, 0 ], 'uint8' ); // $ExpectType Uint8Array - zeroToLike( [ 0, 0 ], 'uint8c' ); // $ExpectType Uint8ClampedArray - zeroToLike( [ 0, 0 ], 'generic' ); // $ExpectType number[] -} - -// The compiler throws an error if the function is not provided an array or typed array for the first argument... -{ - zeroToLike( '5' ); // $ExpectError - zeroToLike( false ); // $ExpectError - zeroToLike( true ); // $ExpectError - zeroToLike( null ); // $ExpectError - zeroToLike( undefined ); // $ExpectError - zeroToLike( {} ); // $ExpectError - zeroToLike( ( x: number ): number => x ); // $ExpectError - - zeroToLike( '5', 'float32' ); // $ExpectError - zeroToLike( false, 'float32' ); // $ExpectError - zeroToLike( true, 'float32' ); // $ExpectError - zeroToLike( null, 'float32' ); // $ExpectError - zeroToLike( undefined, 'float32' ); // $ExpectError - zeroToLike( {}, 'float32' ); // $ExpectError - zeroToLike( ( x: number ): number => x, 'float32' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is an unrecognized/unsupported data type... -{ - zeroToLike( [ 0, 0 ], '10' ); // $ExpectError - zeroToLike( [ 0, 0 ], 10 ); // $ExpectError - zeroToLike( [ 0, 0 ], false ); // $ExpectError - zeroToLike( [ 0, 0 ], true ); // $ExpectError - zeroToLike( [ 0, 0 ], null ); // $ExpectError - zeroToLike( [ 0, 0 ], [] ); // $ExpectError - zeroToLike( [ 0, 0 ], {} ); // $ExpectError - zeroToLike( [ 0, 0 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - zeroToLike( [ 0, 0 ], 'float64', 1 ); // $ExpectError -} diff --git a/zero-to-like/examples/index.js b/zero-to-like/examples/index.js deleted file mode 100644 index d8c05a40..00000000 --- a/zero-to-like/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var zeroToLike = require( './../lib' ); - -// Generate an array of random numbers: -var opts = { - 'dtype': 'generic' -}; -var x = discreteUniform( 10, 100, 200, opts ); - -// Generate an array of indices: -var idx = zeroToLike( x ); - -// Create a temporary array to avoid mutation: -var tmp = x.slice(); - -// Sort the index array according to the sort order of `x`: -sort2hp( x.length, 1, tmp, 1, idx, 1 ); - -console.log( x ); -console.log( idx ); diff --git a/zero-to-like/lib/index.js b/zero-to-like/lib/index.js deleted file mode 100644 index 3032ff47..00000000 --- a/zero-to-like/lib/index.js +++ /dev/null @@ -1,46 +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'; - -/** -* Generate a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @module @stdlib/array/zero-to-like -* -* @example -* var zeroToLike = require( '@stdlib/array/zero-to-like' ); -* -* var arr = zeroToLike( [ 0.0, 0.0 ] ); -* // returns [ 0.0, 1.0 ] -* -* @example -* var zeroToLike = require( '@stdlib/array/zero-to-like' ); -* -* var arr = zeroToLike( [ 0.0, 0.0 ], 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/zero-to-like/lib/main.js b/zero-to-like/lib/main.js deleted file mode 100644 index 29adb602..00000000 --- a/zero-to-like/lib/main.js +++ /dev/null @@ -1,61 +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 zeroTo = require( './../../zero-to' ); -var dtype = require( './../../dtype' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array. -* -* @param {(TypedArray|Array|ComplexArray)} x - input array -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} first argument must be an array or typed array -* @throws {TypeError} second argument must be a recognized data type -* @returns {(TypedArray|Array|ComplexArray)} array or typed array -* -* @example -* var arr = zeroToLike( [ 0.0, 0.0 ] ); -* // returns [ 0.0, 1.0 ] -* -* @example -* var arr = zeroToLike( [ 0.0, 0.0 ], 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ -function zeroToLike( x ) { - var dt = dtype( x ); // delegate input argument validation to dtype resolution - if ( dt === null ) { - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or complex typed array. Value: `%s`.', x ) ); - } - if ( arguments.length > 1 ) { - dt = arguments[ 1 ]; - } - return zeroTo( x.length, dt ); -} - - -// EXPORTS // - -module.exports = zeroToLike; diff --git a/zero-to-like/package.json b/zero-to-like/package.json deleted file mode 100644 index ab0d2129..00000000 --- a/zero-to-like/package.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "name": "@stdlib/array/zero-to-like", - "version": "0.0.0", - "description": "Generate a linearly spaced numeric array whose elements increment by 1 starting from zero and having the same length and data type as a provided input array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "complex128array", - "complex64array", - "complex128", - "complex64", - "complex", - "cmplx", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long", - "generic", - "fill", - "filled", - "matlab", - "linear", - "linspace", - "sequence", - "increment", - "unitspace" - ] -} diff --git a/zero-to-like/test/test.js b/zero-to-like/test/test.js deleted file mode 100644 index 70c1aa1c..00000000 --- a/zero-to-like/test/test.js +++ /dev/null @@ -1,524 +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 tape = require( 'tape' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var zeroToLike = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof zeroToLike, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a value other than an array having a supported data type for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeroToLike( value ); - }; - } -}); - -tape( 'the function throws an error if provided a value other than an array having a supported data type for the first argument (dtype)', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeroToLike( value, 'float32' ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'zeroToLike', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - zeroToLike( [], value ); - }; - } -}); - -tape( 'the function returns a filled array (float64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float32Array( 5 ); - expected = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroToLike( x, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (float32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float32Array( 5 ); - expected = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroToLike( x, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (complex128)', function test( t ) { - var expected; - var arr; - var x; - - x = new Complex128Array( 4 ); - expected = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 4 ); - expected = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroToLike( x, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (complex64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Complex64Array( 4 ); - expected = new Float32Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 4 ); - expected = new Float32Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroToLike( x, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (int32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int32Array( 5 ); - expected = new Int32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (uint32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint32Array( 5 ); - expected = new Uint32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (int16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int16Array( 5 ); - expected = new Int16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (uint16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint16Array( 5 ); - expected = new Uint16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (int8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int8Array( 5 ); - expected = new Int8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (uint8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint8Array( 5 ); - expected = new Uint8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (uint8c)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint8ClampedArray( 5 ); - expected = new Uint8ClampedArray( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint8ClampedArray( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroToLike( x, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (generic)', function test( t ) { - var expected; - var arr; - var x; - - x = [ 0, 0, 0, 0, 0 ]; - expected = [ 0, 1, 2, 3, 4 ]; - - arr = zeroToLike( x ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = [ 0, 1, 2, 3, 4 ]; - - arr = zeroToLike( x, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/zero-to/README.md b/zero-to/README.md deleted file mode 100644 index 60bb8b4e..00000000 --- a/zero-to/README.md +++ /dev/null @@ -1,181 +0,0 @@ - - -# zeroTo - -> Generate a linearly spaced numeric array whose elements increment by `1` starting from zero. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var zeroTo = require( '@stdlib/array/zero-to' ); -``` - -#### zeroTo( n\[, dtype] ) - -Generates a linearly spaced numeric array whose elements increment by `1` starting from zero. - -```javascript -var arr = zeroTo( 5 ); -// returns [ 0.0, 1.0, 2.0, 3.0, 4.0 ] -``` - -If `n == 0`, the function returns an empty array. - -```javascript -var arr = zeroTo( 0 ); -// returns [] -``` - -The function recognizes the following data types: - -- `float64`: double-precision floating-point numbers (IEEE 754) -- `float32`: single-precision floating-point numbers (IEEE 754) -- `complex128`: double-precision complex floating-point numbers -- `complex64`: single-precision complex floating-point numbers -- `int32`: 32-bit two's complement signed integers -- `uint32`: 32-bit unsigned integers -- `int16`: 16-bit two's complement signed integers -- `uint16`: 16-bit unsigned integers -- `int8`: 8-bit two's complement signed integers -- `uint8`: 8-bit unsigned integers -- `uint8c`: 8-bit unsigned integers clamped to `0-255` -- `generic`: generic JavaScript values - -By default, the output array data type is `float64` (i.e., a [typed array][mdn-typed-array]). To specify an alternative data type, provide a `dtype` argument. - -```javascript -var arr = zeroTo( 5, 'int32' ); -// returns [ 0, 1, 2, 3, 4 ] -``` - -
- - - - - -
- -## Notes - -- For complex number arrays, each element of the returned array has an imaginary component equal to `0`. - -
- - - - - -
- -## Examples - - - -```javascript -var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var zeroTo = require( '@stdlib/array/zero-to' ); - -// Generate an array of random numbers: -var opts = { - 'dtype': 'generic' -}; -var x = discreteUniform( 10, 100, 200, opts ); - -// Generate an array of indices: -var idx = zeroTo( x.length, opts.dtype ); - -// Create a temporary array to avoid mutation: -var tmp = x.slice(); - -// Sort the index array according to the sort order of `x`: -sort2hp( x.length, 1, tmp, 1, idx, 1 ); - -console.log( x ); -console.log( idx ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/zero-to/benchmark/benchmark.js b/zero-to/benchmark/benchmark.js deleted file mode 100644 index d3f48e0c..00000000 --- a/zero-to/benchmark/benchmark.js +++ /dev/null @@ -1,264 +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' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a 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 = zeroTo( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeroTo( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( 0, 'generic' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/zero-to/benchmark/benchmark.length.complex128.js b/zero-to/benchmark/benchmark.length.complex128.js deleted file mode 100644 index f33aae51..00000000 --- a/zero-to/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.complex64.js b/zero-to/benchmark/benchmark.length.complex64.js deleted file mode 100644 index e4665882..00000000 --- a/zero-to/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.float32.js b/zero-to/benchmark/benchmark.length.float32.js deleted file mode 100644 index 9bb252d0..00000000 --- a/zero-to/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.float64.js b/zero-to/benchmark/benchmark.length.float64.js deleted file mode 100644 index e48bda06..00000000 --- a/zero-to/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.generic.js b/zero-to/benchmark/benchmark.length.generic.js deleted file mode 100644 index 73d0ad6d..00000000 --- a/zero-to/benchmark/benchmark.length.generic.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'generic' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.int16.js b/zero-to/benchmark/benchmark.length.int16.js deleted file mode 100644 index b49a5d58..00000000 --- a/zero-to/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.int32.js b/zero-to/benchmark/benchmark.length.int32.js deleted file mode 100644 index 51f2f53b..00000000 --- a/zero-to/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.int8.js b/zero-to/benchmark/benchmark.length.int8.js deleted file mode 100644 index d5cb7cbd..00000000 --- a/zero-to/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.uint16.js b/zero-to/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 786ea71f..00000000 --- a/zero-to/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.uint32.js b/zero-to/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 0336f99c..00000000 --- a/zero-to/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.uint8.js b/zero-to/benchmark/benchmark.length.uint8.js deleted file mode 100644 index a9b389a9..00000000 --- a/zero-to/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/zero-to/benchmark/benchmark.length.uint8c.js b/zero-to/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index ad5ca190..00000000 --- a/zero-to/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,93 +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' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeroTo = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeroTo( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/zero-to/docs/repl.txt b/zero-to/docs/repl.txt deleted file mode 100644 index fda8e7b8..00000000 --- a/zero-to/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( n[, dtype] ) - Generates a linearly spaced numeric array whose elements increment by 1 - starting from zero. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values - - The default array data type is `float64`. - - If `n` is equal to zero, the function returns an empty array. - - Parameters - ---------- - n: integer - Number of elements. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr = {{alias}}( 2 ) - [ 0.0, 1.0 ] - > arr = {{alias}}( 2, 'float32' ) - [ 0.0, 1.0 ] - - See Also - -------- - diff --git a/zero-to/docs/types/index.d.ts b/zero-to/docs/types/index.d.ts deleted file mode 100644 index 93e2a169..00000000 --- a/zero-to/docs/types/index.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { NumericAndGenericDataTypeMap } from '@stdlib/types/array'; - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero. -* -* @param n - number of elements -* @param dtype - data type (default: 'float64') -* @returns linearly spaced numeric array -* -* @example -* var arr = zeroTo( 2 ); -* // returns [ 0.0, 1.0 ] -* -* @example -* var arr = zeroTo( 2, 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ -declare function zeroTo = 'float64'>( n: number, dtype?: T ): NumericAndGenericDataTypeMap[T]; - - -// EXPORTS // - -export = zeroTo; diff --git a/zero-to/docs/types/test.ts b/zero-to/docs/types/test.ts deleted file mode 100644 index c2e7ef80..00000000 --- a/zero-to/docs/types/test.ts +++ /dev/null @@ -1,77 +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. -*/ - -import zeroTo = require( './index' ); - - -// TESTS // - -// The function returns an array or typed array... -{ - zeroTo( 10 ); // $ExpectType Float64Array - zeroTo( 10, 'float64' ); // $ExpectType Float64Array - zeroTo( 10, 'float32' ); // $ExpectType Float32Array - zeroTo( 10, 'complex128' ); // $ExpectType Complex128Array - zeroTo( 10, 'complex64' ); // $ExpectType Complex64Array - zeroTo( 10, 'int32' ); // $ExpectType Int32Array - zeroTo( 10, 'int16' ); // $ExpectType Int16Array - zeroTo( 10, 'int8' ); // $ExpectType Int8Array - zeroTo( 10, 'uint32' ); // $ExpectType Uint32Array - zeroTo( 10, 'uint16' ); // $ExpectType Uint16Array - zeroTo( 10, 'uint8' ); // $ExpectType Uint8Array - zeroTo( 10, 'uint8c' ); // $ExpectType Uint8ClampedArray - zeroTo( 10, 'generic' ); // $ExpectType number[] -} - -// The compiler throws an error if the function is not provided a number for the first argument... -{ - zeroTo( '5' ); // $ExpectError - zeroTo( false ); // $ExpectError - zeroTo( true ); // $ExpectError - zeroTo( null ); // $ExpectError - zeroTo( undefined ); // $ExpectError - zeroTo( [] ); // $ExpectError - zeroTo( {} ); // $ExpectError - zeroTo( ( x: number ): number => x ); // $ExpectError - - zeroTo( '5', 'float32' ); // $ExpectError - zeroTo( false, 'float32' ); // $ExpectError - zeroTo( true, 'float32' ); // $ExpectError - zeroTo( null, 'float32' ); // $ExpectError - zeroTo( undefined, 'float32' ); // $ExpectError - zeroTo( [], 'float32' ); // $ExpectError - zeroTo( {}, 'float32' ); // $ExpectError - zeroTo( ( x: number ): number => x, 'float32' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is an unrecognized/unsupported data type... -{ - zeroTo( 10, '10' ); // $ExpectError - zeroTo( 10, 10 ); // $ExpectError - zeroTo( 10, false ); // $ExpectError - zeroTo( 10, true ); // $ExpectError - zeroTo( 10, null ); // $ExpectError - zeroTo( 10, [] ); // $ExpectError - zeroTo( 10, {} ); // $ExpectError - zeroTo( 10, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - zeroTo( 10, 'float64', 1 ); // $ExpectError -} diff --git a/zero-to/examples/index.js b/zero-to/examples/index.js deleted file mode 100644 index 4d7218b1..00000000 --- a/zero-to/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var zeroTo = require( './../lib' ); - -// Generate an array of random numbers: -var opts = { - 'dtype': 'generic' -}; -var x = discreteUniform( 10, 100, 200, opts ); - -// Generate an array of indices: -var idx = zeroTo( x.length, opts.dtype ); - -// Create a temporary array to avoid mutation: -var tmp = x.slice(); - -// Sort the index array according to the sort order of `x`: -sort2hp( x.length, 1, tmp, 1, idx, 1 ); - -console.log( x ); -console.log( idx ); diff --git a/zero-to/lib/index.js b/zero-to/lib/index.js deleted file mode 100644 index fc035baa..00000000 --- a/zero-to/lib/index.js +++ /dev/null @@ -1,46 +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'; - -/** -* Generate a linearly spaced numeric array whose elements increment by 1 starting from zero. -* -* @module @stdlib/array/zero-to -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var arr = zeroTo( 2 ); -* // returns [ 0.0, 1.0 ] -* -* @example -* var zeroTo = require( '@stdlib/array/zero-to' ); -* -* var arr = zeroTo( 2, 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/zero-to/lib/main.js b/zero-to/lib/main.js deleted file mode 100644 index 537bf3db..00000000 --- a/zero-to/lib/main.js +++ /dev/null @@ -1,73 +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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var base = require( './../../base/zero-to' ); -var zeros = require( './../../zeros' ); -var defaults = require( './../../defaults' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); - - -// MAIN // - -/** -* Generates a linearly spaced numeric array whose elements increment by 1 starting from zero. -* -* @param {NonNegativeInteger} n - number of elements -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} first argument must be a nonnegative integer -* @throws {TypeError} second argument must be a recognized data type -* @returns {(TypedArray|Array|ComplexArray)} array or typed array -* -* @example -* var arr = zeroTo( 2 ); -* // returns [ 0.0, 1.0 ] -* -* @example -* var arr = zeroTo( 2, 'float32' ); -* // returns [ 0.0, 1.0 ] -*/ -function zeroTo( n ) { - var dtype; - if ( !isNonNegativeInteger( n ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', n ) ); - } - if ( arguments.length > 1 ) { - dtype = arguments[ 1 ]; - if ( dtype === 'generic' ) { - return base( n ); - } - } else { - dtype = DEFAULT_DTYPE; - } - return base.assign( zeros( n, dtype ), 1, 0 ); // defer dtype validation to `zeros` -} - - -// EXPORTS // - -module.exports = zeroTo; diff --git a/zero-to/package.json b/zero-to/package.json deleted file mode 100644 index fc235b41..00000000 --- a/zero-to/package.json +++ /dev/null @@ -1,111 +0,0 @@ -{ - "name": "@stdlib/array/zero-to", - "version": "0.0.0", - "description": "Generate a linearly spaced numeric array whose elements increment by 1 starting from zero.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "complex128array", - "complex64array", - "complex128", - "complex64", - "complex", - "cmplx", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long", - "generic", - "fill", - "filled", - "matlab", - "linear", - "linspace", - "sequence", - "increment", - "unitspace" - ] -} diff --git a/zero-to/test/test.js b/zero-to/test/test.js deleted file mode 100644 index c7632da7..00000000 --- a/zero-to/test/test.js +++ /dev/null @@ -1,396 +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 tape = require( 'tape' ); -var Float64Array = require( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var zeroTo = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof zeroTo, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeroTo( value ); - }; - } -}); - -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeroTo( value, 'float32' ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'zeroTo', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - zeroTo( 10, value ); - }; - } -}); - -tape( 'the function returns a filled array (default)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroTo( 5 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroTo( 5, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); - - arr = zeroTo( 5, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroTo( 4, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0 ] ); - - arr = zeroTo( 4, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 0, 1, 2, 3, 4 ] ); - - arr = zeroTo( 5, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 0, 1, 2, 3, 4 ]; - - arr = zeroTo( 5, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'if `n` is zero, the function returns an empty array', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [] ); - arr = zeroTo( 0 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Float64Array( [] ); - arr = zeroTo( 0, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Float32Array( [] ); - arr = zeroTo( 0, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Int32Array( [] ); - arr = zeroTo( 0, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Int16Array( [] ); - arr = zeroTo( 0, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Int8Array( [] ); - arr = zeroTo( 0, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Uint32Array( [] ); - arr = zeroTo( 0, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Uint16Array( [] ); - arr = zeroTo( 0, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Uint8Array( [] ); - arr = zeroTo( 0, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Uint8ClampedArray( [] ); - arr = zeroTo( 0, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Complex128Array( [] ); - arr = zeroTo( 0, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = new Complex64Array( [] ); - arr = zeroTo( 0, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - expected = []; - arr = zeroTo( 0, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - - t.end(); -}); diff --git a/zeros-like/README.md b/zeros-like/README.md deleted file mode 100644 index b8d47d0f..00000000 --- a/zeros-like/README.md +++ /dev/null @@ -1,171 +0,0 @@ - - -# zerosLike - -> Create a zero-filled array having the same length and data type as a provided array. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var zerosLike = require( '@stdlib/array/zeros-like' ); -``` - -#### zerosLike( x\[, dtype] ) - -Creates a zero-filled array having the same length and data type as a provided array `x`. - -```javascript -var x = [ 1, 2, 3, 4, 5 ]; - -var arr = zerosLike( x ); -// returns [ 0, 0, 0, 0, 0 ] -``` - -The function supports the following data types: - -- `float64`: double-precision floating-point numbers (IEEE 754) -- `float32`: single-precision floating-point numbers (IEEE 754) -- `complex128`: double-precision complex floating-point numbers -- `complex64`: single-precision complex floating-point numbers -- `int32`: 32-bit two's complement signed integers -- `uint32`: 32-bit unsigned integers -- `int16`: 16-bit two's complement signed integers -- `uint16`: 16-bit unsigned integers -- `int8`: 8-bit two's complement signed integers -- `uint8`: 8-bit unsigned integers -- `uint8c`: 8-bit unsigned integers clamped to `0-255` -- `generic`: generic JavaScript values - -By default, the output array data type is inferred from the provided array `x`. To return an array having a different data type, provide a `dtype` argument. - -```javascript -var x = [ 0, 0 ]; - -var arr = zerosLike( x, 'int32' ); -// returns [ 0, 0 ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/dtypes' ); -var zeros = require( '@stdlib/array/zeros' ); -var zerosLike = require( '@stdlib/array/zeros-like' ); - -// Create a zero-filled array: -var x = zeros( 4, 'complex128' ); - -// Get a list of array data types: -var dt = dtypes(); - -// Generate additional zero-filled arrays... -var y; -var i; -for ( i = 0; i < dt.length; i++ ) { - y = zerosLike( x, dt[ i ] ); - console.log( y ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/zeros-like/benchmark/benchmark.js b/zeros-like/benchmark/benchmark.js deleted file mode 100644 index 38c7d600..00000000 --- a/zeros-like/benchmark/benchmark.js +++ /dev/null @@ -1,317 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var isArray = require( '@stdlib/assert/is-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'float32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'complex128' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'complex64' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint32' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int16' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint16' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'int8' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint8' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'uint8c' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var arr; - var x; - var i; - - x = zeros( 0, 'generic' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/zeros-like/benchmark/benchmark.length.complex128.js b/zeros-like/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 2352873f..00000000 --- a/zeros-like/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'complex128' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.complex64.js b/zeros-like/benchmark/benchmark.length.complex64.js deleted file mode 100644 index a9a1d924..00000000 --- a/zeros-like/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'complex64' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.float32.js b/zeros-like/benchmark/benchmark.length.float32.js deleted file mode 100644 index 7ed1a09f..00000000 --- a/zeros-like/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'float32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.float64.js b/zeros-like/benchmark/benchmark.length.float64.js deleted file mode 100644 index 50004bcf..00000000 --- a/zeros-like/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'float64' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.generic.js b/zeros-like/benchmark/benchmark.length.generic.js deleted file mode 100644 index 61dcbdb6..00000000 --- a/zeros-like/benchmark/benchmark.length.generic.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isArray = require( '@stdlib/assert/is-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'generic' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.int16.js b/zeros-like/benchmark/benchmark.length.int16.js deleted file mode 100644 index fc016836..00000000 --- a/zeros-like/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int16' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.int32.js b/zeros-like/benchmark/benchmark.length.int32.js deleted file mode 100644 index 3bb3d1c0..00000000 --- a/zeros-like/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.int8.js b/zeros-like/benchmark/benchmark.length.int8.js deleted file mode 100644 index 4fb50621..00000000 --- a/zeros-like/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'int8' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.uint16.js b/zeros-like/benchmark/benchmark.length.uint16.js deleted file mode 100644 index f0d78c66..00000000 --- a/zeros-like/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint16' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.uint32.js b/zeros-like/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 3fcd6b8e..00000000 --- a/zeros-like/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint32' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.uint8.js b/zeros-like/benchmark/benchmark.length.uint8.js deleted file mode 100644 index f379a027..00000000 --- a/zeros-like/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint8' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/benchmark/benchmark.length.uint8c.js b/zeros-like/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 7e6c284a..00000000 --- a/zeros-like/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var zeros = require( './../../zeros' ); -var pkg = require( './../package.json' ).name; -var zerosLike = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = zeros( len, 'uint8c' ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zerosLike( x ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/zeros-like/docs/repl.txt b/zeros-like/docs/repl.txt deleted file mode 100644 index 1655e1e8..00000000 --- a/zeros-like/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( x[, dtype] ) - Returns a zero-filled array having the same length and data type as a - provided input array. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values - - Parameters - ---------- - x: TypedArray|Array - Input array. - - dtype: string (optional) - Data type. If not provided, the output array data type is inferred from - the input array. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var x = new {{alias:@stdlib/array/float64}}( 2 ); - > var y = {{alias}}( x ) - [ 0.0, 0.0 ] - > y = {{alias}}( x, 'float32' ) - [ 0.0, 0.0 ] - - See Also - -------- - diff --git a/zeros-like/docs/types/index.d.ts b/zeros-like/docs/types/index.d.ts deleted file mode 100644 index dc82b05b..00000000 --- a/zeros-like/docs/types/index.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { NumericAndGenericDataTypeMap, AnyArray, TypedArray, ComplexTypedArray } from '@stdlib/types/array'; - -/** -* Creates a zero-filled array having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @returns zero-filled array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'generic' ); -* // returns [ 0, 0 ] -* -* var y = zerosLike( x ); -* // returns [ 0, 0 ] -*/ -declare function zerosLike( x: Array ): Array; - -/** -* Creates a zero-filled array having the same length and data type as a provided input array. -* -* @param x - input array from which to derive the output array length -* @returns zero-filled array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float64' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zerosLike( x ); -* // returns [ 0.0, 0.0 ] -*/ -declare function zerosLike( x: T ): T; - -/** -* Creates a zero-filled array having the same length as a provided input array. -* -* The function supports the following data types: -* -* - `float64`: double-precision floating-point numbers (IEEE 754) -* - `float32`: single-precision floating-point numbers (IEEE 754) -* - `complex128`: double-precision complex floating-point numbers -* - `complex64`: single-precision complex floating-point numbers -* - `int32`: 32-bit two's complement signed integers -* - `uint32`: 32-bit unsigned integers -* - `int16`: 16-bit two's complement signed integers -* - `uint16`: 16-bit unsigned integers -* - `int8`: 8-bit two's complement signed integers -* - `uint8`: 8-bit unsigned integers -* - `uint8c`: 8-bit unsigned integers clamped to `0-255` -* - `generic`: generic JavaScript values -* -* @param x - input array from which to derive the output array length -* @param dtype - data type -* @returns zero-filled array -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var x = zeros( 2, 'float64' ); -* // returns [ 0.0, 0.0 ] -* -* var y = zerosLike( x, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function zerosLike>( x: AnyArray, dtype: T ): NumericAndGenericDataTypeMap[T]; - - -// EXPORTS // - -export = zerosLike; diff --git a/zeros-like/docs/types/test.ts b/zeros-like/docs/types/test.ts deleted file mode 100644 index dbb0481f..00000000 --- a/zeros-like/docs/types/test.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import Complex128Array = require( './../../../complex128' ); -import Complex64Array = require( './../../../complex64' ); -import zerosLike = require( './index' ); - - -// TESTS // - -// The function returns an array or typed array... -{ - zerosLike( [ 0, 0 ] ); // $ExpectType number[] - zerosLike( new Float64Array( [ 0, 0 ] ) ); // $ExpectType Float64Array - zerosLike( new Float32Array( [ 0, 0 ] ) ); // $ExpectType Float32Array - zerosLike( new Complex128Array( [ 0, 0 ] ) ); // $ExpectType Complex128Array - zerosLike( new Complex64Array( [ 0, 0 ] ) ); // $ExpectType Complex64Array - zerosLike( new Int32Array( [ 0, 0 ] ) ); // $ExpectType Int32Array - zerosLike( new Int16Array( [ 0, 0 ] ) ); // $ExpectType Int16Array - zerosLike( new Int8Array( [ 0, 0 ] ) ); // $ExpectType Int8Array - zerosLike( new Uint32Array( [ 0, 0 ] ) ); // $ExpectType Uint32Array - zerosLike( new Uint16Array( [ 0, 0 ] ) ); // $ExpectType Uint16Array - zerosLike( new Uint8Array( [ 0, 0 ] ) ); // $ExpectType Uint8Array - zerosLike( new Uint8ClampedArray( [ 0, 0 ] ) ); // $ExpectType Uint8ClampedArray - zerosLike( [ 'a', 'b', 'c' ] ); // $ExpectType number[] - - zerosLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array - zerosLike( [ 0, 0 ], 'float32' ); // $ExpectType Float32Array - zerosLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array - zerosLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array - zerosLike( [ 0, 0 ], 'int32' ); // $ExpectType Int32Array - zerosLike( [ 0, 0 ], 'int16' ); // $ExpectType Int16Array - zerosLike( [ 0, 0 ], 'int8' ); // $ExpectType Int8Array - zerosLike( [ 0, 0 ], 'uint32' ); // $ExpectType Uint32Array - zerosLike( [ 0, 0 ], 'uint16' ); // $ExpectType Uint16Array - zerosLike( [ 0, 0 ], 'uint8' ); // $ExpectType Uint8Array - zerosLike( [ 0, 0 ], 'uint8c' ); // $ExpectType Uint8ClampedArray - zerosLike( [ 0, 0 ], 'generic' ); // $ExpectType number[] - zerosLike( new Int32Array( [ 0, 0 ] ), 'generic' ); // $ExpectType number[] - zerosLike( [ 'a', 'b', 'c' ], 'generic' ); // $ExpectType number[] - zerosLike( [ 'a', 'b', 'c' ], 'float64' ); // $ExpectType Float64Array -} - -// The compiler throws an error if the function is not provided an array or typed array for the first argument... -{ - zerosLike( '5' ); // $ExpectError - zerosLike( 5 ); // $ExpectError - zerosLike( false ); // $ExpectError - zerosLike( true ); // $ExpectError - zerosLike( null ); // $ExpectError - zerosLike( undefined ); // $ExpectError - zerosLike( {} ); // $ExpectError - zerosLike( ( x: number ): number => x ); // $ExpectError - - zerosLike( '5', 'float32' ); // $ExpectError - zerosLike( 5, 'float32' ); // $ExpectError - zerosLike( false, 'float32' ); // $ExpectError - zerosLike( true, 'float32' ); // $ExpectError - zerosLike( null, 'float32' ); // $ExpectError - zerosLike( undefined, 'float32' ); // $ExpectError - zerosLike( {}, 'float32' ); // $ExpectError - zerosLike( ( x: number ): number => x, 'float32' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is an unrecognized/unsupported data type... -{ - zerosLike( [ 0, 0 ], '10' ); // $ExpectError - zerosLike( [ 0, 0 ], 10 ); // $ExpectError - zerosLike( [ 0, 0 ], false ); // $ExpectError - zerosLike( [ 0, 0 ], true ); // $ExpectError - zerosLike( [ 0, 0 ], null ); // $ExpectError - zerosLike( [ 0, 0 ], [] ); // $ExpectError - zerosLike( [ 0, 0 ], {} ); // $ExpectError - zerosLike( [ 0, 0 ], ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - zerosLike( [ 0, 0 ], 'float64', 1 ); // $ExpectError -} diff --git a/zeros-like/examples/index.js b/zeros-like/examples/index.js deleted file mode 100644 index 3daa75e3..00000000 --- a/zeros-like/examples/index.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../dtypes' ); -var zeros = require( './../../zeros' ); -var zerosLike = require( './../lib' ); - -// Create a zero-filled array: -var x = zeros( 4, 'complex128' ); - -// Get a list of array data types: -var dt = dtypes(); - -// Generate additional zero-filled arrays... -var y; -var i; -for ( i = 0; i < dt.length; i++ ) { - y = zerosLike( x, dt[ i ] ); - console.log( y ); -} diff --git a/zeros-like/lib/index.js b/zeros-like/lib/index.js deleted file mode 100644 index 89d8604a..00000000 --- a/zeros-like/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a zero-filled array having the same length and data type as a provided input array. -* -* @module @stdlib/array/zeros-like -* -* @example -* var zerosLike = require( '@stdlib/array/zeros-like' ); -* -* var arr = zerosLike( [ 0.0, 0.0 ] ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var zerosLike = require( '@stdlib/array/zeros-like' ); -* -* var arr = zerosLike( [ 0.0, 0.0 ], 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/zeros-like/lib/main.js b/zeros-like/lib/main.js deleted file mode 100644 index 835f4f9e..00000000 --- a/zeros-like/lib/main.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var dtype = require( './../../dtype' ); -var zeros = require( './../../zeros' ); - - -// MAIN // - -/** -* Creates a zero-filled array having the same length and data type as a provided input array. -* -* @param {(Array|TypedArray|ComplexArray)} x - input array -* @param {string} [dtype] - data type -* @throws {TypeError} first argument must be an array or typed array -* @throws {TypeError} second argument must be a recognized data type -* @returns {(TypedArray|Array|ComplexArray)} array or typed array -* -* @example -* var arr = zerosLike( [ 0.0, 0.0 ] ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = zerosLike( [ 0.0, 0.0 ], 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -function zerosLike( x ) { - var dt = dtype( x ); // delegate input argument validation to dtype resolution - if ( dt === null ) { - throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or complex typed array. Value: `%s`.', x ) ); - } - if ( arguments.length > 1 ) { - dt = arguments[ 1 ]; - } - return zeros( x.length, dt ); -} - - -// EXPORTS // - -module.exports = zerosLike; diff --git a/zeros-like/package.json b/zeros-like/package.json deleted file mode 100644 index e1bf6c35..00000000 --- a/zeros-like/package.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "name": "@stdlib/array/zeros-like", - "version": "0.0.0", - "description": "Create a zero-filled array having the same length and data type as a provided array.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "complex128array", - "complex64array", - "complex128", - "complex64", - "complex", - "cmplx", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long", - "generic", - "fill", - "filled", - "zeros" - ] -} diff --git a/zeros-like/test/test.js b/zeros-like/test/test.js deleted file mode 100644 index 292c0a4d..00000000 --- a/zeros-like/test/test.js +++ /dev/null @@ -1,524 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var zerosLike = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof zerosLike, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a value other than an array having a supported data type for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zerosLike( value ); - }; - } -}); - -tape( 'the function throws an error if provided a value other than an array having a supported data type for the first argument (dtype)', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zerosLike( value, 'float32' ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'zerosLike', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - zerosLike( [], value ); - }; - } -}); - -tape( 'the function returns a zero-filled array (float64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=float64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float32Array( 5 ); - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (float32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float32Array( 5 ); - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=float32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (complex128)', function test( t ) { - var expected; - var arr; - var x; - - x = new Complex128Array( 2 ); - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=complex128)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 2 ); - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (complex64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Complex64Array( 2 ); - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=complex64)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 2 ); - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zerosLike( x, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (int32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int32Array( 5 ); - expected = new Int32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (uint32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint32Array( 5 ); - expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint32)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (int16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int16Array( 5 ); - expected = new Int16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (uint16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint16Array( 5 ); - expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint16)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (int8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Int8Array( 5 ); - expected = new Int8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Int8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (uint8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint8Array( 5 ); - expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint8)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (uint8c)', function test( t ) { - var expected; - var arr; - var x; - - x = new Uint8ClampedArray( 5 ); - expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint8c)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] ); - - arr = zerosLike( x, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (generic)', function test( t ) { - var expected; - var arr; - var x; - - x = [ 1, 2, 3, 4, 5 ]; - expected = [ 0, 0, 0, 0, 0 ]; - - arr = zerosLike( x ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - var x; - - x = new Float64Array( 5 ); - expected = [ 0, 0, 0, 0, 0 ]; - - arr = zerosLike( x, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/zeros/README.md b/zeros/README.md deleted file mode 100644 index 0a99392e..00000000 --- a/zeros/README.md +++ /dev/null @@ -1,165 +0,0 @@ - - -# zeros - -> Create a zero-filled array having a specified length. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var zeros = require( '@stdlib/array/zeros' ); -``` - -#### zeros( length\[, dtype] ) - -Creates a zero-filled array having a specified length. - -```javascript -var arr = zeros( 2 ); -// returns [ 0.0, 0.0 ] -``` - -The function recognizes the following data types: - -- `float64`: double-precision floating-point numbers (IEEE 754) -- `float32`: single-precision floating-point numbers (IEEE 754) -- `complex128`: double-precision complex floating-point numbers -- `complex64`: single-precision complex floating-point numbers -- `int32`: 32-bit two's complement signed integers -- `uint32`: 32-bit unsigned integers -- `int16`: 16-bit two's complement signed integers -- `uint16`: 16-bit unsigned integers -- `int8`: 8-bit two's complement signed integers -- `uint8`: 8-bit unsigned integers -- `uint8c`: 8-bit unsigned integers clamped to `0-255` -- `generic`: generic JavaScript values - -By default, the output array data type is `float64` (i.e., a [typed array][mdn-typed-array]). To specify an alternative data type, provide a `dtype` argument. - -```javascript -var arr = zeros( 2, 'int32' ); -// returns [ 0, 0 ] -``` - -
- - - - - -
- -
- - - - - -
- -## Examples - - - -```javascript -var dtypes = require( '@stdlib/array/dtypes' ); -var zeros = require( '@stdlib/array/zeros' ); - -// Get a list of array data types: -var dt = dtypes(); - -// Generate zero-filled arrays... -var arr; -var i; -for ( i = 0; i < dt.length; i++ ) { - arr = zeros( 4, dt[ i ] ); - console.log( arr ); -} -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/zeros/benchmark/benchmark.js b/zeros/benchmark/benchmark.js deleted file mode 100644 index 72815b81..00000000 --- a/zeros/benchmark/benchmark.js +++ /dev/null @@ -1,264 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a 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 = zeros( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( 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 = zeros( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=generic', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( 0, 'generic' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/zeros/benchmark/benchmark.length.complex128.js b/zeros/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 7ad20551..00000000 --- a/zeros/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.complex64.js b/zeros/benchmark/benchmark.length.complex64.js deleted file mode 100644 index e7443725..00000000 --- a/zeros/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.float32.js b/zeros/benchmark/benchmark.length.float32.js deleted file mode 100644 index 3c2ffa73..00000000 --- a/zeros/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.float64.js b/zeros/benchmark/benchmark.length.float64.js deleted file mode 100644 index 043c5db0..00000000 --- a/zeros/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.generic.js b/zeros/benchmark/benchmark.length.generic.js deleted file mode 100644 index aa54ea85..00000000 --- a/zeros/benchmark/benchmark.length.generic.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'generic' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=generic,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.int16.js b/zeros/benchmark/benchmark.length.int16.js deleted file mode 100644 index bca1e388..00000000 --- a/zeros/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.int32.js b/zeros/benchmark/benchmark.length.int32.js deleted file mode 100644 index 44dfff8e..00000000 --- a/zeros/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.int8.js b/zeros/benchmark/benchmark.length.int8.js deleted file mode 100644 index 29b5956f..00000000 --- a/zeros/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.uint16.js b/zeros/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 70721e63..00000000 --- a/zeros/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.uint32.js b/zeros/benchmark/benchmark.length.uint32.js deleted file mode 100644 index d89e487c..00000000 --- a/zeros/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.uint8.js b/zeros/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8281bcaf..00000000 --- a/zeros/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/zeros/benchmark/benchmark.length.uint8c.js b/zeros/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 0ceb4119..00000000 --- a/zeros/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); -var pkg = require( './../package.json' ).name; -var zeros = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = zeros( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/zeros/docs/repl.txt b/zeros/docs/repl.txt deleted file mode 100644 index 4e88eb65..00000000 --- a/zeros/docs/repl.txt +++ /dev/null @@ -1,44 +0,0 @@ - -{{alias}}( length[, dtype] ) - Returns a zero-filled array having a specified length. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - generic: generic JavaScript values - - The default array data type is `float64`. - - Parameters - ---------- - length: integer - Array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr = {{alias}}( 2 ) - [ 0.0, 0.0 ] - > arr = {{alias}}( 2, 'float32' ) - [ 0.0, 0.0 ] - - See Also - -------- - diff --git a/zeros/docs/types/index.d.ts b/zeros/docs/types/index.d.ts deleted file mode 100644 index 848339a5..00000000 --- a/zeros/docs/types/index.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { NumericAndGenericDataTypeMap } from '@stdlib/types/array'; - -/** -* Creates a zero-filled array having a specified length. -* -* The function recognizes the following data types: -* -* - `float64`: double-precision floating-point numbers (IEEE 754) -* - `float32`: single-precision floating-point numbers (IEEE 754) -* - `complex128`: double-precision complex floating-point numbers -* - `complex64`: single-precision complex floating-point numbers -* - `int32`: 32-bit two's complement signed integers -* - `uint32`: 32-bit unsigned integers -* - `int16`: 16-bit two's complement signed integers -* - `uint16`: 16-bit unsigned integers -* - `int8`: 8-bit two's complement signed integers -* - `uint8`: 8-bit unsigned integers -* - `uint8c`: 8-bit unsigned integers clamped to `0-255` -* - `generic`: generic JavaScript values -* -* @param length - array length -* @param dtype - data type (default: 'float64') -* @returns zero-filled array -* -* @example -* var arr = zeros( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -declare function zeros = 'float64'>( length: number, dtype?: T ): NumericAndGenericDataTypeMap[T]; - - -// EXPORTS // - -export = zeros; diff --git a/zeros/docs/types/test.ts b/zeros/docs/types/test.ts deleted file mode 100644 index a41620a0..00000000 --- a/zeros/docs/types/test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( './index' ); - - -// TESTS // - -// The function returns an array or typed array... -{ - zeros( 10 ); // $ExpectType Float64Array - zeros( 10, 'float64' ); // $ExpectType Float64Array - zeros( 10, 'float32' ); // $ExpectType Float32Array - zeros( 10, 'complex128' ); // $ExpectType Complex128Array - zeros( 10, 'complex64' ); // $ExpectType Complex64Array - zeros( 10, 'int32' ); // $ExpectType Int32Array - zeros( 10, 'int16' ); // $ExpectType Int16Array - zeros( 10, 'int8' ); // $ExpectType Int8Array - zeros( 10, 'uint32' ); // $ExpectType Uint32Array - zeros( 10, 'uint16' ); // $ExpectType Uint16Array - zeros( 10, 'uint8' ); // $ExpectType Uint8Array - zeros( 10, 'uint8c' ); // $ExpectType Uint8ClampedArray - zeros( 10, 'generic' ); // $ExpectType number[] -} - -// The compiler throws an error if the function is not provided a number for the first argument... -{ - zeros( '5' ); // $ExpectError - zeros( false ); // $ExpectError - zeros( true ); // $ExpectError - zeros( null ); // $ExpectError - zeros( undefined ); // $ExpectError - zeros( [] ); // $ExpectError - zeros( {} ); // $ExpectError - zeros( ( x: number ): number => x ); // $ExpectError - - zeros( '5', 'float32' ); // $ExpectError - zeros( false, 'float32' ); // $ExpectError - zeros( true, 'float32' ); // $ExpectError - zeros( null, 'float32' ); // $ExpectError - zeros( undefined, 'float32' ); // $ExpectError - zeros( [], 'float32' ); // $ExpectError - zeros( {}, 'float32' ); // $ExpectError - zeros( ( x: number ): number => x, 'float32' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is an unrecognized/unsupported data type... -{ - zeros( 10, '10' ); // $ExpectError - zeros( 10, 10 ); // $ExpectError - zeros( 10, false ); // $ExpectError - zeros( 10, true ); // $ExpectError - zeros( 10, null ); // $ExpectError - zeros( 10, [] ); // $ExpectError - zeros( 10, {} ); // $ExpectError - zeros( 10, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - zeros( 10, 'float64', 1 ); // $ExpectError -} diff --git a/zeros/examples/index.js b/zeros/examples/index.js deleted file mode 100644 index 5f2b2de6..00000000 --- a/zeros/examples/index.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 dtypes = require( './../../dtypes' ); -var zeros = require( './../lib' ); - -// Get a list of array data types: -var dt = dtypes(); - -// Generate zero-filled arrays... -var arr; -var i; -for ( i = 0; i < dt.length; i++ ) { - arr = zeros( 4, dt[ i ] ); - console.log( arr ); -} diff --git a/zeros/lib/index.js b/zeros/lib/index.js deleted file mode 100644 index fe14f3f4..00000000 --- a/zeros/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a zero-filled array having a specified length. -* -* @module @stdlib/array/zeros -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var arr = zeros( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var zeros = require( '@stdlib/array/zeros' ); -* -* var arr = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/zeros/lib/main.js b/zeros/lib/main.js deleted file mode 100644 index 1bebe3b1..00000000 --- a/zeros/lib/main.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var ctors = require( './../../ctors' ); -var gzeros = require( './../../base/zeros' ); -var defaults = require( './../../defaults' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); - - -// MAIN // - -/** -* Creates a zero-filled array having a specified length. -* -* @param {NonNegativeInteger} length - array length -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} first argument must be a nonnegative integer -* @throws {TypeError} second argument must be a recognized data type -* @returns {(TypedArray|Array|ComplexArray)} array or typed array -* -* @example -* var arr = zeros( 2 ); -* // returns [ 0.0, 0.0 ] -* -* @example -* var arr = zeros( 2, 'float32' ); -* // returns [ 0.0, 0.0 ] -*/ -function zeros( length ) { - var dtype; - var ctor; - if ( !isNonNegativeInteger( length ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', length ) ); - } - if ( arguments.length > 1 ) { - dtype = arguments[ 1 ]; - } else { - dtype = DEFAULT_DTYPE; - } - if ( dtype === 'generic' ) { - return gzeros( length ); - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Second argument must be a recognized data type. Value: `%s`.', dtype ) ); - } - return new ctor( length ); // WARNING: we assume that, apart from 'generic', the constructors for supported array data types are zero-filled by default -} - - -// EXPORTS // - -module.exports = zeros; diff --git a/zeros/package.json b/zeros/package.json deleted file mode 100644 index 4f8e94fb..00000000 --- a/zeros/package.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "name": "@stdlib/array/zeros", - "version": "0.0.0", - "description": "Create a zero-filled array having a specified length.", - "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": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "typed", - "array", - "typed array", - "typed-array", - "vector", - "ndarray", - "matrix", - "float64array", - "float32array", - "int32array", - "uint32array", - "int16array", - "uint16array", - "int8array", - "uint8array", - "uint8clampedarray", - "complex128array", - "complex64array", - "complex128", - "complex64", - "complex", - "cmplx", - "float64", - "double", - "precision", - "double-precision", - "single", - "float", - "single-precision", - "float32", - "ieee754", - "integer", - "int32", - "signed", - "unsigned", - "uint32", - "int16", - "uint16", - "int8", - "uint8", - "uint8c", - "clamped", - "short", - "long", - "generic", - "fill", - "filled", - "zeros" - ] -} diff --git a/zeros/test/test.js b/zeros/test/test.js deleted file mode 100644 index 8fec8f75..00000000 --- a/zeros/test/test.js +++ /dev/null @@ -1,324 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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( './../../float64' ); -var Float32Array = require( './../../float32' ); -var Int32Array = require( './../../int32' ); -var Uint32Array = require( './../../uint32' ); -var Int16Array = require( './../../int16' ); -var Uint16Array = require( './../../uint16' ); -var Int8Array = require( './../../int8' ); -var Uint8Array = require( './../../uint8' ); -var Uint8ClampedArray = require( './../../uint8c' ); -var Complex64Array = require( './../../complex64' ); -var Complex128Array = require( './../../complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); -var zeros = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof zeros, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeros( value ); - }; - } -}); - -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 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() { - zeros( value, 'float32' ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'zeros', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - zeros( 10, value ); - }; - } -}); - -tape( 'the function returns a zero-filled array (default)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zeros( 5 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zeros( 5, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zeros( 5, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=complex128)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zeros( 2, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=complex64)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); - - arr = zeros( 2, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] ); - - arr = zeros( 5, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 0, 0, 0, 0, 0 ]; - - arr = zeros( 5, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -});