diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fb91b40..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-02T01:00:42.045Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 2f3e921..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 2858986..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 6ae02b8..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '42 6 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -697,7 +688,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -762,17 +753,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2169bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1345 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = randu(); - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - if ( out.length === 0 ) { - b.fail( 'should have a length greater than 0' ); - } - } - b.toc(); - if ( out.length === 0 ) { - b.fail( 'should have a length greater than 0' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = randu(); - out = new ndarray( 'generic', buffer, shape, strides, offset, order ); - if ( out.length === 0 ) { - b.fail( 'should have a length greater than 0' ); - } - } - b.toc(); - if ( out.length === 0 ) { - b.fail( 'should have a length greater than 0' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:byteLength', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.byteLength; - if ( v !== null ) { - b.fail( 'should return null' ); - } - } - b.toc(); - if ( v !== null ) { - b.fail( 'should return null' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_byteLength', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._byteLength; // eslint-disable-line no-underscore-dangle - if ( v !== null ) { - b.fail( 'should return null' ); - } - } - b.toc(); - if ( v !== null ) { - b.fail( 'should return null' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:BYTES_PER_ELEMENT', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.BYTES_PER_ELEMENT; - if ( v !== null ) { - b.fail( 'should return null' ); - } - } - b.toc(); - if ( v !== null ) { - b.fail( 'should return null' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:data', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.data; - if ( v.length !== 6 ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== 6 ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_buffer', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._buffer; // eslint-disable-line no-underscore-dangle - if ( v.length !== 6 ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== 6 ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:dtype', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.dtype; - if ( v !== 'generic' ) { - b.fail( 'should return expected data type' ); - } - } - b.toc(); - if ( v !== 'generic' ) { - b.fail( 'should return expected data type' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:flags', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.flags; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_flags', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._flags; // eslint-disable-line no-underscore-dangle - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:length', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.length; - if ( v !== buffer.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v !== buffer.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_length', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._length; // eslint-disable-line no-underscore-dangle - if ( v !== buffer.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v !== buffer.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:ndims', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.ndims; - if ( v !== shape.length ) { - b.fail( 'should return expected number of dimensions' ); - } - } - b.toc(); - if ( v !== shape.length ) { - b.fail( 'should return expected number of dimensions' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:offset', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.offset; - if ( v !== offset ) { - b.fail( 'should return expected offset' ); - } - } - b.toc(); - if ( v !== offset ) { - b.fail( 'should return expected offset' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_offset', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._offset; // eslint-disable-line no-underscore-dangle - if ( v !== offset ) { - b.fail( 'should return expected offset' ); - } - } - b.toc(); - if ( v !== offset ) { - b.fail( 'should return expected offset' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:order', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.order; - if ( v !== order ) { - b.fail( 'should return expected order' ); - } - } - b.toc(); - if ( v !== order ) { - b.fail( 'should return expected order' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_order', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._order; // eslint-disable-line no-underscore-dangle - if ( v !== order ) { - b.fail( 'should return expected order' ); - } - } - b.toc(); - if ( v !== order ) { - b.fail( 'should return expected order' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:shape', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.shape; - if ( v.length !== shape.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== shape.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_shape', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._shape; // eslint-disable-line no-underscore-dangle - if ( v.length !== shape.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== shape.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:strides', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out.strides; - if ( v.length !== strides.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== strides.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::get:_strides', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = out._strides; // eslint-disable-line no-underscore-dangle - if ( v.length !== strides.length ) { - b.fail( 'should return expected length' ); - } - } - b.toc(); - if ( v.length !== strides.length ) { - b.fail( 'should return expected length' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':get', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.get( floor( randu()*3.0 ), 1 ); - 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+'::all_positive_strides:iget:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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+'::all_positive_strides:iget:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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+'::all_negative_strides:iget:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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+'::all_negative_strides:iget:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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+'::mixed_sign_strides:iget:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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+'::mixed_sign_strides:iget:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.iget( floor( randu()*4.0 ) ); - 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', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*3.0 ); - out.set( j, 1, v ); - if ( buffer[ (2*j) + (1*1) ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ (2*j) + 1 ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::all_positive_strides:iset:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::all_positive_strides:iset:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::all_negative_strides:iset:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ 3-j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ 3-j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::all_negative_strides:iset:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ 3-j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ 3-j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::mixed_sign_strides:iset:order=row-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ 0 ] !== buffer[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( out.iget( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::mixed_sign_strides:iset:order=column-major', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - var j; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = randu(); - j = floor( randu()*4.0 ); - out.iset( j, v ); - if ( buffer[ 0 ] !== buffer[ 0 ] ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( out.iget( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':toJSON', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':toString', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = randu(); - v = out.toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':valueOf:ndims=0', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0 ]; - shape = []; - strides = [ 0 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - v = out.valueOf(); - if ( typeof v !== 'number' ) { - b.fail( 'should return a number' ); - } - } - b.toc(); - if ( typeof v !== 'number' ) { - b.fail( 'should return a number' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':valueOf:ndims>=1', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var out; - var v; - var i; - - buffer = [ 1.0, 2.0 ]; - shape = [ 2 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ i%buffer.length ] = i; - v = out.valueOf(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 07b8b37..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ndarray.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - print_version() - - name = "::instantiation" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float64'); shape = [3, 2]; strides = [2, 1]; offset = 0; order = 'C';" - stmt = "y = np.ndarray(buffer=x, shape=shape, strides=strides, offset=offset, order=order)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::get:data" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.data" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:dtype" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.dtype" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:flags" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.flags" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:length" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.size" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:BYTES_PER_ELEMENT" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.itemsize" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:byteLength" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.nbytes" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:ndims" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.ndim" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:shape" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.shape" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::get:strides" - setup = "import numpy as np; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape);" - stmt = "z = y.strides" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = ":get" - setup = "import numpy as np; from math import floor; from random import random; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape, dtype='float64');" - stmt = "z = y[int(floor(random()*3.0)), 1]" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = ":set" - setup = "import numpy as np; from math import floor; from random import random; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape, dtype='float64');" - stmt = "y[int(floor(random()*3.0)), 1] = random()" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = ":iget" - setup = "import numpy as np; from math import floor; from random import random; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape, dtype='float64');" - stmt = "z = y.item(int(floor(random()*4.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = ":iset" - setup = "import numpy as np; from math import floor; from random import random; shape = [3, 2]; y = np.ndarray(buffer=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), shape=shape, dtype='float64');" - stmt = "y.itemset(int(floor(random()*4.0)), random())" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index be11e2c..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor" -%% click B href "https://github.com/stdlib-js/ndarray-base-ctor/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-ctor/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-ctor/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-ctor/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-ctor/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor -[production-url]: https://github.com/stdlib-js/ndarray-base-ctor/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-ctor/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-ctor/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-ctor/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-ctor/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-ctor/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index af0af6a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict";var l=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var A=l(function(se,w){ -function rt(t,r){return r&&(t===2||t===3)}w.exports=rt -});var R=l(function(ie,N){ -function st(t,r){return r&&(t===1||t===3)}N.exports=st -});var C=l(function(ae,U){ -var it=require('@stdlib/ndarray-base-minmax-view-buffer-index/dist');function at(t,r,n,s,o){var a;return t===0||o===0?!1:(a=it(r,n,s),t===a[1]-a[0]+1)}U.exports=at -});var M=l(function(ne,S){ -function nt(t){return{ROW_MAJOR_CONTIGUOUS:t.ROW_MAJOR_CONTIGUOUS,COLUMN_MAJOR_CONTIGUOUS:t.COLUMN_MAJOR_CONTIGUOUS,READONLY:t.READONLY}}S.exports=nt -});var T=l(function(oe,L){ -var ot=require('@stdlib/ndarray-base-assert-is-column-major-string/dist');function ut(t){var r,n,s,o,a,e;if(s=this._ndims,s===0)return this._accessors?this._buffer.get(this._offset):this._buffer[this._offset];if(this._flags.ROW_MAJOR_CONTIGUOUS||this._flags.COLUMN_MAJOR_CONTIGUOUS){if(this._iterationOrder===1)return this._accessors?this._buffer.get(this._offset+t):this._buffer[this._offset+t];if(this._iterationOrder===-1)return this._accessors?this._buffer.get(this.offset-t):this._buffer[this._offset-t]}if(n=this._shape,r=this._strides,o=this._offset,ot(this._order)){for(e=0;e=0;e--)a=t%n[e],t-=a,t/=n[e],o+=a*r[e];return this._accessors?this._buffer.get(o):this._buffer[o]}L.exports=ut -});var D=l(function(ue,B){ -var ft=require('@stdlib/ndarray-base-assert-is-column-major-string/dist');function ht(t,r){var n,s,o,a,e,i;if(o=this._ndims,o===0)return this._accessors?this._buffer.set(t,this._offset):this._buffer[this._offset]=t,this;if(this._flags.ROW_MAJOR_CONTIGUOUS||this._flags.COLUMN_MAJOR_CONTIGUOUS){if(this._iterationOrder===1)return this._accessors?this._buffer.set(r,this._offset+t):this._buffer[this._offset+t]=r,this;if(this._iterationOrder===-1)return this._accessors?this._buffer.set(r,this._offset-t):this._buffer[this._offset-t]=r,this}if(s=this._shape,n=this._strides,a=this._offset,ft(this._order)){for(i=0;i=0;i--)e=t%s[i],t-=e,t/=s[i],a+=e*n[i];return this._accessors?this._buffer.set(r,a):this._buffer[a]=r,this}B.exports=ht -});var Y=l(function(fe,J){ -function _t(){var t,r;for(t=this._offset,r=0;r=0;e--)a=this.iget(this._length-1-e),t+=b(a)+", "+I(a),e>0&&(t+=", ");else for(e=2;e>=0;e--)t+=this.iget(this._length-1-e),e>0&&(t+=", ")}if(n=yt[this.dtype],s+=dt(n,"{{data}}",t),s+=", ",r===0?s+="[]":s+="[ "+this._shape.join(", ")+" ]",s+=", ",s+="[ ",r===0)s+="0";else for(e=0;e= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\treturn this._buffer.get( ind );\n\t}\n\treturn this._buffer[ ind ];\n}\n\n\n// EXPORTS //\n\nmodule.exports = iget;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' );\n\n\n// MAIN //\n\n/**\n* Sets an array element located a specified linear view index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the first, and only, argument should be the value to set.\n*\n* @private\n* @param {integer} [idx] - linear view index\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*/\nfunction iset( idx, v ) {\n\t/* eslint-disable no-invalid-this */\n\tvar strides;\n\tvar shape;\n\tvar ndims;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = this._ndims;\n\tif ( ndims === 0 ) {\n\t\tif ( this._accessors ) {\n\t\t\tthis._buffer.set( idx, this._offset );\n\t\t} else {\n\t\t\tthis._buffer[ this._offset ] = idx;\n\t\t}\n\t\treturn this;\n\t}\n\tif ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len\n\t\t// Trivial case where we have all positive strides...\n\t\tif ( this._iterationOrder === 1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\tthis._buffer.set( v, this._offset+idx );\n\t\t\t} else {\n\t\t\t\tthis._buffer[ this._offset+idx ] = v;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t\t// Trivial case where we have all negative strides...\n\t\tif ( this._iterationOrder === -1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\tthis._buffer.set( v, this._offset-idx );\n\t\t\t} else {\n\t\t\t\tthis._buffer[ this._offset-idx ] = v;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tshape = this._shape;\n\tstrides = this._strides;\n\tind = this._offset;\n\tif ( isColumnMajor( this._order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\tif ( this._accessors ) {\n\t\t\tthis._buffer.set( v, ind );\n\t\t} else {\n\t\t\tthis._buffer[ ind ] = v;\n\t\t}\n\t\treturn this;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\tthis._buffer.set( v, ind );\n\t} else {\n\t\tthis._buffer[ ind ] = v;\n\t}\n\treturn this;\n}\n\n\n// EXPORTS //\n\nmodule.exports = iset;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Sets an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @private\n* @param {...integer} [idx] - indices\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*/\nfunction set() {\n\t/* eslint-disable no-invalid-this */\n\tvar idx;\n\tvar i;\n\n\tidx = this._offset;\n\tfor ( i = 0; i < arguments.length-1; i++ ) {\n\t\tidx += this._strides[ i ] * arguments[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\tthis._buffer.set( arguments[ i ], idx );\n\t} else {\n\t\tthis._buffer[ idx ] = arguments[ i ];\n\t}\n\treturn this;\n}\n\n\n// EXPORTS //\n\nmodule.exports = set;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @private\n* @param {...integer} idx - indices\n* @returns {*} array element\n*/\nfunction get() {\n\t/* eslint-disable no-invalid-this */\n\tvar idx;\n\tvar i;\n\n\tidx = this._offset;\n\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\tidx += this._strides[ i ] * arguments[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\treturn this._buffer.get( idx );\n\t}\n\treturn this._buffer[ idx ];\n}\n\n\n// EXPORTS //\n\nmodule.exports = get;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Converts an ndarray instance to a primitive value.\n*\n* ## Notes\n*\n* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.\n*\n* @private\n* @returns {(*|ndarray)} result\n*/\nfunction valueOf() { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tif ( this._ndims === 0 ) {\n\t\treturn this.iget();\n\t}\n\treturn this;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar real = require( '@stdlib/complex-float64-real' );\nvar imag = require( '@stdlib/complex-float64-imag' );\n\n\n// MAIN //\n\n/**\n* Serializes an ndarray as a JSON object.\n*\n* ## Notes\n*\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @private\n* @returns {Object} JSON representation\n*/\nfunction toJSON() {\n\t/* eslint-disable no-invalid-this */\n\tvar out;\n\tvar len;\n\tvar v;\n\tvar i;\n\n\tlen = this._length;\n\n\t// Build an object containing all ndarray properties needed to revive a serialized ndarray...\n\tout = {};\n\tout.type = 'ndarray';\n\tout.dtype = this.dtype;\n\tout.flags = {\n\t\t'READONLY': this._flags.READONLY\n\t};\n\tout.order = this._order;\n\tout.shape = this._shape.slice();\n\tout.strides = this._strides.slice();\n\n\t// Flip the signs of negative strides:\n\tfor ( i = 0; i < out.strides.length; i++ ) {\n\t\tif ( out.strides[ i ] < 0 ) {\n\t\t\tout.strides[ i ] *= -1;\n\t\t}\n\t}\n\t// Cast data to generic array...\n\tout.data = [];\n\tif ( out.dtype === 'complex64' || out.dtype === 'complex128' ) {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv = this.iget( i );\n\t\t\tout.data.push( real( v ), imag( v ) );\n\t\t}\n\t} else {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.data.push( this.iget( i ) );\n\t\t}\n\t}\n\treturn out;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nmodule.exports = toJSON;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar real = require( '@stdlib/complex-float64-real' );\nvar imag = require( '@stdlib/complex-float64-imag' );\n\n\n// VARIABLES //\n\nvar CTORS = {\n\t'int8': 'new Int8Array( [ {{data}} ] )',\n\t'uint8': 'new Uint8Array( [ {{data}} ] )',\n\t'uint8c': 'new Uint8ClampedArray( [ {{data}} ] )',\n\t'int16': 'new Int16Array( [ {{data}} ] )',\n\t'uint16': 'new Uint16Array( [ {{data}} ] )',\n\t'int32': 'new Int32Array( [ {{data}} ] )',\n\t'uint32': 'new Uint32Array( [ {{data}} ] )',\n\t'float32': 'new Float32Array( [ {{data}} ] )',\n\t'float64': 'new Float64Array( [ {{data}} ] )',\n\t'generic': '[ {{data}} ]',\n\t'binary': 'new Buffer( [ {{data}} ] )',\n\t'complex64': 'new Complex64Array( [ {{data}} ] )',\n\t'complex128': 'new Complex128Array( [ {{data}} ] )',\n\t'bool': 'new BooleanArray( [ {{data}} ] )'\n};\n\n\n// MAIN //\n\n/**\n* Serializes an ndarray as a string.\n*\n* ## Notes\n*\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @private\n* @returns {string} string representation\n*/\nfunction toString() { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tvar buffer;\n\tvar ndims;\n\tvar ctor;\n\tvar str;\n\tvar dt;\n\tvar v;\n\tvar i;\n\n\tndims = this._shape.length;\n\tdt = this._dtype;\n\n\t// Function to invoke to create an ndarray:\n\tstr = 'ndarray( \\''+dt+'\\', ';\n\n\t// Data buffer parameter...\n\tbuffer = '';\n\tif ( this._length <= 100 ) {\n\t\tif ( dt === 'complex64' || dt === 'complex128' ) {\n\t\t\tfor ( i = 0; i < this._length; i++ ) {\n\t\t\t\tv = this.iget( i );\n\t\t\t\tbuffer += real( v ) + ', ' + imag( v );\n\t\t\t\tif ( i < this._length-1 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < this._length; i++ ) {\n\t\t\t\tbuffer += this.iget( i );\n\t\t\t\tif ( i < this._length-1 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// First three values...\n\t\tif ( dt === 'complex64' || dt === 'complex128' ) {\n\t\t\tfor ( i = 0; i < 3; i++ ) {\n\t\t\t\tv = this.iget( i );\n\t\t\t\tbuffer += real( v ) + ', ' + imag( v );\n\t\t\t\tif ( i < 2 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < 3; i++ ) {\n\t\t\t\tbuffer += this.iget( i );\n\t\t\t\tif ( i < 2 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tbuffer += ', ..., ';\n\n\t\t// Last three values...\n\t\tif ( dt === 'complex64' || dt === 'complex128' ) {\n\t\t\tfor ( i = 2; i >= 0; i-- ) {\n\t\t\t\tv = this.iget( this._length-1-i );\n\t\t\t\tbuffer += real( v ) + ', ' + imag( v );\n\t\t\t\tif ( i > 0 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 2; i >= 0; i-- ) {\n\t\t\t\tbuffer += this.iget( this._length-1-i );\n\t\t\t\tif ( i > 0 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tctor = CTORS[ this.dtype ];\n\tstr += replace( ctor, '{{data}}', buffer );\n\tstr += ', ';\n\n\t// Array shape...\n\tif ( ndims === 0 ) {\n\t\tstr += '[]';\n\t} else {\n\t\tstr += '[ ' + this._shape.join( ', ' ) + ' ]';\n\t}\n\tstr += ', ';\n\n\t// Stride array...\n\tstr += '[ ';\n\tif ( ndims === 0 ) {\n\t\tstr += '0';\n\t} else {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\tif ( this._strides[ i ] < 0 ) {\n\t\t\t\tstr += -this._strides[ i ];\n\t\t\t} else {\n\t\t\t\tstr += this._strides[ i ];\n\t\t\t}\n\t\t\tif ( i < ndims-1 ) {\n\t\t\t\tstr += ', ';\n\t\t\t}\n\t\t}\n\t}\n\tstr += ' ]';\n\tstr += ', ';\n\n\t// Buffer offset:\n\tstr += '0';\n\tstr += ', ';\n\n\t// Order:\n\tstr += '\\'' + this._order + '\\'';\n\n\t// Close the function call:\n\tstr += ' )';\n\treturn str;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nmodule.exports = toString;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar BigInt = require( '@stdlib/bigint-ctor' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// FUNCTIONS //\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @returns {DataView} serialized meta data\n*/\nfunction meta2dataview() {\n\t/* eslint-disable no-invalid-this */\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\tm = this._mode || 'throw';\n\tsm = this._submode || [ m ];\n\tN = this._ndims;\n\tM = sm.length;\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer...\n\tv = this.__meta_dataview__;\n\tif ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be \"stale\" (e.g., shape and/or strides may have changed)\n\t\treturn v;\n\t}\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Retrieve ndarray meta data:\n\tsh = this._shape;\n\tst = this._strides;\n\tdt = this._dtype;\n\tnbytes = this._bytesPerElement;\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( this._offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ this._order ] );\n\n\t// Mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tflgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\t// Cache the serialized meta data:\n\tthis.__meta_dataview__ = v;\n\n\treturn v;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nmodule.exports = meta2dataview;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' );\nvar ArrayBuffer = require( '@stdlib/array-buffer' );\nvar DataView = require( '@stdlib/array-dataview' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar dtypes = require( '@stdlib/ndarray-dtypes' ).enum;\nvar orders = require( '@stdlib/ndarray-orders' ).enum;\nvar modes = require( '@stdlib/ndarray-index-modes' ).enum;\nvar float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign;\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// FUNCTIONS //\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @returns {DataView} serialized meta data\n*/\nfunction meta2dataview() {\n\t/* eslint-disable no-invalid-this */\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\tm = this._mode || 'throw';\n\tsm = this._submode || [ m ];\n\tN = this._ndims;\n\tM = sm.length;\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer...\n\tv = this.__meta_dataview__;\n\tif ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be \"stale\" (e.g., shape and/or strides may have changed)\n\t\treturn v;\n\t}\n\t// Allocate raw memory and create views for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Retrieve ndarray meta data:\n\tsh = this._shape;\n\tst = this._strides;\n\tdt = this._dtype;\n\tnbytes = this._bytesPerElement;\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( this._offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ this._order ] );\n\n\t// Mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tflgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\t// Cache the serialized meta data:\n\tthis.__meta_dataview__ = v;\n\n\treturn v;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nmodule.exports = meta2dataview;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );\nvar iterationOrder = require( '@stdlib/ndarray-base-iteration-order' );\nvar strides2order = require( '@stdlib/ndarray-base-strides2order' );\nvar slice = require( '@stdlib/array-base-slice' );\nvar Boolean = require( '@stdlib/boolean-ctor' );\nvar isColumnMajorContiguous = require( './is_column_major_contiguous.js' );\nvar isRowMajorContiguous = require( './is_row_major_contiguous.js' );\nvar isContiguous = require( './is_contiguous.js' );\nvar copyFlags = require( './copy_flags.js' );\nvar igetValue = require( './iget.js' );\nvar isetValue = require( './iset.js' );\nvar setValue = require( './set.js' );\nvar getValue = require( './get.js' );\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\nvar toJSON = require( './tojson.js' );\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\nvar meta2dataview = require( './meta2dataview.js' );\nvar meta2dataviewPolyfill = require( './meta2dataview.polyfill.js' );\n\n\n// MAIN //\n\n/**\n* ndarray constructor.\n*\n* ## Notes\n*\n* - To create a zero-dimensional array,\n*\n* ```javascript\n* var buffer = [ 1 ];\n* var shape = [];\n* var strides = [ 0 ];\n* var offset = 0;\n*\n* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* ```\n*\n* @constructor\n* @param {string} dtype - data type\n* @param {(ArrayLikeObject|TypedArray|Buffer)} buffer - data buffer\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @param {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*/\nfunction ndarray( dtype, buffer, shape, strides, offset, order ) {\n\tvar contiguous;\n\tvar nbytes;\n\tvar ord;\n\tvar len;\n\tvar i;\n\tif ( !(this instanceof ndarray) ) {\n\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order );\n\t}\n\t// Compute the number of elements...\n\tlen = 1;\n\tfor ( i = 0; i < shape.length; i++ ) {\n\t\tlen *= shape[ i ]; // TODO: consider supporting accessor arrays here\n\t}\n\t// Compute the number of bytes...\n\tif ( buffer.BYTES_PER_ELEMENT ) {\n\t\tnbytes = buffer.BYTES_PER_ELEMENT * len;\n\t} else {\n\t\tnbytes = null;\n\t}\n\t// Set private properties...\n\tthis._byteLength = nbytes;\n\tthis._bytesPerElement = bytesPerElement( dtype );\n\tthis._buffer = buffer;\n\tthis._dtype = dtype;\n\tthis._length = len;\n\tthis._ndims = shape.length;\n\tthis._offset = offset;\n\tthis._order = order;\n\tthis._shape = shape;\n\tthis._strides = strides;\n\tthis._accessors = Boolean( buffer.get && buffer.set );\n\n\tthis._iterationOrder = iterationOrder( strides );\n\n\t// Determine if the array can be stored contiguously:\n\tcontiguous = isContiguous( len, shape, strides, offset, this._iterationOrder ); // eslint-disable-line max-len\n\n\t// Infer the array \"order\" from the stride array (this is supplementary to the `order` parameter):\n\tord = strides2order( strides );\n\n\tthis._flags = {\n\t\t'ROW_MAJOR_CONTIGUOUS': isRowMajorContiguous( ord, contiguous ),\n\t\t'COLUMN_MAJOR_CONTIGUOUS': isColumnMajorContiguous( ord, contiguous ),\n\t\t'READONLY': false\n\t};\n\n\t// Initialize a property for caching serialized meta data:\n\tthis.__meta_dataview__ = null;\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndarray\n* @type {string}\n* @default 'ndarray'\n*\n* @example\n* var str = ndarray.name;\n* // returns 'ndarray'\n*/\nsetReadOnly( ndarray, 'name', 'ndarray' );\n\n/**\n* Size (in bytes) of the array (if known).\n*\n* @name byteLength\n* @memberof ndarray.prototype\n* @type {(NonNegativeInteger|null)}\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n*\n* var byteLength = x.byteLength;\n* // returns 48\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'byteLength', function get() {\n\treturn this._byteLength;\n});\n\n/**\n* Size (in bytes) of each array element (if known).\n*\n* @name BYTES_PER_ELEMENT\n* @memberof ndarray.prototype\n* @type {(PositiveInteger|null)}\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n*\n* var nbytes = x.BYTES_PER_ELEMENT;\n* // returns 8\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'BYTES_PER_ELEMENT', function get() {\n\treturn this._bytesPerElement;\n});\n\n/**\n* Pointer to the underlying data buffer.\n*\n* @name data\n* @memberof ndarray.prototype\n* @type {(Array|TypedArray|Buffer)}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var data = x.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'data', function get() {\n\treturn this._buffer;\n});\n\n/**\n* Underlying data type.\n*\n* @name dtype\n* @memberof ndarray.prototype\n* @type {string}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var dtype = x.dtype;\n* // returns 'generic'\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'dtype', function get() {\n\treturn this._dtype;\n});\n\n/**\n* Meta information, such as information concerning the memory layout of the array.\n*\n* @name flags\n* @memberof ndarray.prototype\n* @type {Object}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var flgs = x.flags;\n* // returns \n*/\nsetReadOnlyAccessor( ndarray.prototype, 'flags', function get() {\n\treturn copyFlags( this._flags );\n});\n\n/**\n* Length of the array.\n*\n* @name length\n* @memberof ndarray.prototype\n* @type {NonNegativeInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var len = x.length;\n* // returns 6\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'length', function get() {\n\treturn this._length;\n});\n\n/**\n* Number of dimensions.\n*\n* @name ndims\n* @memberof ndarray.prototype\n* @type {PositiveInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var ndims = x.ndims;\n* // returns 2\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'ndims', function get() {\n\treturn this._ndims;\n});\n\n/**\n* Index offset which specifies the buffer index at which to start iterating over array elements.\n*\n* @name offset\n* @memberof ndarray.prototype\n* @type {NonNegativeInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var o = x.offset;\n* // returns 0\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'offset', function get() {\n\treturn this._offset;\n});\n\n/**\n* Array order.\n*\n* ## Notes\n*\n* - The array order is either row-major (C-style) or column-major (Fortran-style).\n*\n* @name order\n* @memberof ndarray.prototype\n* @type {string}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var order = x.order;\n* // returns 'row-major'\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'order', function get() {\n\treturn this._order;\n});\n\n/**\n* Shape of the array.\n*\n* @name shape\n* @memberof ndarray.prototype\n* @type {NonNegativeIntegerArray}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var s = x.shape;\n* // returns [ 3, 2 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'shape', function get() {\n\treturn slice( this._shape, 0, this._shape.length );\n});\n\n/**\n* Index strides which specify how to access data along corresponding array dimensions.\n*\n* @name strides\n* @memberof ndarray.prototype\n* @type {IntegerArray}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var s = x.strides;\n* // returns [ 2, 1 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'strides', function get() {\n\treturn slice( this._strides, 0, this._strides.length );\n});\n\n/**\n* Returns an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @name get\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {...integer} [idx] - indices\n* @returns {*} array element\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.get( 1, 1 );\n* // returns 4\n*/\nsetReadOnly( ndarray.prototype, 'get', getValue );\n\n/**\n* Returns an array element located at a specified linear index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided.\n*\n* @name iget\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {integer} [idx] - linear index\n* @returns {*} array element\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.iget( 3 );\n* // returns 4\n*/\nsetReadOnly( ndarray.prototype, 'iget', igetValue );\n\n/**\n* Sets an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @name set\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {...integer} [idx] - indices\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.get( 1, 1 );\n* // returns 4\n*\n* x.set( 1, 1, 10 );\n*\n* var b = x.data;\n* // returns [ 1, 2, 3, 10, 5, 6 ]\n*\n* v = x.get( 1, 1 );\n* // returns 10\n*/\nsetReadOnly( ndarray.prototype, 'set', setValue );\n\n/**\n* Sets an array element located at a specified linear index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the first, and only, argument should be the value to set.\n*\n* @name iset\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {integer} [idx] - linear index\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.iget( 3 );\n* // returns 4\n*\n* x.iset( 3, 10 );\n*\n* var b = x.data;\n* // returns [ 1, 2, 3, 10, 5, 6 ]\n*\n* v = x.iget( 3 );\n* // returns 10\n*/\nsetReadOnly( ndarray.prototype, 'iset', isetValue );\n\n/**\n* Serializes an ndarray as a string.\n*\n* ## Notes\n*\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @name toString\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {string} serialized ndarray\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var str = x.toString();\n* // returns \"ndarray( 'generic', [ 3, 4, 5, 6, 7, 8 ], [ 3, 2 ], [ 2, 1 ], 0, 'row-major' )\"\n*/\nsetReadOnly( ndarray.prototype, 'toString', toString );\n\n/**\n* Serializes an ndarray as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndarray` instance.\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @name toJSON\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {Object} serialized ndarray\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var o = x.toJSON();\n* // e.g., returns { 'type': 'ndarray', 'dtype': 'generic', 'flags': {...}, 'offset': 0, 'order': 'row-major', 'shape': [ 3, 2 ], 'strides': [ 2, 1 ], 'data': [ 3, 4, 5, 6, 7, 8 ] }\n*/\nsetReadOnly( ndarray.prototype, 'toJSON', toJSON );\n\n/**\n* Converts an ndarray instance to a primitive value.\n*\n* ## Notes\n*\n* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.\n*\n* @name valueOf\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {(*|ndarray)} result\n*\n* @example\n* var buffer = [ 3.14 ];\n* var shape = [];\n* var strides = [ 0 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.valueOf();\n* // returns 3.14\n*\n* @example\n* var buffer = [ 3.14 ];\n* var shape = [ 1 ];\n* var strides = [ 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.valueOf();\n* // returns \n*/\nsetReadOnly( ndarray.prototype, 'valueOf', valueOf );\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - Meta data format:\n*\n* ```text\n* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Consumers of this method should treat the returned `DataView` as **immutable**. Otherwise, mutation can invalidate meta data and potentially affect other consumers.\n*\n* @private\n* @name __array_meta_dataview__\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {DataView} serialized meta data\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var dv = x.__array_meta_dataview__();\n* // returns \n*/\nsetReadOnly( ndarray.prototype, '__array_meta_dataview__', ( hasBigIntSupport() ) ? meta2dataview : meta2dataviewPolyfill );\n\n\n// EXPORTS //\n\nmodule.exports = ndarray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Multidimensional array constructor.\n*\n* @module @stdlib/ndarray-base-ctor\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-base-ctor' );\n*\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var out = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "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", - "names": ["require_is_column_major_contiguous", "__commonJSMin", "exports", "module", "isColumnMajorContiguous", "order", "contiguous", "require_is_row_major_contiguous", "__commonJSMin", "exports", "module", "isRowMajorContiguous", "order", "contiguous", "require_is_contiguous", "__commonJSMin", "exports", "module", "minmaxViewBufferIndex", "isContiguous", "len", "shape", "strides", "offset", "iterationOrder", "buf", "require_copy_flags", "__commonJSMin", "exports", "module", "copyFlags", "flags", "require_iget", "__commonJSMin", "exports", "module", "isColumnMajor", "iget", "idx", "strides", "shape", "ndims", "ind", "s", "i", "require_iset", "__commonJSMin", "exports", "module", "isColumnMajor", "iset", "idx", "v", "strides", "shape", "ndims", "ind", "s", "require_set", "__commonJSMin", "exports", "module", "set", "idx", "i", "require_get", "__commonJSMin", "exports", "module", "get", "idx", "i", "require_valueof", "__commonJSMin", "exports", "module", "valueOf", "require_tojson", "__commonJSMin", "exports", "module", "real", "imag", "toJSON", "out", "len", "v", "i", "require_tostring", "__commonJSMin", "exports", "module", "replace", "real", "imag", "CTORS", "toString", "buffer", "ndims", "ctor", "str", "dt", "v", "i", "require_meta2dataview", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "BigInt", "dtypes", "orders", "modes", "DTYPES", "ORDERS", "MODES", "meta2dataview", "nbytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_meta2dataview_polyfill", "__commonJSMin", "exports", "module", "IS_LITTLE_ENDIAN", "ArrayBuffer", "DataView", "Uint8Array", "dtypes", "orders", "modes", "float64ToInt64Bytes", "DTYPES", "ORDERS", "MODES", "meta2dataview", "nbytes", "bytes", "flgs", "len", "dt", "sh", "st", "sm", "v", "m", "o", "s", "N", "M", "i", "require_main", "__commonJSMin", "exports", "module", "hasBigIntSupport", "setReadOnly", "setReadOnlyAccessor", "bytesPerElement", "iterationOrder", "strides2order", "slice", "Boolean", "isColumnMajorContiguous", "isRowMajorContiguous", "isContiguous", "copyFlags", "igetValue", "isetValue", "setValue", "getValue", "valueOf", "toJSON", "toString", "meta2dataview", "meta2dataviewPolyfill", "ndarray", "dtype", "buffer", "shape", "strides", "offset", "order", "contiguous", "nbytes", "ord", "len", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index ba02ec0..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,445 +0,0 @@ - -{{alias}}( dtype, buffer, shape, strides, offset, order ) - Returns an ndarray. - - Parameters - ---------- - dtype: string - Underlying data type. - - buffer: ArrayLikeObject|TypedArray|Buffer - Data buffer. A data buffer must be an array-like object (i.e., have a - `length` property). For data buffers which are not indexed collections - (i.e., collections which cannot support direct index access, such as - `buffer[ index ]`; e.g., Complex64Array, Complex128Array, etc), a data - buffer should provide `#.get( idx )` and `#.set( v[, idx] )` methods. - Note that, for `set` methods, the value to set should be the first - argument, followed by the linear index, similar to the native typed - array `set` method. - - shape: ArrayLikeObject - Array shape. - - strides: ArrayLikeObject - Array strides. - - offset: integer - Index offset. - - order: string - Specifies whether an array is row-major (C-style) or column-major - (Fortran-style). - - Returns - ------- - ndarray: ndarray - ndarray instance. - - Examples - -------- - // Create a new instance... - > var b = [ 1, 2, 3, 4 ]; // underlying data buffer - > var d = [ 2, 2 ]; // shape - > var s = [ 2, 1 ]; // strides - > var o = 0; // index offset - > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4 - - // Set an element using subscripts: - > arr.set( 1, 1, 40 ); - > arr.get( 1, 1 ) - 40 - - // Set an element using a linear index: - > arr.iset( 3, 99 ); - > arr.get( 1, 1 ) - 99 - - -{{alias}}.prototype.byteLength - Size (in bytes) of the array (if known). - - Returns - ------- - size: integer|null - Size (in bytes) of the array. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var sz = arr.byteLength - 32 - - -{{alias}}.prototype.BYTES_PER_ELEMENT - Size (in bytes) of each array element (if known). - - Returns - ------- - size: integer|null - Size (in bytes) of each array element. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var sz = arr.BYTES_PER_ELEMENT - 8 - - -{{alias}}.prototype.data - Pointer to the underlying data buffer. - - Returns - ------- - buf: ArrayLikeObject|TypedArray|Buffer - Underlying data buffer. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var buf = arr.data - [ 1.0, 2.0, 3.0, 4.0 ] - - -{{alias}}.prototype.dtype - Underlying data type. - - Returns - ------- - dtype: string - Underlying data type. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var dt = arr.dtype - 'float64' - - -{{alias}}.prototype.flags - Meta information, such as information concerning the memory layout of the - array. - - Returns - ------- - flags: Object - Info object. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var fl = arr.flags - {...} - - -{{alias}}.prototype.length - Length of the array (i.e., number of elements). - - Returns - ------- - len: integer - Array length. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var len = arr.length - 4 - - -{{alias}}.prototype.ndims - Number of dimensions. - - Returns - ------- - ndims: integer - Number of dimensions. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var n = arr.ndims - 2 - - -{{alias}}.prototype.offset - Index offset which specifies the buffer index at which to start iterating - over array elements. - - Returns - ------- - offset: integer - Index offset. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var v = arr.offset - 0 - - -{{alias}}.prototype.order: string - Array order. - - The array order is either row-major (C-style) or column-major (Fortran- - style). - - Returns - ------- - order: string - Array order. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var ord = arr.order - 'row-major' - - -{{alias}}.prototype.shape - Array shape. - - Returns - ------- - shape: Array - Array shape. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var sh = arr.shape - [ 2, 2 ] - - -{{alias}}.prototype.strides - Index strides which specify how to access data along corresponding array - dimensions. - - Returns - ------- - strides: Array - Index strides. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var st = arr.strides - [ 2, 1 ] - - -{{alias}}.prototype.get( ...idx ) - Returns an array element specified according to provided subscripts. - - The number of provided subscripts should equal the number of dimensions. - - For zero-dimensional arrays, no indices should be provided. - - Parameters - ---------- - idx: ...integer - Subscripts. - - Returns - ------- - out: any - Array element. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var v = arr.get( 1, 1 ) - 4.0 - - -{{alias}}.prototype.iget( idx ) - Returns an array element located at a specified linear index. - - For zero-dimensional arrays, the input argument is ignored and, for clarity, - should not be provided. - - Parameters - ---------- - idx: integer - Linear index. - - Returns - ------- - out: any - Array element. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > var v = arr.iget( 3 ) - 4.0 - - -{{alias}}.prototype.set( ...idx, v ) - Sets an array element specified according to provided subscripts. - - The number of provided subscripts should equal the number of dimensions. - - For zero-dimensional arrays, no indices should be provided. - - Parameters - ---------- - idx: ...integer - Subscripts. - - v: any - Value to set. - - Returns - ------- - out: ndarray - ndarray instance. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > arr.set( 1, 1, -4.0 ); - > arr.get( 1, 1 ) - -4.0 - - -{{alias}}.prototype.iset( idx, v ) - Sets an array element located at a specified linear index. - - For zero-dimensional arrays, the first, and only, argument should be the - value to set. - - Parameters - ---------- - idx: integer - Linear index. - - v: any - Value to set. - - Returns - ------- - out: ndarray - ndarray instance. - - Examples - -------- - > var b = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'float64', b, d, s, o, 'row-major' ); - > arr.iset( 3, -4.0 ); - > arr.iget( 3 ) - -4.0 - - -{{alias}}.prototype.toString() - Serializes an ndarray as a string. - - This method does **not** serialize data outside of the buffer region defined - by the array configuration. - - Returns - ------- - str: string - Serialized ndarray string. - - Examples - -------- - > var b = [ 1, 2, 3, 4 ]; - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ); - > arr.toString() - '...' - - -{{alias}}.prototype.toJSON() - Serializes an ndarray as a JSON object. - - This method does **not** serialize data outside of the buffer region defined - by the array configuration. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var b = [ 1, 2, 3, 4 ]; - > var d = [ 2, 2 ]; - > var s = [ 2, 1 ]; - > var o = 0; - > var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' ); - > arr.toJSON() - {...} - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1f2b6f4..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,141 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 ndarray = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); // $ExpectType ndarray - new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); // $ExpectType ndarray - - const buffer = new Int32Array( [ 1, 2, 3 ] ); - ndarray( 'int32', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); // $ExpectType ndarray - new ndarray( 'int32', buffer, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not a recognized data type... -{ - const buffer = [ 1, 2, 3, 4 ]; - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - - ndarray( 'abc', buffer, shape, strides, offset, order ); // $ExpectError - ndarray( 123, buffer, shape, strides, offset, order ); // $ExpectError - ndarray( true, buffer, shape, strides, offset, order ); // $ExpectError - ndarray( false, buffer, shape, strides, offset, order ); // $ExpectError - ndarray( null, buffer, shape, strides, offset, order ); // $ExpectError - ndarray( undefined, buffer, shape, strides, offset, order ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object or buffer... -{ - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float64', 123, shape, strides, offset, order ); // $ExpectError - ndarray( 'float64', true, shape, strides, offset, order ); // $ExpectError - ndarray( 'float64', false, shape, strides, offset, order ); // $ExpectError - ndarray( 'float64', null, shape, strides, offset, order ); // $ExpectError - ndarray( 'float64', undefined, shape, strides, offset, order ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object containing numbers... -{ - const buffer = [ 1, 2, 3, 4 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float64', buffer, true, strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, false, strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, null, strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, undefined, strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, '5', strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, [ '1', '2' ], strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, {}, strides, offset, order ); // $ExpectError - ndarray( 'float64', buffer, ( x: number ): number => x, strides, offset, order ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an array-like object containing numbers... -{ - const buffer = [ 1, 2, 3, 4 ]; - const shape = [ 2, 2 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float32', buffer, shape, true, offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, false, offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, null, offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, undefined, offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, '5', offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, [ '1', '2' ], offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, {}, offset, order ); // $ExpectError - ndarray( 'float32', buffer, shape, ( x: number ): number => x, offset, order ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const buffer = [ 1, 2, 3, 4 ]; - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const order = 'row-major'; - ndarray( 'int32', buffer, shape, strides, true, order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, false, order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, null, order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, undefined, order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, '5', order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, [ '1', '2' ], order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, {}, order ); // $ExpectError - ndarray( 'int32', buffer, shape, strides, ( x: number ): number => x, order ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a known array order... -{ - const buffer = [ 1, 2, 3, 4 ]; - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - ndarray( 'int8', buffer, shape, strides, offset, true ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, false ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, null ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, undefined ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, '5' ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, [ '1', '2' ] ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, {} ); // $ExpectError - ndarray( 'int8', buffer, shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - const buffer = [ 1, 2, 3, 4 ]; - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - ndarray(); // $ExpectError - ndarray( 'uint32' ); // $ExpectError - ndarray( 'int8', buffer ); // $ExpectError - ndarray( 'uint8c', buffer, shape ); // $ExpectError - ndarray( 'uint8', buffer, shape, strides ); // $ExpectError - ndarray( 'uint16', buffer, shape, strides, offset ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index afbf4fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float32Array = require( '@stdlib/array-float32' ); -var ndarray = require( './../lib' ); - -// Create a data buffer: -var buffer = new Float32Array( (3*3*3*3) + 100 ); - -// Specify the array shape: -var shape = [ 3, 3, 3, 3 ]; - -// Specify the array strides: -var strides = [ 27, 9, 3, 1 ]; - -// Specify the index offset: -var offset = 4; - -// Specify the order: -var order = 'row-major'; // C-style - -// Create a new ndarray: -var arr = ndarray( 'float32', buffer, shape, strides, offset, order ); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// e.g., => '{"type":"ndarray","dtype":"float32","flags":{"READONLY":false},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 02934fb..ea30ce8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray, DataType, Order, Shape, Strides } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5dae1cb --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-bigint-support@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-bytes-per-element@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-iteration-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-slice@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/boolean-ctor@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-minmax-view-buffer-index@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-float64-real@v0.1.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-float64-imag@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-replace@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-little-endian@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dataview@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/bigint-ctor@v0.2.2-esm/index.mjs";import{enum as g}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtypes@v0.3.0-esm/index.mjs";import{enum as b}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-orders@v0.2.2-esm/index.mjs";import{enum as y}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index-modes@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-uint8@v0.2.2-esm/index.mjs";import{assign as v}from"https://cdn.jsdelivr.net/gh/stdlib-js/number-float64-base-to-int64-bytes@v0.2.2-esm/index.mjs";function O(t,s){return s&&(2===t||3===t)}function x(t,s){return s&&(1===t||3===t)}var I={int8:"new Int8Array( [ {{data}} ] )",uint8:"new Uint8Array( [ {{data}} ] )",uint8c:"new Uint8ClampedArray( [ {{data}} ] )",int16:"new Int16Array( [ {{data}} ] )",uint16:"new Uint16Array( [ {{data}} ] )",int32:"new Int32Array( [ {{data}} ] )",uint32:"new Uint32Array( [ {{data}} ] )",float32:"new Float32Array( [ {{data}} ] )",float64:"new Float64Array( [ {{data}} ] )",generic:"[ {{data}} ]",binary:"new Buffer( [ {{data}} ] )",complex64:"new Complex64Array( [ {{data}} ] )",complex128:"new Complex128Array( [ {{data}} ] )",bool:"new BooleanArray( [ {{data}} ] )"};var w=g(),A=b(),U=y();var E=g(),N=b(),R=y();function L(t,s,e,h,a,d){var _,m,l,p,u;if(!(this instanceof L))return new L(t,s,e,h,a,d);for(p=1,u=0;u=0;h--)t-=n=t%e[h],t/=e[h],r+=n*s[h];return this._accessors?this._buffer.get(r):this._buffer[r]})),s(L.prototype,"set",(function(){var t,s;for(t=this._offset,s=0;s=0;o--)t-=h=t%i[o],t/=i[o],n+=h*e[o];return this._accessors?this._buffer.set(s,n):this._buffer[n]=s,this})),s(L.prototype,"toString",(function(){var t,s,e,i,r,n,h;if(s=this._shape.length,i="ndarray( '"+(r=this._dtype)+"', ",t="",this._length<=100)if("complex64"===r||"complex128"===r)for(h=0;h=0;h--)n=this.iget(this._length-1-h),t+=d(n)+", "+_(n),h>0&&(t+=", ");else for(h=2;h>=0;h--)t+=this.iget(this._length-1-h),h>0&&(t+=", ")}if(e=I[this.dtype],i+=m(e,"{{data}}",t),i+=", ",i+=0===s?"[]":"[ "+this._shape.join(", ")+" ]",i+=", ",i+="[ ",0===s)i+="0";else for(h=0;h= 0; i-- ) {\n\t\t\t\tv = this.iget( this._length-1-i );\n\t\t\t\tbuffer += real( v ) + ', ' + imag( v );\n\t\t\t\tif ( i > 0 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 2; i >= 0; i-- ) {\n\t\t\t\tbuffer += this.iget( this._length-1-i );\n\t\t\t\tif ( i > 0 ) {\n\t\t\t\t\tbuffer += ', ';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tctor = CTORS[ this.dtype ];\n\tstr += replace( ctor, '{{data}}', buffer );\n\tstr += ', ';\n\n\t// Array shape...\n\tif ( ndims === 0 ) {\n\t\tstr += '[]';\n\t} else {\n\t\tstr += '[ ' + this._shape.join( ', ' ) + ' ]';\n\t}\n\tstr += ', ';\n\n\t// Stride array...\n\tstr += '[ ';\n\tif ( ndims === 0 ) {\n\t\tstr += '0';\n\t} else {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\tif ( this._strides[ i ] < 0 ) {\n\t\t\t\tstr += -this._strides[ i ];\n\t\t\t} else {\n\t\t\t\tstr += this._strides[ i ];\n\t\t\t}\n\t\t\tif ( i < ndims-1 ) {\n\t\t\t\tstr += ', ';\n\t\t\t}\n\t\t}\n\t}\n\tstr += ' ]';\n\tstr += ', ';\n\n\t// Buffer offset:\n\tstr += '0';\n\tstr += ', ';\n\n\t// Order:\n\tstr += '\\'' + this._order + '\\'';\n\n\t// Close the function call:\n\tstr += ' )';\n\treturn str;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nexport default toString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport DataView from '@stdlib/array-dataview';\nimport BigInt from '@stdlib/bigint-ctor';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// FUNCTIONS //\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @returns {DataView} serialized meta data\n*/\nfunction meta2dataview() {\n\t/* eslint-disable no-invalid-this */\n\tvar nbytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\tm = this._mode || 'throw';\n\tsm = this._submode || [ m ];\n\tN = this._ndims;\n\tM = sm.length;\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer...\n\tv = this.__meta_dataview__;\n\tif ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be \"stale\" (e.g., shape and/or strides may have changed)\n\t\treturn v;\n\t}\n\t// Allocate raw memory and create a view for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\n\t// Retrieve ndarray meta data:\n\tsh = this._shape;\n\tst = this._strides;\n\tdt = this._dtype;\n\tnbytes = this._bytesPerElement;\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tv.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN );\n\t\tv.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tv.setBigInt64( o, BigInt( this._offset*nbytes ), IS_LITTLE_ENDIAN );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ this._order ] );\n\n\t// Mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tv.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tflgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\t// Cache the serialized meta data:\n\tthis.__meta_dataview__ = v;\n\n\treturn v;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nexport default meta2dataview;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport IS_LITTLE_ENDIAN from '@stdlib/assert-is-little-endian';\nimport ArrayBuffer from '@stdlib/array-buffer';\nimport DataView from '@stdlib/array-dataview';\nimport Uint8Array from '@stdlib/array-uint8';\nimport { enum as dtypes } from '@stdlib/ndarray-dtypes';\nimport { enum as orders } from '@stdlib/ndarray-orders';\nimport { enum as modes } from '@stdlib/ndarray-index-modes';\nimport { assign as float64ToInt64Bytes } from '@stdlib/number-float64-base-to-int64-bytes';\n\n\n// VARIABLES //\n\nvar DTYPES = dtypes();\nvar ORDERS = orders();\nvar MODES = modes();\n\n\n// FUNCTIONS //\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - This function takes into account ndarray-like objects which may support index modes.\n*\n* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Meta data format:\n*\n* ```text\n* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* which translates to the following `ArrayBuffer` layout:\n*\n* ```text\n* ArrayBuffer[\n* [int8],\n* [int16],\n* [int64],\n* [ndims*int64],\n* [ndims*int64],\n* [int64],\n* [int8],\n* [int8],\n* [int64],\n* [nsubmodes*int8],\n* [int32]\n* ]\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Buffer length:\n*\n* ```text\n* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes\n* ```\n*\n* For example, consider a three-dimensional ndarray with one subscript index mode (submode):\n*\n* ```text\n* 33 + (3*16) + 1 = 82 bytes\n* ```\n*\n* - Views:\n*\n* - endianness: `Int8Array( buf, 0, 1 )`\n* - dtype: `Int16Array( buf, 1, 1 )`\n* - ndims: `Int64Array( buf, 3, 1 )`\n* - shape: `Int64Array( buf, 11, ndims )`\n* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`\n* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`\n* - order: `Int8Array( buf, 19+(ndims*16), 1 )`\n* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`\n* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`\n* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`\n* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )`\n*\n* @private\n* @returns {DataView} serialized meta data\n*/\nfunction meta2dataview() {\n\t/* eslint-disable no-invalid-this */\n\tvar nbytes;\n\tvar bytes;\n\tvar flgs;\n\tvar len;\n\tvar dt;\n\tvar sh;\n\tvar st;\n\tvar sm;\n\tvar v;\n\tvar m;\n\tvar o;\n\tvar s;\n\tvar N;\n\tvar M;\n\tvar i;\n\n\tm = this._mode || 'throw';\n\tsm = this._submode || [ m ];\n\tN = this._ndims;\n\tM = sm.length;\n\n\t// Compute the amount of memory we need to allocate for storing meta data:\n\tlen = 33 + (N*16) + M;\n\n\t// Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer...\n\tv = this.__meta_dataview__;\n\tif ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be \"stale\" (e.g., shape and/or strides may have changed)\n\t\treturn v;\n\t}\n\t// Allocate raw memory and create views for interfacing with the allocated memory:\n\tv = new DataView( new ArrayBuffer( len ) );\n\tbytes = new Uint8Array( v.buffer );\n\n\t// Retrieve ndarray meta data:\n\tsh = this._shape;\n\tst = this._strides;\n\tdt = this._dtype;\n\tnbytes = this._bytesPerElement;\n\n\t// Endianness: (byteoffset: 0; bytelength: 1)\n\to = 0;\n\tv.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 );\n\n\t// Data type: (byteoffset: 1; bytelength: 2)\n\to += 1;\n\tv.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN );\n\n\t// Number of dimensions: (byteoffset: 3; bytelength: 8)\n\to += 2;\n\tfloat64ToInt64Bytes( N, bytes, 1, o );\n\n\t// Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total)\n\ts = N * 8; // stride length between a dimension (shape[i]) and its associated stride\n\to += 8;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tfloat64ToInt64Bytes( sh[i], bytes, 1, o );\n\t\tfloat64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s );\n\t\to += 8;\n\t}\n\t// Offset: (byteoffset: 11+(ndims*16); bytelength: 8)\n\to += s;\n\tfloat64ToInt64Bytes( this._offset*nbytes, bytes, 1, o );\n\n\t// Order: (byteoffset: 19+(ndims*16); bytelength: 1)\n\to += 8;\n\tv.setInt8( o, ORDERS[ this._order ] );\n\n\t// Mode: (byteoffset: 20+(ndims*16); bytelength: 1)\n\to += 1;\n\tv.setInt8( o, MODES[ m ] );\n\n\t// Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8)\n\to += 1;\n\tfloat64ToInt64Bytes( M, bytes, 1, o );\n\n\t// Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1)\n\to += 8;\n\tfor ( i = 0; i < M; i++ ) {\n\t\tv.setInt8( o, MODES[ sm[i] ] );\n\t\to += 1;\n\t}\n\t// Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4)\n\tflgs = 0|0;\n\tflgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100\n\tv.setInt32( o, flgs, IS_LITTLE_ENDIAN );\n\n\t// Cache the serialized meta data:\n\tthis.__meta_dataview__ = v;\n\n\treturn v;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nexport default meta2dataview;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport hasBigIntSupport from '@stdlib/assert-has-bigint-support';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport bytesPerElement from '@stdlib/ndarray-base-bytes-per-element';\nimport iterationOrder from '@stdlib/ndarray-base-iteration-order';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport slice from '@stdlib/array-base-slice';\nimport Boolean from '@stdlib/boolean-ctor';\nimport isColumnMajorContiguous from './is_column_major_contiguous.js';\nimport isRowMajorContiguous from './is_row_major_contiguous.js';\nimport isContiguous from './is_contiguous.js';\nimport copyFlags from './copy_flags.js';\nimport igetValue from './iget.js';\nimport isetValue from './iset.js';\nimport setValue from './set.js';\nimport getValue from './get.js';\nimport valueOf from './valueof.js'; // eslint-disable-line stdlib/no-redeclare\nimport toJSON from './tojson.js';\nimport toString from './tostring.js'; // eslint-disable-line stdlib/no-redeclare\nimport meta2dataview from './meta2dataview.js';\nimport meta2dataviewPolyfill from './meta2dataview.polyfill.js';\n\n\n// MAIN //\n\n/**\n* ndarray constructor.\n*\n* ## Notes\n*\n* - To create a zero-dimensional array,\n*\n* ```javascript\n* var buffer = [ 1 ];\n* var shape = [];\n* var strides = [ 0 ];\n* var offset = 0;\n*\n* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n* ```\n*\n* @constructor\n* @param {string} dtype - data type\n* @param {(ArrayLikeObject|TypedArray|Buffer)} buffer - data buffer\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @param {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*/\nfunction ndarray( dtype, buffer, shape, strides, offset, order ) {\n\tvar contiguous;\n\tvar nbytes;\n\tvar ord;\n\tvar len;\n\tvar i;\n\tif ( !(this instanceof ndarray) ) {\n\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order );\n\t}\n\t// Compute the number of elements...\n\tlen = 1;\n\tfor ( i = 0; i < shape.length; i++ ) {\n\t\tlen *= shape[ i ]; // TODO: consider supporting accessor arrays here\n\t}\n\t// Compute the number of bytes...\n\tif ( buffer.BYTES_PER_ELEMENT ) {\n\t\tnbytes = buffer.BYTES_PER_ELEMENT * len;\n\t} else {\n\t\tnbytes = null;\n\t}\n\t// Set private properties...\n\tthis._byteLength = nbytes;\n\tthis._bytesPerElement = bytesPerElement( dtype );\n\tthis._buffer = buffer;\n\tthis._dtype = dtype;\n\tthis._length = len;\n\tthis._ndims = shape.length;\n\tthis._offset = offset;\n\tthis._order = order;\n\tthis._shape = shape;\n\tthis._strides = strides;\n\tthis._accessors = Boolean( buffer.get && buffer.set );\n\n\tthis._iterationOrder = iterationOrder( strides );\n\n\t// Determine if the array can be stored contiguously:\n\tcontiguous = isContiguous( len, shape, strides, offset, this._iterationOrder ); // eslint-disable-line max-len\n\n\t// Infer the array \"order\" from the stride array (this is supplementary to the `order` parameter):\n\tord = strides2order( strides );\n\n\tthis._flags = {\n\t\t'ROW_MAJOR_CONTIGUOUS': isRowMajorContiguous( ord, contiguous ),\n\t\t'COLUMN_MAJOR_CONTIGUOUS': isColumnMajorContiguous( ord, contiguous ),\n\t\t'READONLY': false\n\t};\n\n\t// Initialize a property for caching serialized meta data:\n\tthis.__meta_dataview__ = null;\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndarray\n* @type {string}\n* @default 'ndarray'\n*\n* @example\n* var str = ndarray.name;\n* // returns 'ndarray'\n*/\nsetReadOnly( ndarray, 'name', 'ndarray' );\n\n/**\n* Size (in bytes) of the array (if known).\n*\n* @name byteLength\n* @memberof ndarray.prototype\n* @type {(NonNegativeInteger|null)}\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n*\n* var byteLength = x.byteLength;\n* // returns 48\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'byteLength', function get() {\n\treturn this._byteLength;\n});\n\n/**\n* Size (in bytes) of each array element (if known).\n*\n* @name BYTES_PER_ELEMENT\n* @memberof ndarray.prototype\n* @type {(PositiveInteger|null)}\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );\n*\n* var nbytes = x.BYTES_PER_ELEMENT;\n* // returns 8\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'BYTES_PER_ELEMENT', function get() {\n\treturn this._bytesPerElement;\n});\n\n/**\n* Pointer to the underlying data buffer.\n*\n* @name data\n* @memberof ndarray.prototype\n* @type {(Array|TypedArray|Buffer)}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var data = x.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'data', function get() {\n\treturn this._buffer;\n});\n\n/**\n* Underlying data type.\n*\n* @name dtype\n* @memberof ndarray.prototype\n* @type {string}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var dtype = x.dtype;\n* // returns 'generic'\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'dtype', function get() {\n\treturn this._dtype;\n});\n\n/**\n* Meta information, such as information concerning the memory layout of the array.\n*\n* @name flags\n* @memberof ndarray.prototype\n* @type {Object}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var flgs = x.flags;\n* // returns \n*/\nsetReadOnlyAccessor( ndarray.prototype, 'flags', function get() {\n\treturn copyFlags( this._flags );\n});\n\n/**\n* Length of the array.\n*\n* @name length\n* @memberof ndarray.prototype\n* @type {NonNegativeInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var len = x.length;\n* // returns 6\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'length', function get() {\n\treturn this._length;\n});\n\n/**\n* Number of dimensions.\n*\n* @name ndims\n* @memberof ndarray.prototype\n* @type {PositiveInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var ndims = x.ndims;\n* // returns 2\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'ndims', function get() {\n\treturn this._ndims;\n});\n\n/**\n* Index offset which specifies the buffer index at which to start iterating over array elements.\n*\n* @name offset\n* @memberof ndarray.prototype\n* @type {NonNegativeInteger}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var o = x.offset;\n* // returns 0\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'offset', function get() {\n\treturn this._offset;\n});\n\n/**\n* Array order.\n*\n* ## Notes\n*\n* - The array order is either row-major (C-style) or column-major (Fortran-style).\n*\n* @name order\n* @memberof ndarray.prototype\n* @type {string}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var order = x.order;\n* // returns 'row-major'\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'order', function get() {\n\treturn this._order;\n});\n\n/**\n* Shape of the array.\n*\n* @name shape\n* @memberof ndarray.prototype\n* @type {NonNegativeIntegerArray}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var s = x.shape;\n* // returns [ 3, 2 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'shape', function get() {\n\treturn slice( this._shape, 0, this._shape.length );\n});\n\n/**\n* Index strides which specify how to access data along corresponding array dimensions.\n*\n* @name strides\n* @memberof ndarray.prototype\n* @type {IntegerArray}\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var s = x.strides;\n* // returns [ 2, 1 ]\n*/\nsetReadOnlyAccessor( ndarray.prototype, 'strides', function get() {\n\treturn slice( this._strides, 0, this._strides.length );\n});\n\n/**\n* Returns an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @name get\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {...integer} [idx] - indices\n* @returns {*} array element\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.get( 1, 1 );\n* // returns 4\n*/\nsetReadOnly( ndarray.prototype, 'get', getValue );\n\n/**\n* Returns an array element located at a specified linear index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided.\n*\n* @name iget\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {integer} [idx] - linear index\n* @returns {*} array element\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.iget( 3 );\n* // returns 4\n*/\nsetReadOnly( ndarray.prototype, 'iget', igetValue );\n\n/**\n* Sets an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @name set\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {...integer} [idx] - indices\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.get( 1, 1 );\n* // returns 4\n*\n* x.set( 1, 1, 10 );\n*\n* var b = x.data;\n* // returns [ 1, 2, 3, 10, 5, 6 ]\n*\n* v = x.get( 1, 1 );\n* // returns 10\n*/\nsetReadOnly( ndarray.prototype, 'set', setValue );\n\n/**\n* Sets an array element located at a specified linear index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the first, and only, argument should be the value to set.\n*\n* @name iset\n* @memberof ndarray.prototype\n* @type {Function}\n* @param {integer} [idx] - linear index\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.iget( 3 );\n* // returns 4\n*\n* x.iset( 3, 10 );\n*\n* var b = x.data;\n* // returns [ 1, 2, 3, 10, 5, 6 ]\n*\n* v = x.iget( 3 );\n* // returns 10\n*/\nsetReadOnly( ndarray.prototype, 'iset', isetValue );\n\n/**\n* Serializes an ndarray as a string.\n*\n* ## Notes\n*\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @name toString\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {string} serialized ndarray\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var str = x.toString();\n* // returns \"ndarray( 'generic', [ 3, 4, 5, 6, 7, 8 ], [ 3, 2 ], [ 2, 1 ], 0, 'row-major' )\"\n*/\nsetReadOnly( ndarray.prototype, 'toString', toString );\n\n/**\n* Serializes an ndarray as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndarray` instance.\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @name toJSON\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {Object} serialized ndarray\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var o = x.toJSON();\n* // e.g., returns { 'type': 'ndarray', 'dtype': 'generic', 'flags': {...}, 'offset': 0, 'order': 'row-major', 'shape': [ 3, 2 ], 'strides': [ 2, 1 ], 'data': [ 3, 4, 5, 6, 7, 8 ] }\n*/\nsetReadOnly( ndarray.prototype, 'toJSON', toJSON );\n\n/**\n* Converts an ndarray instance to a primitive value.\n*\n* ## Notes\n*\n* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.\n*\n* @name valueOf\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {(*|ndarray)} result\n*\n* @example\n* var buffer = [ 3.14 ];\n* var shape = [];\n* var strides = [ 0 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.valueOf();\n* // returns 3.14\n*\n* @example\n* var buffer = [ 3.14 ];\n* var shape = [ 1 ];\n* var strides = [ 1 ];\n* var offset = 0;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var v = x.valueOf();\n* // returns \n*/\nsetReadOnly( ndarray.prototype, 'valueOf', valueOf );\n\n/**\n* Serializes ndarray meta data to a `DataView`.\n*\n* ## Notes\n*\n* - Meta data format:\n*\n* ```text\n* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) |\n* ```\n*\n* where `strides` and `offset` are in units of bytes.\n*\n* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.\n*\n* - Serialization is performed according to host byte order (endianness).\n*\n* - Consumers of this method should treat the returned `DataView` as **immutable**. Otherwise, mutation can invalidate meta data and potentially affect other consumers.\n*\n* @private\n* @name __array_meta_dataview__\n* @memberof ndarray.prototype\n* @type {Function}\n* @returns {DataView} serialized meta data\n*\n* @example\n* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ];\n* var shape = [ 3, 2 ];\n* var strides = [ 2, 1 ];\n* var offset = 2;\n*\n* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );\n*\n* var dv = x.__array_meta_dataview__();\n* // returns \n*/\nsetReadOnly( ndarray.prototype, '__array_meta_dataview__', ( hasBigIntSupport() ) ? meta2dataview : meta2dataviewPolyfill );\n\n\n// EXPORTS //\n\nexport default ndarray;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport minmaxViewBufferIndex from '@stdlib/ndarray-base-minmax-view-buffer-index';\n\n\n// MAIN //\n\n/**\n* Determines if an array is contiguous.\n*\n* @private\n* @param {NonNegativeInteger} len - array length\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - index offset\n* @param {integer} iterationOrder - iteration order\n* @returns {boolean} boolean indicating if an array is contiguous\n*/\nfunction isContiguous( len, shape, strides, offset, iterationOrder ) {\n\tvar buf;\n\n\t// If an array does not contain any elements, then no data to store, and, if the array is unordered, adjacent array elements are not guaranteed to be stored next to each other.\n\tif ( len === 0 || iterationOrder === 0 ) {\n\t\treturn false;\n\t}\n\t// Ensure that the array is compatible with a single memory segment:\n\tbuf = minmaxViewBufferIndex( shape, strides, offset );\n\treturn ( len === ( buf[1]-buf[0]+1 ) );\n}\n\n\n// EXPORTS //\n\nexport default isContiguous;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Copies ndarray flags.\n*\n* @private\n* @param {Object} flags - flags\n* @returns {Object} copy of input object\n*/\nfunction copyFlags( flags ) {\n\treturn {\n\t\t'ROW_MAJOR_CONTIGUOUS': flags.ROW_MAJOR_CONTIGUOUS,\n\t\t'COLUMN_MAJOR_CONTIGUOUS': flags.COLUMN_MAJOR_CONTIGUOUS,\n\t\t'READONLY': flags.READONLY\n\t};\n}\n\n\n// EXPORTS //\n\nexport default copyFlags;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @private\n* @param {...integer} idx - indices\n* @returns {*} array element\n*/\nfunction get() {\n\t/* eslint-disable no-invalid-this */\n\tvar idx;\n\tvar i;\n\n\tidx = this._offset;\n\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\tidx += this._strides[ i ] * arguments[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\treturn this._buffer.get( idx );\n\t}\n\treturn this._buffer[ idx ];\n}\n\n\n// EXPORTS //\n\nexport default get;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\n\n\n// MAIN //\n\n/**\n* Returns an array element located a specified linear view index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided.\n*\n* @private\n* @param {integer} [idx] - linear view index\n* @returns {*} array element\n*/\nfunction iget( idx ) {\n\t/* eslint-disable no-invalid-this */\n\tvar strides;\n\tvar shape;\n\tvar ndims;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = this._ndims;\n\tif ( ndims === 0 ) {\n\t\tif ( this._accessors ) {\n\t\t\treturn this._buffer.get( this._offset );\n\t\t}\n\t\treturn this._buffer[ this._offset ];\n\t}\n\tif ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len\n\t\t// Trivial case where we have all positive strides...\n\t\tif ( this._iterationOrder === 1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\treturn this._buffer.get( this._offset+idx );\n\t\t\t}\n\t\t\treturn this._buffer[ this._offset+idx ];\n\t\t}\n\t\t// Trivial case where we have all negative strides...\n\t\tif ( this._iterationOrder === -1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\treturn this._buffer.get( this.offset-idx );\n\t\t\t}\n\t\t\treturn this._buffer[ this._offset-idx ];\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tshape = this._shape;\n\tstrides = this._strides;\n\tind = this._offset;\n\tif ( isColumnMajor( this._order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\tif ( this._accessors ) {\n\t\t\treturn this._buffer.get( ind );\n\t\t}\n\t\treturn this._buffer[ ind ];\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\treturn this._buffer.get( ind );\n\t}\n\treturn this._buffer[ ind ];\n}\n\n\n// EXPORTS //\n\nexport default iget;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Sets an array element.\n*\n* ## Notes\n*\n* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided.\n*\n* @private\n* @param {...integer} [idx] - indices\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*/\nfunction set() {\n\t/* eslint-disable no-invalid-this */\n\tvar idx;\n\tvar i;\n\n\tidx = this._offset;\n\tfor ( i = 0; i < arguments.length-1; i++ ) {\n\t\tidx += this._strides[ i ] * arguments[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\tthis._buffer.set( arguments[ i ], idx );\n\t} else {\n\t\tthis._buffer[ idx ] = arguments[ i ];\n\t}\n\treturn this;\n}\n\n\n// EXPORTS //\n\nexport default set;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\n\n\n// MAIN //\n\n/**\n* Sets an array element located a specified linear view index.\n*\n* ## Notes\n*\n* - For zero-dimensional arrays, the first, and only, argument should be the value to set.\n*\n* @private\n* @param {integer} [idx] - linear view index\n* @param {*} v - value to set\n* @returns {ndarray} ndarray instance\n*/\nfunction iset( idx, v ) {\n\t/* eslint-disable no-invalid-this */\n\tvar strides;\n\tvar shape;\n\tvar ndims;\n\tvar ind;\n\tvar s;\n\tvar i;\n\n\tndims = this._ndims;\n\tif ( ndims === 0 ) {\n\t\tif ( this._accessors ) {\n\t\t\tthis._buffer.set( idx, this._offset );\n\t\t} else {\n\t\t\tthis._buffer[ this._offset ] = idx;\n\t\t}\n\t\treturn this;\n\t}\n\tif ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len\n\t\t// Trivial case where we have all positive strides...\n\t\tif ( this._iterationOrder === 1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\tthis._buffer.set( v, this._offset+idx );\n\t\t\t} else {\n\t\t\t\tthis._buffer[ this._offset+idx ] = v;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t\t// Trivial case where we have all negative strides...\n\t\tif ( this._iterationOrder === -1 ) {\n\t\t\tif ( this._accessors ) {\n\t\t\t\tthis._buffer.set( v, this._offset-idx );\n\t\t\t} else {\n\t\t\t\tthis._buffer[ this._offset-idx ] = v;\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t}\n\t// The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer...\n\tshape = this._shape;\n\tstrides = this._strides;\n\tind = this._offset;\n\tif ( isColumnMajor( this._order ) ) {\n\t\tfor ( i = 0; i < ndims; i++ ) {\n\t\t\ts = idx % shape[ i ];\n\t\t\tidx -= s;\n\t\t\tidx /= shape[ i ];\n\t\t\tind += s * strides[ i ];\n\t\t}\n\t\tif ( this._accessors ) {\n\t\t\tthis._buffer.set( v, ind );\n\t\t} else {\n\t\t\tthis._buffer[ ind ] = v;\n\t\t}\n\t\treturn this;\n\t}\n\t// Case: row-major\n\tfor ( i = ndims-1; i >= 0; i-- ) {\n\t\ts = idx % shape[ i ];\n\t\tidx -= s;\n\t\tidx /= shape[ i ];\n\t\tind += s * strides[ i ];\n\t}\n\tif ( this._accessors ) {\n\t\tthis._buffer.set( v, ind );\n\t} else {\n\t\tthis._buffer[ ind ] = v;\n\t}\n\treturn this;\n}\n\n\n// EXPORTS //\n\nexport default iset;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport real from '@stdlib/complex-float64-real';\nimport imag from '@stdlib/complex-float64-imag';\n\n\n// MAIN //\n\n/**\n* Serializes an ndarray as a JSON object.\n*\n* ## Notes\n*\n* - The method does **not** serialize data outside of the buffer region defined by the array configuration.\n*\n* @private\n* @returns {Object} JSON representation\n*/\nfunction toJSON() {\n\t/* eslint-disable no-invalid-this */\n\tvar out;\n\tvar len;\n\tvar v;\n\tvar i;\n\n\tlen = this._length;\n\n\t// Build an object containing all ndarray properties needed to revive a serialized ndarray...\n\tout = {};\n\tout.type = 'ndarray';\n\tout.dtype = this.dtype;\n\tout.flags = {\n\t\t'READONLY': this._flags.READONLY\n\t};\n\tout.order = this._order;\n\tout.shape = this._shape.slice();\n\tout.strides = this._strides.slice();\n\n\t// Flip the signs of negative strides:\n\tfor ( i = 0; i < out.strides.length; i++ ) {\n\t\tif ( out.strides[ i ] < 0 ) {\n\t\t\tout.strides[ i ] *= -1;\n\t\t}\n\t}\n\t// Cast data to generic array...\n\tout.data = [];\n\tif ( out.dtype === 'complex64' || out.dtype === 'complex128' ) {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tv = this.iget( i );\n\t\t\tout.data.push( real( v ), imag( v ) );\n\t\t}\n\t} else {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.data.push( this.iget( i ) );\n\t\t}\n\t}\n\treturn out;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nexport default toJSON;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Converts an ndarray instance to a primitive value.\n*\n* ## Notes\n*\n* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects.\n*\n* @private\n* @returns {(*|ndarray)} result\n*/\nfunction valueOf() { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tif ( this._ndims === 0 ) {\n\t\treturn this.iget();\n\t}\n\treturn this;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// EXPORTS //\n\nexport default valueOf;\n"],"names":["isColumnMajorContiguous","order","contiguous","isRowMajorContiguous","CTORS","int8","uint8","uint8c","int16","uint16","int32","uint32","float32","float64","generic","binary","complex64","complex128","bool","DTYPES","dtypes","ORDERS","orders","MODES","modes","ndarray","dtype","buffer","shape","strides","offset","nbytes","ord","len","i","this","length","BYTES_PER_ELEMENT","_byteLength","_bytesPerElement","bytesPerElement","_buffer","_dtype","_length","_ndims","_offset","_order","_shape","_strides","_accessors","Boolean","get","set","_iterationOrder","iterationOrder","buf","minmaxViewBufferIndex","isContiguous","strides2order","_flags","ROW_MAJOR_CONTIGUOUS","COLUMN_MAJOR_CONTIGUOUS","READONLY","__meta_dataview__","setReadOnly","setReadOnlyAccessor","prototype","flags","slice","idx","arguments","ndims","ind","s","isColumnMajor","v","ctor","str","dt","iget","real","imag","replace","join","out","type","data","push","hasBigIntSupport","flgs","sh","st","sm","m","o","N","M","_mode","_submode","byteLength","DataView","ArrayBuffer","setInt8","setInt16","IS_LITTLE_ENDIAN","setBigInt64","BigInt","setInt32","bytes","Uint8Array","float64ToInt64Bytes"],"mappings":"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"} \ No newline at end of file diff --git a/lib/copy_flags.js b/lib/copy_flags.js deleted file mode 100644 index 6ac6234..0000000 --- a/lib/copy_flags.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Copies ndarray flags. -* -* @private -* @param {Object} flags - flags -* @returns {Object} copy of input object -*/ -function copyFlags( flags ) { - return { - 'ROW_MAJOR_CONTIGUOUS': flags.ROW_MAJOR_CONTIGUOUS, - 'COLUMN_MAJOR_CONTIGUOUS': flags.COLUMN_MAJOR_CONTIGUOUS, - 'READONLY': flags.READONLY - }; -} - - -// EXPORTS // - -module.exports = copyFlags; diff --git a/lib/get.js b/lib/get.js deleted file mode 100644 index 07dc7e7..0000000 --- a/lib/get.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'; - -// MAIN // - -/** -* Returns an array element. -* -* ## Notes -* -* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided. -* -* @private -* @param {...integer} idx - indices -* @returns {*} array element -*/ -function get() { - /* eslint-disable no-invalid-this */ - var idx; - var i; - - idx = this._offset; - for ( i = 0; i < arguments.length; i++ ) { - idx += this._strides[ i ] * arguments[ i ]; - } - if ( this._accessors ) { - return this._buffer.get( idx ); - } - return this._buffer[ idx ]; -} - - -// EXPORTS // - -module.exports = get; diff --git a/lib/iget.js b/lib/iget.js deleted file mode 100644 index 9c6a4af..0000000 --- a/lib/iget.js +++ /dev/null @@ -1,103 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); - - -// MAIN // - -/** -* Returns an array element located a specified linear view index. -* -* ## Notes -* -* - For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided. -* -* @private -* @param {integer} [idx] - linear view index -* @returns {*} array element -*/ -function iget( idx ) { - /* eslint-disable no-invalid-this */ - var strides; - var shape; - var ndims; - var ind; - var s; - var i; - - ndims = this._ndims; - if ( ndims === 0 ) { - if ( this._accessors ) { - return this._buffer.get( this._offset ); - } - return this._buffer[ this._offset ]; - } - if ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len - // Trivial case where we have all positive strides... - if ( this._iterationOrder === 1 ) { - if ( this._accessors ) { - return this._buffer.get( this._offset+idx ); - } - return this._buffer[ this._offset+idx ]; - } - // Trivial case where we have all negative strides... - if ( this._iterationOrder === -1 ) { - if ( this._accessors ) { - return this._buffer.get( this.offset-idx ); - } - return this._buffer[ this._offset-idx ]; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - shape = this._shape; - strides = this._strides; - ind = this._offset; - if ( isColumnMajor( this._order ) ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - if ( this._accessors ) { - return this._buffer.get( ind ); - } - return this._buffer[ ind ]; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - if ( this._accessors ) { - return this._buffer.get( ind ); - } - return this._buffer[ ind ]; -} - - -// EXPORTS // - -module.exports = iget; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 59dc413..0000000 --- a/lib/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'; - -/** -* Multidimensional array constructor. -* -* @module @stdlib/ndarray-base-ctor -* -* @example -* var ndarray = require( '@stdlib/ndarray-base-ctor' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var out = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_column_major_contiguous.js b/lib/is_column_major_contiguous.js deleted file mode 100644 index b313361..0000000 --- a/lib/is_column_major_contiguous.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'; - -// MAIN // - -/** -* Determines if an array is column-major contiguous. -* -* @private -* @param {integer} order - **inferred** array order -* @param {boolean} contiguous - boolean indicating is an array is contiguous -* @returns {boolean} boolean indicating if an array is column-major contiguous -*/ -function isColumnMajorContiguous( order, contiguous ) { - return contiguous && ( order === 2 || order === 3 ); -} - - -// EXPORTS // - -module.exports = isColumnMajorContiguous; diff --git a/lib/is_contiguous.js b/lib/is_contiguous.js deleted file mode 100644 index 430f3aa..0000000 --- a/lib/is_contiguous.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 minmaxViewBufferIndex = require( '@stdlib/ndarray-base-minmax-view-buffer-index' ); - - -// MAIN // - -/** -* Determines if an array is contiguous. -* -* @private -* @param {NonNegativeInteger} len - array length -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - index offset -* @param {integer} iterationOrder - iteration order -* @returns {boolean} boolean indicating if an array is contiguous -*/ -function isContiguous( len, shape, strides, offset, iterationOrder ) { - var buf; - - // If an array does not contain any elements, then no data to store, and, if the array is unordered, adjacent array elements are not guaranteed to be stored next to each other. - if ( len === 0 || iterationOrder === 0 ) { - return false; - } - // Ensure that the array is compatible with a single memory segment: - buf = minmaxViewBufferIndex( shape, strides, offset ); - return ( len === ( buf[1]-buf[0]+1 ) ); -} - - -// EXPORTS // - -module.exports = isContiguous; diff --git a/lib/is_row_major_contiguous.js b/lib/is_row_major_contiguous.js deleted file mode 100644 index 2455b6a..0000000 --- a/lib/is_row_major_contiguous.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'; - -// MAIN // - -/** -* Determines if an array is row-major contiguous. -* -* @private -* @param {integer} order - **inferred** array order -* @param {boolean} contiguous - boolean indicating is an array is contiguous -* @returns {boolean} boolean indicating if an array is row-major contiguous -*/ -function isRowMajorContiguous( order, contiguous ) { - return contiguous && ( order === 1 || order === 3 ); -} - - -// EXPORTS // - -module.exports = isRowMajorContiguous; diff --git a/lib/iset.js b/lib/iset.js deleted file mode 100644 index a39ce16..0000000 --- a/lib/iset.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 isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); - - -// MAIN // - -/** -* Sets an array element located a specified linear view index. -* -* ## Notes -* -* - For zero-dimensional arrays, the first, and only, argument should be the value to set. -* -* @private -* @param {integer} [idx] - linear view index -* @param {*} v - value to set -* @returns {ndarray} ndarray instance -*/ -function iset( idx, v ) { - /* eslint-disable no-invalid-this */ - var strides; - var shape; - var ndims; - var ind; - var s; - var i; - - ndims = this._ndims; - if ( ndims === 0 ) { - if ( this._accessors ) { - this._buffer.set( idx, this._offset ); - } else { - this._buffer[ this._offset ] = idx; - } - return this; - } - if ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len - // Trivial case where we have all positive strides... - if ( this._iterationOrder === 1 ) { - if ( this._accessors ) { - this._buffer.set( v, this._offset+idx ); - } else { - this._buffer[ this._offset+idx ] = v; - } - return this; - } - // Trivial case where we have all negative strides... - if ( this._iterationOrder === -1 ) { - if ( this._accessors ) { - this._buffer.set( v, this._offset-idx ); - } else { - this._buffer[ this._offset-idx ] = v; - } - return this; - } - } - // The approach which follows is to resolve a view index to its subscripts and then plug the subscripts into the standard formula for computing the linear index in the underlying data buffer... - shape = this._shape; - strides = this._strides; - ind = this._offset; - if ( isColumnMajor( this._order ) ) { - for ( i = 0; i < ndims; i++ ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - if ( this._accessors ) { - this._buffer.set( v, ind ); - } else { - this._buffer[ ind ] = v; - } - return this; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = idx % shape[ i ]; - idx -= s; - idx /= shape[ i ]; - ind += s * strides[ i ]; - } - if ( this._accessors ) { - this._buffer.set( v, ind ); - } else { - this._buffer[ ind ] = v; - } - return this; -} - - -// EXPORTS // - -module.exports = iset; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index f8ba67d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,650 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var hasBigIntSupport = require( '@stdlib/assert-has-bigint-support' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' ); -var iterationOrder = require( '@stdlib/ndarray-base-iteration-order' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var slice = require( '@stdlib/array-base-slice' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var isColumnMajorContiguous = require( './is_column_major_contiguous.js' ); -var isRowMajorContiguous = require( './is_row_major_contiguous.js' ); -var isContiguous = require( './is_contiguous.js' ); -var copyFlags = require( './copy_flags.js' ); -var igetValue = require( './iget.js' ); -var isetValue = require( './iset.js' ); -var setValue = require( './set.js' ); -var getValue = require( './get.js' ); -var valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare -var toJSON = require( './tojson.js' ); -var toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare -var meta2dataview = require( './meta2dataview.js' ); -var meta2dataviewPolyfill = require( './meta2dataview.polyfill.js' ); - - -// MAIN // - -/** -* ndarray constructor. -* -* ## Notes -* -* - To create a zero-dimensional array, -* -* ```javascript -* var buffer = [ 1 ]; -* var shape = []; -* var strides = [ 0 ]; -* var offset = 0; -* -* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* ``` -* -* @constructor -* @param {string} dtype - data type -* @param {(ArrayLikeObject|TypedArray|Buffer)} buffer - data buffer -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - index offset -* @param {string} order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {ndarray} ndarray instance -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -*/ -function ndarray( dtype, buffer, shape, strides, offset, order ) { - var contiguous; - var nbytes; - var ord; - var len; - var i; - if ( !(this instanceof ndarray) ) { - return new ndarray( dtype, buffer, shape, strides, offset, order ); - } - // Compute the number of elements... - len = 1; - for ( i = 0; i < shape.length; i++ ) { - len *= shape[ i ]; // TODO: consider supporting accessor arrays here - } - // Compute the number of bytes... - if ( buffer.BYTES_PER_ELEMENT ) { - nbytes = buffer.BYTES_PER_ELEMENT * len; - } else { - nbytes = null; - } - // Set private properties... - this._byteLength = nbytes; - this._bytesPerElement = bytesPerElement( dtype ); - this._buffer = buffer; - this._dtype = dtype; - this._length = len; - this._ndims = shape.length; - this._offset = offset; - this._order = order; - this._shape = shape; - this._strides = strides; - this._accessors = Boolean( buffer.get && buffer.set ); - - this._iterationOrder = iterationOrder( strides ); - - // Determine if the array can be stored contiguously: - contiguous = isContiguous( len, shape, strides, offset, this._iterationOrder ); // eslint-disable-line max-len - - // Infer the array "order" from the stride array (this is supplementary to the `order` parameter): - ord = strides2order( strides ); - - this._flags = { - 'ROW_MAJOR_CONTIGUOUS': isRowMajorContiguous( ord, contiguous ), - 'COLUMN_MAJOR_CONTIGUOUS': isColumnMajorContiguous( ord, contiguous ), - 'READONLY': false - }; - - // Initialize a property for caching serialized meta data: - this.__meta_dataview__ = null; - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndarray -* @type {string} -* @default 'ndarray' -* -* @example -* var str = ndarray.name; -* // returns 'ndarray' -*/ -setReadOnly( ndarray, 'name', 'ndarray' ); - -/** -* Size (in bytes) of the array (if known). -* -* @name byteLength -* @memberof ndarray.prototype -* @type {(NonNegativeInteger|null)} -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* -* var byteLength = x.byteLength; -* // returns 48 -*/ -setReadOnlyAccessor( ndarray.prototype, 'byteLength', function get() { - return this._byteLength; -}); - -/** -* Size (in bytes) of each array element (if known). -* -* @name BYTES_PER_ELEMENT -* @memberof ndarray.prototype -* @type {(PositiveInteger|null)} -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* -* var nbytes = x.BYTES_PER_ELEMENT; -* // returns 8 -*/ -setReadOnlyAccessor( ndarray.prototype, 'BYTES_PER_ELEMENT', function get() { - return this._bytesPerElement; -}); - -/** -* Pointer to the underlying data buffer. -* -* @name data -* @memberof ndarray.prototype -* @type {(Array|TypedArray|Buffer)} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var data = x.data; -* // returns [ 1, 2, 3, 4, 5, 6 ] -*/ -setReadOnlyAccessor( ndarray.prototype, 'data', function get() { - return this._buffer; -}); - -/** -* Underlying data type. -* -* @name dtype -* @memberof ndarray.prototype -* @type {string} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var dtype = x.dtype; -* // returns 'generic' -*/ -setReadOnlyAccessor( ndarray.prototype, 'dtype', function get() { - return this._dtype; -}); - -/** -* Meta information, such as information concerning the memory layout of the array. -* -* @name flags -* @memberof ndarray.prototype -* @type {Object} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var flgs = x.flags; -* // returns -*/ -setReadOnlyAccessor( ndarray.prototype, 'flags', function get() { - return copyFlags( this._flags ); -}); - -/** -* Length of the array. -* -* @name length -* @memberof ndarray.prototype -* @type {NonNegativeInteger} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var len = x.length; -* // returns 6 -*/ -setReadOnlyAccessor( ndarray.prototype, 'length', function get() { - return this._length; -}); - -/** -* Number of dimensions. -* -* @name ndims -* @memberof ndarray.prototype -* @type {PositiveInteger} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var ndims = x.ndims; -* // returns 2 -*/ -setReadOnlyAccessor( ndarray.prototype, 'ndims', function get() { - return this._ndims; -}); - -/** -* Index offset which specifies the buffer index at which to start iterating over array elements. -* -* @name offset -* @memberof ndarray.prototype -* @type {NonNegativeInteger} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var o = x.offset; -* // returns 0 -*/ -setReadOnlyAccessor( ndarray.prototype, 'offset', function get() { - return this._offset; -}); - -/** -* Array order. -* -* ## Notes -* -* - The array order is either row-major (C-style) or column-major (Fortran-style). -* -* @name order -* @memberof ndarray.prototype -* @type {string} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var order = x.order; -* // returns 'row-major' -*/ -setReadOnlyAccessor( ndarray.prototype, 'order', function get() { - return this._order; -}); - -/** -* Shape of the array. -* -* @name shape -* @memberof ndarray.prototype -* @type {NonNegativeIntegerArray} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var s = x.shape; -* // returns [ 3, 2 ] -*/ -setReadOnlyAccessor( ndarray.prototype, 'shape', function get() { - return slice( this._shape, 0, this._shape.length ); -}); - -/** -* Index strides which specify how to access data along corresponding array dimensions. -* -* @name strides -* @memberof ndarray.prototype -* @type {IntegerArray} -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var s = x.strides; -* // returns [ 2, 1 ] -*/ -setReadOnlyAccessor( ndarray.prototype, 'strides', function get() { - return slice( this._strides, 0, this._strides.length ); -}); - -/** -* Returns an array element. -* -* ## Notes -* -* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided. -* -* @name get -* @memberof ndarray.prototype -* @type {Function} -* @param {...integer} [idx] - indices -* @returns {*} array element -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.get( 1, 1 ); -* // returns 4 -*/ -setReadOnly( ndarray.prototype, 'get', getValue ); - -/** -* Returns an array element located at a specified linear index. -* -* ## Notes -* -* - For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided. -* -* @name iget -* @memberof ndarray.prototype -* @type {Function} -* @param {integer} [idx] - linear index -* @returns {*} array element -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.iget( 3 ); -* // returns 4 -*/ -setReadOnly( ndarray.prototype, 'iget', igetValue ); - -/** -* Sets an array element. -* -* ## Notes -* -* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided. -* -* @name set -* @memberof ndarray.prototype -* @type {Function} -* @param {...integer} [idx] - indices -* @param {*} v - value to set -* @returns {ndarray} ndarray instance -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.get( 1, 1 ); -* // returns 4 -* -* x.set( 1, 1, 10 ); -* -* var b = x.data; -* // returns [ 1, 2, 3, 10, 5, 6 ] -* -* v = x.get( 1, 1 ); -* // returns 10 -*/ -setReadOnly( ndarray.prototype, 'set', setValue ); - -/** -* Sets an array element located at a specified linear index. -* -* ## Notes -* -* - For zero-dimensional arrays, the first, and only, argument should be the value to set. -* -* @name iset -* @memberof ndarray.prototype -* @type {Function} -* @param {integer} [idx] - linear index -* @param {*} v - value to set -* @returns {ndarray} ndarray instance -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.iget( 3 ); -* // returns 4 -* -* x.iset( 3, 10 ); -* -* var b = x.data; -* // returns [ 1, 2, 3, 10, 5, 6 ] -* -* v = x.iget( 3 ); -* // returns 10 -*/ -setReadOnly( ndarray.prototype, 'iset', isetValue ); - -/** -* Serializes an ndarray as a string. -* -* ## Notes -* -* - The method does **not** serialize data outside of the buffer region defined by the array configuration. -* -* @name toString -* @memberof ndarray.prototype -* @type {Function} -* @returns {string} serialized ndarray -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 2; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var str = x.toString(); -* // returns "ndarray( 'generic', [ 3, 4, 5, 6, 7, 8 ], [ 3, 2 ], [ 2, 1 ], 0, 'row-major' )" -*/ -setReadOnly( ndarray.prototype, 'toString', toString ); - -/** -* Serializes an ndarray as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndarray` instance. -* - The method does **not** serialize data outside of the buffer region defined by the array configuration. -* -* @name toJSON -* @memberof ndarray.prototype -* @type {Function} -* @returns {Object} serialized ndarray -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 2; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var o = x.toJSON(); -* // e.g., returns { 'type': 'ndarray', 'dtype': 'generic', 'flags': {...}, 'offset': 0, 'order': 'row-major', 'shape': [ 3, 2 ], 'strides': [ 2, 1 ], 'data': [ 3, 4, 5, 6, 7, 8 ] } -*/ -setReadOnly( ndarray.prototype, 'toJSON', toJSON ); - -/** -* Converts an ndarray instance to a primitive value. -* -* ## Notes -* -* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects. -* -* @name valueOf -* @memberof ndarray.prototype -* @type {Function} -* @returns {(*|ndarray)} result -* -* @example -* var buffer = [ 3.14 ]; -* var shape = []; -* var strides = [ 0 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.valueOf(); -* // returns 3.14 -* -* @example -* var buffer = [ 3.14 ]; -* var shape = [ 1 ]; -* var strides = [ 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var v = x.valueOf(); -* // returns -*/ -setReadOnly( ndarray.prototype, 'valueOf', valueOf ); - -/** -* Serializes ndarray meta data to a `DataView`. -* -* ## Notes -* -* - Meta data format: -* -* ```text -* | (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Consumers of this method should treat the returned `DataView` as **immutable**. Otherwise, mutation can invalidate meta data and potentially affect other consumers. -* -* @private -* @name __array_meta_dataview__ -* @memberof ndarray.prototype -* @type {Function} -* @returns {DataView} serialized meta data -* -* @example -* var buffer = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 2; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* -* var dv = x.__array_meta_dataview__(); -* // returns -*/ -setReadOnly( ndarray.prototype, '__array_meta_dataview__', ( hasBigIntSupport() ) ? meta2dataview : meta2dataviewPolyfill ); - - -// EXPORTS // - -module.exports = ndarray; diff --git a/lib/meta2dataview.js b/lib/meta2dataview.js deleted file mode 100644 index 8f2504a..0000000 --- a/lib/meta2dataview.js +++ /dev/null @@ -1,206 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var BigInt = require( '@stdlib/bigint-ctor' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// FUNCTIONS // - -/** -* Serializes ndarray meta data to a `DataView`. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @returns {DataView} serialized meta data -*/ -function meta2dataview() { - /* eslint-disable no-invalid-this */ - var nbytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - m = this._mode || 'throw'; - sm = this._submode || [ m ]; - N = this._ndims; - M = sm.length; - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer... - v = this.__meta_dataview__; - if ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be "stale" (e.g., shape and/or strides may have changed) - return v; - } - // Allocate raw memory and create a view for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - - // Retrieve ndarray meta data: - sh = this._shape; - st = this._strides; - dt = this._dtype; - nbytes = this._bytesPerElement; - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - v.setBigInt64( o, BigInt( N ), IS_LITTLE_ENDIAN ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - v.setBigInt64( o, BigInt( sh[i] ), IS_LITTLE_ENDIAN ); - v.setBigInt64( o+s, BigInt( st[i]*nbytes ), IS_LITTLE_ENDIAN ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - v.setBigInt64( o, BigInt( this._offset*nbytes ), IS_LITTLE_ENDIAN ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ this._order ] ); - - // Mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - v.setBigInt64( o, BigInt( M ), IS_LITTLE_ENDIAN ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - flgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - // Cache the serialized meta data: - this.__meta_dataview__ = v; - - return v; - - /* eslint-enable no-invalid-this */ -} - - -// EXPORTS // - -module.exports = meta2dataview; diff --git a/lib/meta2dataview.polyfill.js b/lib/meta2dataview.polyfill.js deleted file mode 100644 index 31fa593..0000000 --- a/lib/meta2dataview.polyfill.js +++ /dev/null @@ -1,209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var DataView = require( '@stdlib/array-dataview' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var float64ToInt64Bytes = require( '@stdlib/number-float64-base-to-int64-bytes' ).assign; - - -// VARIABLES // - -var DTYPES = dtypes(); -var ORDERS = orders(); -var MODES = modes(); - - -// FUNCTIONS // - -/** -* Serializes ndarray meta data to a `DataView`. -* -* ## Notes -* -* - This function takes into account ndarray-like objects which may support index modes. -* -* - This function defaults to returning cached serialized meta data. To force serialization, set the private `__meta_dataview__` property to `null`. -* -* - Serialization is performed according to host byte order (endianness). -* -* - Meta data format: -* -* ```text -* | endianness (1 byte) | (2 bytes) | (8 bytes) | (ndims*8 bytes) | (ndims*8 bytes) | (8 bytes) | (1 byte) | (1 byte) | (8 bytes) | (nsubmodes*1 bytes) | (4 bytes) | -* ``` -* -* which translates to the following `ArrayBuffer` layout: -* -* ```text -* ArrayBuffer[ -* [int8], -* [int16], -* [int64], -* [ndims*int64], -* [ndims*int64], -* [int64], -* [int8], -* [int8], -* [int64], -* [nsubmodes*int8], -* [int32] -* ] -* ``` -* -* where `strides` and `offset` are in units of bytes. -* -* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian. -* -* - Buffer length: -* -* ```text -* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes -* ``` -* -* For example, consider a three-dimensional ndarray with one subscript index mode (submode): -* -* ```text -* 33 + (3*16) + 1 = 82 bytes -* ``` -* -* - Views: -* -* - endianness: `Int8Array( buf, 0, 1 )` -* - dtype: `Int16Array( buf, 1, 1 )` -* - ndims: `Int64Array( buf, 3, 1 )` -* - shape: `Int64Array( buf, 11, ndims )` -* - strides: `Int64Array( buf, 11+(ndims*8), ndims )` -* - offset: `Int64Array( buf, 11+(ndims*16), 1 )` -* - order: `Int8Array( buf, 19+(ndims*16), 1 )` -* - mode: `Int8Array( buf, 20+(ndims*16), 1 )` -* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )` -* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )` -* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1 )` -* -* @private -* @returns {DataView} serialized meta data -*/ -function meta2dataview() { - /* eslint-disable no-invalid-this */ - var nbytes; - var bytes; - var flgs; - var len; - var dt; - var sh; - var st; - var sm; - var v; - var m; - var o; - var s; - var N; - var M; - var i; - - m = this._mode || 'throw'; - sm = this._submode || [ m ]; - N = this._ndims; - M = sm.length; - - // Compute the amount of memory we need to allocate for storing meta data: - len = 33 + (N*16) + M; - - // Check if we've already serialized ndarray meta data and can reuse an already allocated array buffer... - v = this.__meta_dataview__; - if ( v && v.byteLength === len ) { // Note: the byte length check is only a bare minimum sanity check, as cached contents may still be "stale" (e.g., shape and/or strides may have changed) - return v; - } - // Allocate raw memory and create views for interfacing with the allocated memory: - v = new DataView( new ArrayBuffer( len ) ); - bytes = new Uint8Array( v.buffer ); - - // Retrieve ndarray meta data: - sh = this._shape; - st = this._strides; - dt = this._dtype; - nbytes = this._bytesPerElement; - - // Endianness: (byteoffset: 0; bytelength: 1) - o = 0; - v.setInt8( o, ( IS_LITTLE_ENDIAN ) ? 1 : 0 ); - - // Data type: (byteoffset: 1; bytelength: 2) - o += 1; - v.setInt16( o, DTYPES[ dt ], IS_LITTLE_ENDIAN ); - - // Number of dimensions: (byteoffset: 3; bytelength: 8) - o += 2; - float64ToInt64Bytes( N, bytes, 1, o ); - - // Shape and strides: (byteoffset: 11 and 11+(ndims*8), respectively; bytelength: ndims*8 for both shape and strides, and, thus, ndims*16 total) - s = N * 8; // stride length between a dimension (shape[i]) and its associated stride - o += 8; - for ( i = 0; i < N; i++ ) { - float64ToInt64Bytes( sh[i], bytes, 1, o ); - float64ToInt64Bytes( st[i]*nbytes, bytes, 1, o+s ); - o += 8; - } - // Offset: (byteoffset: 11+(ndims*16); bytelength: 8) - o += s; - float64ToInt64Bytes( this._offset*nbytes, bytes, 1, o ); - - // Order: (byteoffset: 19+(ndims*16); bytelength: 1) - o += 8; - v.setInt8( o, ORDERS[ this._order ] ); - - // Mode: (byteoffset: 20+(ndims*16); bytelength: 1) - o += 1; - v.setInt8( o, MODES[ m ] ); - - // Number of submodes: (byteoffset: 21+(ndims*16); bytelength: 8) - o += 1; - float64ToInt64Bytes( M, bytes, 1, o ); - - // Submodes: (byteoffset: 29+(ndims*16); bytelength: nsubmodes*1) - o += 8; - for ( i = 0; i < M; i++ ) { - v.setInt8( o, MODES[ sm[i] ] ); - o += 1; - } - // Flags: (byteoffset: 29+(ndims*16)+nsubmodes; bytelength: 4) - flgs = 0|0; - flgs |= ( this._flags.READONLY ) ? 4 : 0; // 00000000 00000000 00000000 00000100 - v.setInt32( o, flgs, IS_LITTLE_ENDIAN ); - - // Cache the serialized meta data: - this.__meta_dataview__ = v; - - return v; - - /* eslint-enable no-invalid-this */ -} - - -// EXPORTS // - -module.exports = meta2dataview; diff --git a/lib/set.js b/lib/set.js deleted file mode 100644 index ed6f25c..0000000 --- a/lib/set.js +++ /dev/null @@ -1,55 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an array element. -* -* ## Notes -* -* - The number of indices should **equal** the number of dimensions. Accordingly, for zero-dimensional arrays, no indices should be provided. -* -* @private -* @param {...integer} [idx] - indices -* @param {*} v - value to set -* @returns {ndarray} ndarray instance -*/ -function set() { - /* eslint-disable no-invalid-this */ - var idx; - var i; - - idx = this._offset; - for ( i = 0; i < arguments.length-1; i++ ) { - idx += this._strides[ i ] * arguments[ i ]; - } - if ( this._accessors ) { - this._buffer.set( arguments[ i ], idx ); - } else { - this._buffer[ idx ] = arguments[ i ]; - } - return this; -} - - -// EXPORTS // - -module.exports = set; diff --git a/lib/tojson.js b/lib/tojson.js deleted file mode 100644 index 5b338f4..0000000 --- a/lib/tojson.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); - - -// MAIN // - -/** -* Serializes an ndarray as a JSON object. -* -* ## Notes -* -* - The method does **not** serialize data outside of the buffer region defined by the array configuration. -* -* @private -* @returns {Object} JSON representation -*/ -function toJSON() { - /* eslint-disable no-invalid-this */ - var out; - var len; - var v; - var i; - - len = this._length; - - // Build an object containing all ndarray properties needed to revive a serialized ndarray... - out = {}; - out.type = 'ndarray'; - out.dtype = this.dtype; - out.flags = { - 'READONLY': this._flags.READONLY - }; - out.order = this._order; - out.shape = this._shape.slice(); - out.strides = this._strides.slice(); - - // Flip the signs of negative strides: - for ( i = 0; i < out.strides.length; i++ ) { - if ( out.strides[ i ] < 0 ) { - out.strides[ i ] *= -1; - } - } - // Cast data to generic array... - out.data = []; - if ( out.dtype === 'complex64' || out.dtype === 'complex128' ) { - for ( i = 0; i < len; i++ ) { - v = this.iget( i ); - out.data.push( real( v ), imag( v ) ); - } - } else { - for ( i = 0; i < len; i++ ) { - out.data.push( this.iget( i ) ); - } - } - return out; - - /* eslint-enable no-invalid-this */ -} - - -// EXPORTS // - -module.exports = toJSON; diff --git a/lib/tostring.js b/lib/tostring.js deleted file mode 100644 index 582f0c6..0000000 --- a/lib/tostring.js +++ /dev/null @@ -1,181 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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-replace' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); - - -// VARIABLES // - -var CTORS = { - 'int8': 'new Int8Array( [ {{data}} ] )', - 'uint8': 'new Uint8Array( [ {{data}} ] )', - 'uint8c': 'new Uint8ClampedArray( [ {{data}} ] )', - 'int16': 'new Int16Array( [ {{data}} ] )', - 'uint16': 'new Uint16Array( [ {{data}} ] )', - 'int32': 'new Int32Array( [ {{data}} ] )', - 'uint32': 'new Uint32Array( [ {{data}} ] )', - 'float32': 'new Float32Array( [ {{data}} ] )', - 'float64': 'new Float64Array( [ {{data}} ] )', - 'generic': '[ {{data}} ]', - 'binary': 'new Buffer( [ {{data}} ] )', - 'complex64': 'new Complex64Array( [ {{data}} ] )', - 'complex128': 'new Complex128Array( [ {{data}} ] )', - 'bool': 'new BooleanArray( [ {{data}} ] )' -}; - - -// MAIN // - -/** -* Serializes an ndarray as a string. -* -* ## Notes -* -* - The method does **not** serialize data outside of the buffer region defined by the array configuration. -* -* @private -* @returns {string} string representation -*/ -function toString() { // eslint-disable-line stdlib/no-redeclare - /* eslint-disable no-invalid-this */ - var buffer; - var ndims; - var ctor; - var str; - var dt; - var v; - var i; - - ndims = this._shape.length; - dt = this._dtype; - - // Function to invoke to create an ndarray: - str = 'ndarray( \''+dt+'\', '; - - // Data buffer parameter... - buffer = ''; - if ( this._length <= 100 ) { - if ( dt === 'complex64' || dt === 'complex128' ) { - for ( i = 0; i < this._length; i++ ) { - v = this.iget( i ); - buffer += real( v ) + ', ' + imag( v ); - if ( i < this._length-1 ) { - buffer += ', '; - } - } - } else { - for ( i = 0; i < this._length; i++ ) { - buffer += this.iget( i ); - if ( i < this._length-1 ) { - buffer += ', '; - } - } - } - } else { - // First three values... - if ( dt === 'complex64' || dt === 'complex128' ) { - for ( i = 0; i < 3; i++ ) { - v = this.iget( i ); - buffer += real( v ) + ', ' + imag( v ); - if ( i < 2 ) { - buffer += ', '; - } - } - } else { - for ( i = 0; i < 3; i++ ) { - buffer += this.iget( i ); - if ( i < 2 ) { - buffer += ', '; - } - } - } - buffer += ', ..., '; - - // Last three values... - if ( dt === 'complex64' || dt === 'complex128' ) { - for ( i = 2; i >= 0; i-- ) { - v = this.iget( this._length-1-i ); - buffer += real( v ) + ', ' + imag( v ); - if ( i > 0 ) { - buffer += ', '; - } - } - } else { - for ( i = 2; i >= 0; i-- ) { - buffer += this.iget( this._length-1-i ); - if ( i > 0 ) { - buffer += ', '; - } - } - } - } - ctor = CTORS[ this.dtype ]; - str += replace( ctor, '{{data}}', buffer ); - str += ', '; - - // Array shape... - if ( ndims === 0 ) { - str += '[]'; - } else { - str += '[ ' + this._shape.join( ', ' ) + ' ]'; - } - str += ', '; - - // Stride array... - str += '[ '; - if ( ndims === 0 ) { - str += '0'; - } else { - for ( i = 0; i < ndims; i++ ) { - if ( this._strides[ i ] < 0 ) { - str += -this._strides[ i ]; - } else { - str += this._strides[ i ]; - } - if ( i < ndims-1 ) { - str += ', '; - } - } - } - str += ' ]'; - str += ', '; - - // Buffer offset: - str += '0'; - str += ', '; - - // Order: - str += '\'' + this._order + '\''; - - // Close the function call: - str += ' )'; - return str; - - /* eslint-enable no-invalid-this */ -} - - -// EXPORTS // - -module.exports = toString; diff --git a/lib/valueof.js b/lib/valueof.js deleted file mode 100644 index a015ba8..0000000 --- a/lib/valueof.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Converts an ndarray instance to a primitive value. -* -* ## Notes -* -* - Only zero-dimensional ndarrays are converted to a primitive value. For ndarray instances having one or more dimensions, the method returns the `this` value, as is the default behavior for objects. -* -* @private -* @returns {(*|ndarray)} result -*/ -function valueOf() { // eslint-disable-line stdlib/no-redeclare - /* eslint-disable no-invalid-this */ - if ( this._ndims === 0 ) { - return this.iget(); - } - return this; - - /* eslint-enable no-invalid-this */ -} - - -// EXPORTS // - -module.exports = valueOf; diff --git a/package.json b/package.json index bc711c7..4854f3a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Base multidimensional 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": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,70 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-slice": "^0.2.2", - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-dataview": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-has-bigint-support": "^0.2.2", - "@stdlib/assert-is-little-endian": "^0.2.2", - "@stdlib/bigint-ctor": "^0.2.2", - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/complex-float64-imag": "^0.1.1", - "@stdlib/complex-float64-real": "^0.1.1", - "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-iteration-order": "^0.2.2", - "@stdlib/ndarray-base-minmax-view-buffer-index": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/number-float64-base-to-int64-bytes": "^0.2.2", - "@stdlib/string-replace": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-has-property": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-dataview": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/random-base-randu": "^0.2.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -120,7 +33,6 @@ "ctor", "base" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..553d3b6 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 90db58a..0000000 --- a/test/test.js +++ /dev/null @@ -1,4128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 Float64Array = require( '@stdlib/array-float64' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isDataView = require( '@stdlib/assert-is-dataview' ); -var IS_LITTLE_ENDIAN = require( '@stdlib/assert-is-little-endian' ); -var real = require( '@stdlib/complex-float64-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ).enum; -var modes = require( '@stdlib/ndarray-index-modes' ).enum; -var orders = require( '@stdlib/ndarray-orders' ).enum; -var ndarray = require( './../lib' ); - - -// VARIABLES // - -var DTYPES = dtypes(); -var MODES = modes(); -var ORDERS = orders(); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is an ndarray constructor', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = new ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` keyword', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the function supports creating zero-dimensional ndarrays', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = new ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.byteLength, 8*buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.byteLength, 8*buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (typed; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.byteLength, 8*buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of the array (complex typed; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.byteLength ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.byteLength, 8*buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of an array (generic)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( arr.byteLength, null, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `byteLength` property specifying the size (in bytes) of an array (generic; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'byteLength' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'byteLength' ), true, 'has property' ); - t.strictEqual( arr.byteLength, null, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (typed; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (complex typed; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.BYTES_PER_ELEMENT ), true, 'is a positive integer' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, 8, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (generic)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, null, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `BYTES_PER_ELEMENT` property specifying the size (in bytes) of each array element (generic; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'BYTES_PER_ELEMENT' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'BYTES_PER_ELEMENT' ), true, 'has property' ); - t.strictEqual( arr.BYTES_PER_ELEMENT, null, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `data` property pointing to the underlying data buffer', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'data' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'data' ), true, 'has property' ); - t.strictEqual( arr.data, buffer, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `data` property pointing to the underlying data buffer (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'data' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'data' ), true, 'has property' ); - t.strictEqual( arr.data, buffer, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `data` property pointing to the underlying data buffer (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'data' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'data' ), true, 'has property' ); - t.strictEqual( arr.data, buffer, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `dtype` property specifying the underlying data type', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'dtype' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'dtype' ), true, 'has property' ); - t.strictEqual( arr.dtype, dtype, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `dtype` property specifying the underlying data type (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'dtype' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'dtype' ), true, 'has property' ); - t.strictEqual( arr.dtype, dtype, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `dtype` property specifying the underlying data type (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'dtype' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'dtype' ), true, 'has property' ); - t.strictEqual( arr.dtype, dtype, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major contiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); - t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); - - t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (column-major contiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); - t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); - - t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); - - t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); - t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); - - t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout of the array (row-major and column-major contiguous; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); - t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); - - t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, true, 'has expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `flags` property providing meta information, such as information concerning the memory layout the array (neither row-major nor column-major contiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ); - shape = [ 2, 2, 2 ]; - order = 'column-major'; - strides = [ 4, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'flags' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'flags' ), true, 'has property' ); - t.strictEqual( isPlainObject( arr.flags ), true, 'is an object' ); - - t.strictEqual( hasOwnProp( arr.flags, 'ROW_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.ROW_MAJOR_CONTIGUOUS, false, 'has expected value' ); - - t.strictEqual( hasOwnProp( arr.flags, 'COLUMN_MAJOR_CONTIGUOUS' ), true, 'has own property' ); - t.strictEqual( arr.flags.COLUMN_MAJOR_CONTIGUOUS, false, 'has expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `length` property specifying the number of array elements', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.length, buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `length` property specifying the number of array elements (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.length, buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `length` property specifying the number of array elements (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'length' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'length' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.length ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.length, buffer.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `ndims` property specifying the number of array dimensions', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); - t.strictEqual( isPositiveInteger( arr.ndims ), true, 'is a positive integer' ); - t.strictEqual( arr.ndims, shape.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `ndims` property specifying the number of array dimensions (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'ndims' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'ndims' ), true, 'has property' ); - t.strictEqual( arr.ndims, shape.length, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `offset` property specifying the location of the first indexed element (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'offset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'offset' ), true, 'has property' ); - t.strictEqual( isNonNegativeInteger( arr.offset ), true, 'is a nonnegative integer' ); - t.strictEqual( arr.offset, offset, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `order` property specifying the array order (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `order` property specifying the array order (row-major; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `order` property specifying the array order (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has an `order` property specifying the array order (column-major; 0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'column-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'order' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'order' ), true, 'has property' ); - t.strictEqual( arr.order, order, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `shape` property specifying the array shape (dimensions)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); - t.notEqual( arr.shape, shape, 'returns a copy' ); - t.deepEqual( arr.shape, shape, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `shape` property specifying the array shape (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'column-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'shape' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'shape' ), true, 'has property' ); - t.notEqual( arr.shape, shape, 'returns a copy' ); - t.deepEqual( arr.shape, shape, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); - t.notEqual( arr.strides, strides, 'returns a copy' ); - t.deepEqual( arr.strides, strides, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `strides` property specifying how to access array elements along corresponding dimensions (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'column-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'strides' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'strides' ), true, 'has property' ); - t.notEqual( arr.strides, strides, 'returns a copy' ); - t.deepEqual( arr.strides, strides, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (row-major; complex dtype)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 0 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get( 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (column-major; complex dtype)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.get( 1, 0 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `get` method for retrieving an array element using subscripts (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'get' ), true, 'has property' ); - t.strictEqual( isFunction( arr.get ), true, 'has method' ); - - t.strictEqual( arr.get(), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; noncontiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (row-major; noncontiguous; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len - shape = [ 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; noncontiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 4, 8 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 7.0, 'returns expected value' ); - t.strictEqual( imag( v ), 8.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (column-major; noncontiguous; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len - shape = [ 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 4, 8 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 1.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.strictEqual( arr.iget(), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has an `iget` method for retrieving an array element using a linear index (0d; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - v = arr.iget(); - t.strictEqual( real( v ), 5.0, 'returns expected value' ); - t.strictEqual( imag( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 5.0, 8.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 5.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 7.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, new Complex64( 9.0, 10.0 ) ); - arr.set( 0, 1, new Complex64( 11.0, 12.0 ) ); - arr.set( 1, 0, new Complex64( 13.0, 14.0 ) ); - arr.set( 1, 1, new Complex64( 15.0, 16.0 ) ); - - v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.get( 1, 0 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 7.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 5.0, 8.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 8.0, 5.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( 1, 0, 7.0 ); - arr.set( 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 6.0, 7.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 0, 0, new Complex64( 9.0, 10.0 ) ); - arr.set( 0, 1, new Complex64( 11.0, 12.0 ) ); - arr.set( 1, 0, new Complex64( 13.0, 14.0 ) ); - arr.set( 1, 1, new Complex64( 15.0, 16.0 ) ); - - v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.get( 1, 0 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 9.0, 10.0, 13.0, 14.0, 11.0, 12.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a `set` method for setting an array element using subscripts (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - - arr.set( 5.0 ); - - t.strictEqual( arr.get(), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 5.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 5.0, 8.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 5.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 7.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major; noncontiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - shape = [ 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, -5.0 ); - arr.iset( 1, -6.0 ); - arr.iset( 2, -7.0 ); - arr.iset( 3, -8.0 ); - - t.strictEqual( arr.iget( 0 ), -5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), -6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), -7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), -8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ -5.0, -6.0, 3.0, 4.0, -7.0, -8.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 13.0, 14.0, 15.0, 16.0, 9.0, 10.0, 11.0, 12.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 15.0, 16.0, 13.0, 14.0, 11.0, 12.0, 9.0, 10.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (row-major; noncontiguous; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); // eslint-disable-line max-len - shape = [ 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( -9.0, -10.0 ) ); - arr.iset( 1, new Complex64( -11.0, -12.0 ) ); - arr.iset( 2, new Complex64( -13.0, -14.0 ) ); - arr.iset( 3, new Complex64( -15.0, -16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), -9.0, 'returns expected value' ); - t.strictEqual( imag( v ), -10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), -11.0, 'returns expected value' ); - t.strictEqual( imag( v ), -12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), -13.0, 'returns expected value' ); - t.strictEqual( imag( v ), -14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), -15.0, 'returns expected value' ); - t.strictEqual( imag( v ), -16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ -9.0, -10.0, 3.0, 4.0, -11.0, -12.0, 7.0, 8.0, -13.0, -14.0, 11.0, 12.0, -15.0, -16.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 5.0, 8.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7, 8, 5, 6 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( 2, 7.0 ); - arr.iset( 3, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 7.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major; noncontiguous)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - shape = [ 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 4, 8 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, -5.0 ); - arr.iset( 1, -6.0 ); - arr.iset( 2, -7.0 ); - arr.iset( 3, -8.0 ); - - t.strictEqual( arr.iget( 0 ), -5.0, 'returns expected value' ); - t.strictEqual( arr.iget( 1 ), -6.0, 'returns expected value' ); - t.strictEqual( arr.iget( 2 ), -7.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), -8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ -5.0, -6.0, 3.0, 4.0, -7.0, -8.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 13.0, 14.0, 15.0, 16.0, 9.0, 10.0, 11.0, 12.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( 9.0, 10.0 ) ); - arr.iset( 1, new Complex64( 11.0, 12.0 ) ); - arr.iset( 2, new Complex64( 13.0, 14.0 ) ); - arr.iset( 3, new Complex64( 15.0, 16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), 9.0, 'returns expected value' ); - t.strictEqual( imag( v ), 10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), 11.0, 'returns expected value' ); - t.strictEqual( imag( v ), 12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), 13.0, 'returns expected value' ); - t.strictEqual( imag( v ), 14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), 15.0, 'returns expected value' ); - t.strictEqual( imag( v ), 16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 15.0, 16.0, 13.0, 14.0, 11.0, 12.0, 9.0, 10.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (column-major; noncontiguous; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); // eslint-disable-line max-len - shape = [ 2, 2, 1 ]; - order = 'column-major'; - strides = [ 4, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( 0, new Complex64( -9.0, -10.0 ) ); - arr.iset( 1, new Complex64( -11.0, -12.0 ) ); - arr.iset( 2, new Complex64( -13.0, -14.0 ) ); - arr.iset( 3, new Complex64( -15.0, -16.0 ) ); - - v = arr.iget( 0 ); - t.strictEqual( real( v ), -9.0, 'returns expected value' ); - t.strictEqual( imag( v ), -10.0, 'returns expected value' ); - v = arr.iget( 1 ); - t.strictEqual( real( v ), -11.0, 'returns expected value' ); - t.strictEqual( imag( v ), -12.0, 'returns expected value' ); - v = arr.iget( 2 ); - t.strictEqual( real( v ), -13.0, 'returns expected value' ); - t.strictEqual( imag( v ), -14.0, 'returns expected value' ); - v = arr.iget( 3 ); - t.strictEqual( real( v ), -15.0, 'returns expected value' ); - t.strictEqual( imag( v ), -16.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ -9.0, -10.0, 3.0, 4.0, -11.0, -12.0, 7.0, 8.0, -13.0, -14.0, 11.0, 12.0, -15.0, -16.0, 15.0, 16.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (0d)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( -5.0 ); - - t.strictEqual( arr.iget(), -5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, -5.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has an `iset` method for setting an array element using a linear index (0d; complex type)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var v; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - arr.iset( new Complex64( -5.0, -6.0 ) ); - - v = arr.iget(); - t.strictEqual( real( v ), -5.0, 'returns expected value' ); - t.strictEqual( imag( v ), -6.0, 'returns expected value' ); - - t.deepEqual( buffer, new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0, -6.0, 7.0, 8.0 ] ), 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (row-major)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'generic\', [ 3, 4, 5, 6 ], [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (column-major)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'generic\', [ 4, 3, 2, 1 ], [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (complex type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (boolean type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'bool'; - buffer = new BooleanArray( [ true, false, true, false ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'bool\', new BooleanArray( [ true, false, true, false ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (complex type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex128'; - buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'complex128\', new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (0d)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'generic\', [ 4 ], [], [ 0 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (large array)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - - // Intentionally create a sparse array: - buffer = new Array( 1e4 ); // eslint-disable-line stdlib/no-new-array - shape = [ buffer.length ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - buffer[ 0 ] = 1.0; - buffer[ 1 ] = 2.0; - buffer[ 2 ] = 3.0; - buffer[ buffer.length-3 ] = 4.0; - buffer[ buffer.length-2 ] = 5.0; - buffer[ buffer.length-1 ] = 6.0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'generic\', [ 1, 2, 3, ..., 4, 5, 6 ], [ 10000 ], [ 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (large array; complex type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( 1e4 ); - shape = [ buffer.length ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - buffer.set( new Complex64( 1.0, 1.0 ), 0 ); - buffer.set( new Complex64( 2.0, 2.0 ), 1 ); - buffer.set( new Complex64( 3.0, 3.0 ), 2 ); - buffer.set( new Complex64( 4.0, 4.0 ), buffer.length-3 ); - buffer.set( new Complex64( 5.0, 5.0 ), buffer.length-2 ); - buffer.set( new Complex64( 6.0, 6.0 ), buffer.length-1 ); - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'complex64\', new Complex64Array( [ 1, 1, 2, 2, 3, 3, ..., 4, 4, 5, 5, 6, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toString()` method (large array; complex type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex128'; - buffer = new Complex128Array( 1e4 ); - shape = [ buffer.length ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - buffer.set( new Complex128( 1.0, 1.0 ), 0 ); - buffer.set( new Complex128( 2.0, 2.0 ), 1 ); - buffer.set( new Complex128( 3.0, 3.0 ), 2 ); - buffer.set( new Complex128( 4.0, 4.0 ), buffer.length-3 ); - buffer.set( new Complex128( 5.0, 5.0 ), buffer.length-2 ); - buffer.set( new Complex128( 6.0, 6.0 ), buffer.length-1 ); - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toString' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toString' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toString ), true, 'has method' ); - - expected = 'ndarray( \'complex128\', new Complex128Array( [ 1, 1, 2, 2, 3, 3, ..., 4, 4, 5, 5, 6, 6 ] ), [ 10000 ], [ 1 ], 0, \'row-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toJSON()` method (row-major)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toJSON ), true, 'has method' ); - - expected = { - 'type': 'ndarray', - 'dtype': 'float64', - 'data': [ 3.0, 4.0, 5.0, 6.0 ], - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'order': 'row-major', - 'flags': { - 'READONLY': false - } - }; - actual = arr.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toJSON()` method (column-major)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 2, 2 ]; - order = 'column-major'; - strides = [ -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toJSON ), true, 'has method' ); - - expected = { - 'type': 'ndarray', - 'dtype': 'generic', - 'data': [ 4.0, 3.0, 2.0, 1.0 ], - 'shape': [ 2, 2 ], - 'strides': [ 1, 2 ], - 'order': 'column-major', - 'flags': { - 'READONLY': false - } - }; - actual = arr.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toJSON()` method (complex type)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toJSON ), true, 'has method' ); - - expected = { - 'type': 'ndarray', - 'dtype': 'complex64', - 'data': [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ], - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'order': 'row-major', - 'flags': { - 'READONLY': false - } - }; - actual = arr.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `toJSON()` method (0d)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'toJSON' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'toJSON' ), true, 'has property' ); - t.strictEqual( isFunction( arr.toJSON ), true, 'has method' ); - - expected = { - 'type': 'ndarray', - 'dtype': 'generic', - 'data': [ 3.0 ], - 'shape': [], - 'strides': [ 0 ], - 'order': 'row-major', - 'flags': { - 'READONLY': false - } - }; - actual = arr.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `valueOf()` method (0d)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 3.14 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'valueOf' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'valueOf' ), true, 'has property' ); - t.strictEqual( isFunction( arr.valueOf ), true, 'has method' ); - - expected = 3.14; - actual = arr.valueOf(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a custom `valueOf()` method (>=1d)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'generic'; - buffer = [ 1.0, 2.0 ]; - shape = [ 2 ]; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, 'valueOf' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'valueOf' ), true, 'has property' ); - t.strictEqual( isFunction( arr.valueOf ), true, 'has method' ); - - expected = arr; - actual = arr.valueOf(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray has a protocol method for serializing meta data to a DataView', function test( t ) { - /* eslint-disable no-underscore-dangle */ - var expected; - var strides; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, '__array_meta_dataview__' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, '__array_meta_dataview__' ), true, 'has property' ); - t.strictEqual( isFunction( arr.__array_meta_dataview__ ), true, 'has method' ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - arr.__meta_dataview__ = null; - actual = arr.__array_meta_dataview__(); - arr.__meta_dataview__ = null; - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); - - /* eslint-enable no-underscore-dangle */ -}); - -tape( 'an ndarray has a protocol method for serializing meta data to a DataView (no BigInt support)', function test( t ) { - /* eslint-disable no-underscore-dangle */ - var expected; - var strides; - var ndarray; - var actual; - var buffer; - var offset; - var dtype; - var order; - var shape; - var bytes; - var arr; - - ndarray = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( hasOwnProp( arr, '__array_meta_dataview__' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, '__array_meta_dataview__' ), true, 'has property' ); - t.strictEqual( isFunction( arr.__array_meta_dataview__ ), true, 'has method' ); - - expected = { - 'dtype': DTYPES[ 'float64' ], - 'ndims': shape.length, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': ORDERS[ 'row-major' ], - 'mode': MODES[ 'throw' ], - 'nsubmodes': 1, - 'submodes': [ MODES[ 'throw' ] ], - 'flags': 0 - }; - - arr.__meta_dataview__ = null; - actual = arr.__array_meta_dataview__(); - arr.__meta_dataview__ = null; - - t.strictEqual( isDataView( actual ), true, 'returns a DataView' ); - t.strictEqual( actual.byteLength, 1+2+8+(2*8)+(2*8)+8+1+1+8+(1*1)+4, 'returns expected byte length' ); - - bytes = new Uint8Array( actual.buffer ); - if ( IS_LITTLE_ENDIAN ) { - t.strictEqual( bytes[ 0 ], 1, 'returns expected endianness' ); - t.strictEqual( bytes[ 1 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 3 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 11 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 19 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 27 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); - t.strictEqual( bytes[ 35 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); - t.strictEqual( bytes[ 43 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 53 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 62 ], expected.flags, 'returns expected flags' ); - } else { - t.strictEqual( bytes[ 0 ], 0, 'returns expected endianness' ); - t.strictEqual( bytes[ 2 ], expected.dtype, 'returns expected dtype' ); - t.strictEqual( bytes[ 10 ], expected.ndims, 'returns expected ndims' ); - t.strictEqual( bytes[ 18 ], expected.shape[ 0 ], 'returns expected first dimension' ); - t.strictEqual( bytes[ 26 ], expected.shape[ 1 ], 'returns expected second dimension' ); - t.strictEqual( bytes[ 34 ], expected.strides[ 0 ]*arr.BYTES_PER_ELEMENT, 'returns expected first stride' ); - t.strictEqual( bytes[ 42 ], expected.strides[ 1 ]*arr.BYTES_PER_ELEMENT, 'returns expected second stride' ); - t.strictEqual( bytes[ 50 ], expected.offset*arr.BYTES_PER_ELEMENT, 'returns expected offset' ); - t.strictEqual( bytes[ 51 ], expected.order, 'returns expected order' ); - t.strictEqual( bytes[ 52 ], expected.mode, 'returns expected index mode' ); - t.strictEqual( bytes[ 60 ], expected.nsubmodes, 'returns expected number of subscript modes' ); - t.strictEqual( bytes[ 61 ], expected.submodes[ 0 ], 'returns expected submode' ); - t.strictEqual( bytes[ 65 ], expected.flags, 'returns expected flags' ); - } - t.end(); - - function hasSupport() { - return false; - } - - /* eslint-enable no-underscore-dangle */ -}); - -tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { - /* eslint-disable no-underscore-dangle */ - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var dv1; - var dv2; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.__meta_dataview__ = null; - dv1 = arr.__array_meta_dataview__(); - dv2 = arr.__array_meta_dataview__(); - arr.__meta_dataview__ = null; - - t.strictEqual( dv1, dv2, 'returns cached meta data' ); - - t.end(); - - /* eslint-enable no-underscore-dangle */ -}); - -tape( 'an ndarray has a protocol method for serializing meta data to a DataView (cached)', function test( t ) { - /* eslint-disable no-underscore-dangle */ - var ndarray; - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var dv1; - var dv2; - - ndarray = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-bigint-support': hasSupport - }); - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.__meta_dataview__ = null; - dv1 = arr.__array_meta_dataview__(); - dv2 = arr.__array_meta_dataview__(); - arr.__meta_dataview__ = null; - - t.strictEqual( dv1, dv2, 'returns cached meta data' ); - - t.end(); - - function hasSupport() { - return false; - } - - /* eslint-enable no-underscore-dangle */ -});