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 a20cad7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-14T00:31:16.651Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5b48e10..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/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 87e7c1a..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/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 5a4c3e6..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: '1 1 * * 2' - - # 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 + + ```
@@ -726,2842 +717,7 @@ str = JSON.stringify( arr.toJSON() ); -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/ctor.h" -``` - -#### ndarray - -Structure holding ndarray data. - -```c -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include - -struct ndarray { - // Underlying data type: - int16_t dtype; - - // Pointer to the underlying byte array: - uint8_t *data; - - // Number of array dimensions: - int64_t ndims; - - // Array shape (dimensions): - int64_t *shape; - - // Array strides (in bytes) specifying how to iterate over a strided array: - int64_t *strides; - - // Byte offset which specifies the location at which to start iterating over array elements: - int64_t offset; - - // Array order (either row-major (C-style) or column-major (Fortran-style)): - int8_t order; - - // Mode specifying how to handle indices which exceed array dimensions: - int8_t imode; - - // Number of subscript modes: - int64_t nsubmodes; - - // Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis: - int8_t *submodes; - - // Number of array elements: - int64_t length; - - // Size in bytes: - int64_t byteLength; - - // Number of bytes per element (i.e., item size): - int64_t BYTES_PER_ELEMENT; - - // Bit mask providing information regarding the memory layout of the array (e.g., see macros): - int64_t flags; -}; -``` - -#### STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG - -Macro defining a flag indicating whether an ndarray is row-major (C-style) contiguous. - -```c -#define STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG 0x0001 -``` - -Notes: - -- Row-major order indicates that the last ndarray index varies the fastest. -- Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory. -- `strides` array is in reverse order to that of column-major order. -- An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional). - -#### STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG - -Macro defining a flag indicating whether an ndarray is column-major (Fortran-style) contiguous. - -```c -#define STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG 0x0002 -``` - -Notes: - -- Column-major order indicates that the first ndarray index varies the fastest. -- Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory. -- `strides` array is in reverse order to that of row-major order. -- An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional). - -* * * - - - -#### stdlib_ndarray_allocate( dtype, \*data, ndims, \*shape, \*strides, offset, order, imode, nsubmodes, \*submodes ) - -Returns a pointer to a dynamically allocated ndarray. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include -#include -#include - -// Specify the underlying data type: -enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; - -// Create an underlying byte array: -uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -// Specify the number of array dimensions: -int64_t ndims = 1; - -// Specify the array shape: -int64_t shape[] = { 3 }; // vector consisting of 3 doubles - -// Specify the array strides: -int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; - -// Specify the byte offset: -int64_t offset = 0; - -// Specify the array order (note: this does not matter for a 1-dimensional array): -enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; - -// Specify the index mode: -enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; - -// Specify the subscript index modes: -int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -int64_t nsubmodes = 1; - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( dtype, buffer, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **dtype**: `[in] int16_t` [data type][@stdlib/ndarray/dtypes]. -- **data**: `[in] uint8_t*` pointer to the underlying byte array. -- **ndims**: `[in] int64_t` number of dimensions. -- **shape**: `[in] int64_t*` array shape (i.e., dimensions). -- **strides**: `[in] int64_t*` array strides (in bytes). -- **offset**: `[in] int64_t` byte offset specifying the location of the first element. -- **order**: `[in] int8_t` specifies whether an array is [row-major][@stdlib/ndarray/orders] (C-style) or [column-major][@stdlib/ndarray/orders] (Fortran-style). -- **imode**: `[in] int8_t` specifies the [index mode][@stdlib/ndarray/index-modes] (i.e., how to handle indices which exceed array dimensions). -- **nsubmodes**: `[in] int64_t` number of subscript modes. -- **submodes**: `[in] int8_t*` specifies how to handle subscripts which [exceed][@stdlib/ndarray/index-modes] array dimensions on a per dimension basis (if provided fewer submodes than dimensions, submodes are recycled using modulo arithmetic). - -```c -struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int8_t order, int8_t imode, int64_t nsubmodes, int8_t *submodes ); -``` - -Notes: - -- The user is responsible for freeing the allocated memory. -- To allocate a zero-dimensional ndarray, provide a `shape` argument equal to a null pointer, an `ndims` argument equal to `0`, and a `strides` argument consisting of a single element equal to `0`. The `order` argument can be either row-major or column-major and has no effect on data storage or access. - -#### stdlib_ndarray_bytelength( \*arr ) - -Returns the size of an ndarray (in bytes). - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the ndarray size: -int64_t N = stdlib_ndarray_bytelength( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_bytelength( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_data( \*arr ) - -Returns a pointer to an ndarray's underlying byte array. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the underlying byte array: -uint8_t *data = stdlib_ndarray_data( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -uint8_t * stdlib_ndarray_data( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_dimension( \*arr, i ) - -Returns an ndarray dimension. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve a dimension: -int64_t dim = stdlib_ndarray_dimension( x, 0 ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **i**: `[in] int64_t` dimension index. - -```c -int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i ); -``` - -Notes: - -- The function does perform bounds checking for the dimension index. -- If an input ndarray is zero-dimensional, the function always returns `-1`. - -#### stdlib_ndarray_disable_flags( \*arr, flags ) - -Disables specified ndarray flags. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Disables specified ndarray flags: -int8_t status = stdlib_ndarray_disable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **flags**: `[in] int64_t` bit mask to disable flags. - -The function returns a status code of `0` if able to successfully disable flags. - -```c -int8_t stdlib_ndarray_disable_flags( const struct ndarray *arr, const int64_t flags ); -``` - -Notes: - -- The function does not perform any sanity checks and **assumes** the user knows what s/he is doing. - -#### stdlib_ndarray_dtype( \*arr ) - -Returns the data type of an ndarray. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/dtypes.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the dtype: -enum STDLIB_NDARRAY_DTYPE dtype = stdlib_ndarray_dtype( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int16_t stdlib_ndarray_dtype( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_enable_flags( \*arr, flags ) - -Enables specified ndarray flags. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Enables specified ndarray flags: -int8_t status = stdlib_ndarray_enable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **flags**: `[in] int64_t` bit mask to enable flags. - -The function returns a status code of `0` if able to successfully enable flags. - -```c -int8_t stdlib_ndarray_enable_flags( const struct ndarray *arr, const int64_t flags ); -``` - -Notes: - -- The function does not perform any sanity checks and **assumes** the user knows what s/he is doing. - -#### stdlib_ndarray_flags( \*arr ) - -Returns ndarray flags as a single integer value. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the ndarray flags: -int64_t flags = stdlib_ndarray_flags( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_flags( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_free( \*arr ) - -Frees an ndarray's allocated memory. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -void stdlib_ndarray_free( struct ndarray *arr ); -``` - -#### stdlib_ndarray_has_flags( \*arr, flags ) - -Tests whether an ndarray has specified flags enabled. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Test whether an ndarray is row-major contiguous: -int8_t out = stdlib_ndarray_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **flags**: `[in] int64_t` bit mask specifying flags to test against. - -The function returns `1` if flags are set and `0` otherwise. - -```c -int8_t stdlib_ndarray_has_flags( const struct ndarray *arr, const int64_t flags ); -``` - -#### stdlib_ndarray_index_mode( \*arr ) - -Returns the index mode of an ndarray. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the index mode: -enum STDLIB_NDARRAY_INDEX_MODE imode = stdlib_ndarray_index_mode( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int8_t stdlib_ndarray_index_mode( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_length( \*arr ) - -Returns the number of elements in an ndarray. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the number of elements: -int64_t N = stdlib_ndarray_length( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_length( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_ndims( \*arr ) - -Returns the number of ndarray dimensions. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the number of dimensions: -int64_t ndims = stdlib_ndarray_ndims( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_ndims( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_nsubmodes( \*arr ) - -Returns the number of ndarray subscript modes. - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the number of index modes: -int64_t n = stdlib_ndarray_nsubmodes( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_nsubmodes( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_offset( \*arr ) - -Returns an ndarray index offset (in bytes). - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the index offset: -int64_t offset = stdlib_ndarray_offset( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t stdlib_ndarray_offset( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_order( \*arr ) - -Returns the order of an ndarray. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/orders.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the order: -enum STDLIB_NDARRAY_ORDER order = stdlib_ndarray_order( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int8_t stdlib_ndarray_order( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_shape( \*arr ) - -Returns a pointer to an array containing an ndarray shape (dimensions). - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the shape: -int64_t *shape = stdlib_ndarray_shape( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t * stdlib_ndarray_shape( const struct ndarray *arr ); -``` - -Notes: - -- If an input ndarray is zero-dimensional, the function returns a null pointer. - -#### stdlib_ndarray_stride( \*arr, i ) - -Returns an ndarray stride (in bytes). - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve a stride: -int64_t s = stdlib_ndarray_stride( x, 0 ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **i**: `[in] int64_t` dimension index. - -```c -int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i ); -``` - -Notes: - -- The function does perform bounds checking for the dimension index. - -#### stdlib_ndarray_strides( \*arr ) - -Returns a pointer to an array containing ndarray strides (in bytes). - -```c -#include "stdlib/ndarray/ctor.h" -#include -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the strides: -int64_t *strides = stdlib_ndarray_strides( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int64_t * stdlib_ndarray_strides( const struct ndarray *arr ); -``` - -#### stdlib_ndarray_submode( \*arr, i ) - -Returns an ndarray subscript mode. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve an index mode: -enum STDLIB_NDARRAY_INDEX_MODE mode = stdlib_ndarray_submode( x, 0 ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **i**: `[in] int64_t` dimension index. - -```c -int8_t stdlib_ndarray_submode( const struct ndarray *arr, const int64_t i ); -``` - -Notes: - -- If an ndarray has fewer subscript modes than dimensions, modes are recycled using modulo arithmetic. -- The function does not perform bounds checking for the dimension index. - -#### stdlib_ndarray_submodes( \*arr ) - -Returns ndarray subscript modes. - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include - -// ... - -// Create an ndarray: -struct ndarray *x = stdlib_ndarray_allocate( ... ); -if ( x == NULL ) { - fprintf( stderr, "Error allocating memory.\n" ); - exit( 1 ); -} - -// ... - -// Retrieve the index subscript modes: -int8_t *modes = stdlib_ndarray_submodes( x ); - -// ... - -// Free allocated memory: -stdlib_ndarray_free( x ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. - -```c -int8_t * stdlib_ndarray_submodes( const struct ndarray *arr ); -``` - -* * * - -#### stdlib_ndarray_get( \*arr, \*sub, \*out ) - -Returns an ndarray data element. - -```c -int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] void *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. - -#### stdlib_ndarray_get_float64( \*arr, \*sub, \*out ) - -Returns a double-precision floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_get_float64( const struct ndarray *arr, const int64_t *sub, double *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] double *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_float32( \*arr, \*sub, \*out ) - -Returns a single-precision floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_get_float32( const struct ndarray *arr, const int64_t *sub, float *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] float *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_uint64( \*arr, \*sub, \*out ) - -Returns an unsigned 64-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_uint64( const struct ndarray *arr, const int64_t *sub, uint64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] uint64_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_int64( \*arr, \*sub, \*out ) - -Returns a signed 64-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_int64( const struct ndarray *arr, const int64_t *sub, int64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] int64_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_uint32( \*arr, \*sub, \*out ) - -Returns an unsigned 32-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_uint32( const struct ndarray *arr, const int64_t *sub, uint32_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] uint32_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_int32( \*arr, \*sub, \*out ) - -Returns a signed 32-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_int32( const struct ndarray *arr, const int64_t *sub, int32_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] int32_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_uint16( \*arr, \*sub, \*out ) - -Returns an unsigned 16-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_uint16( const struct ndarray *arr, const int64_t *sub, uint16_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] uint16_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_int16( \*arr, \*sub, \*out ) - -Returns a signed 16-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_int16( const struct ndarray *arr, const int64_t *sub, int16_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] int16_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_uint8( \*arr, \*sub, \*out ) - -Returns an unsigned 8-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_uint8( const struct ndarray *arr, const int64_t *sub, uint8_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] uint8_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_int8( \*arr, \*sub, \*out ) - -Returns a signed 8-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_get_int8( const struct ndarray *arr, const int64_t *sub, int8_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] int8_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_complex128( \*arr, \*sub, \*out ) - -Returns a double-precision complex floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_get_complex128( const struct ndarray *arr, const int64_t *sub, stdlib_complex128_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] stdlib_complex128_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_complex64( \*arr, \*sub, \*out ) - -Returns a single-precision complex floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_get_complex64( const struct ndarray *arr, const int64_t *sub, stdlib_complex64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] stdlib_complex64_t *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -#### stdlib_ndarray_get_bool( \*arr, \*sub, \*out ) - -Returns a boolean ndarray data element. - -```c -int8_t stdlib_ndarray_get_bool( const struct ndarray *arr, const int64_t *sub, bool *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. -- **out**: `[out] bool *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. - -* * * - -#### stdlib_ndarray_get_ptr( \*arr, \*sub ) - -Returns a pointer to an ndarray data element in the underlying byte array. - -```c -uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **sub**: `[in] int64_t *` ndarray subscripts. - -#### stdlib_ndarray_get_ptr_value( \*arr, \*idx, \*out ) - -Returns an ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray *` input ndarray. -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] void *` output address. - -Notes: - -- The function does **not** perform bounds checking and **assumes** you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. - -#### stdlib_ndarray_get_ptr_float64( \*idx, \*out ) - -Returns a double-precision floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_float64( const uint8_t *idx, double *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] double *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_float32( \*idx, \*out ) - -Returns a single-precision floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_float32( const uint8_t *idx, float *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] float *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_uint64( \*idx, \*out ) - -Returns an unsigned 64-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_uint64( const uint8_t *idx, uint64_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] uint64_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_int64( \*idx, \*out ) - -Returns a signed 64-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_int64( const uint8_t *idx, int64_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] int64_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_uint32( \*idx, \*out ) - -Returns an unsigned 32-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_uint32( const uint8_t *idx, uint32_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] uint32_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_int32( \*idx, \*out ) - -Returns a signed 32-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_int32( const uint8_t *idx, int32_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] int32_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_uint16( \*idx, \*out ) - -Returns an unsigned 16-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_uint16( const uint8_t *idx, uint16_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] uint16_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_int16( \*idx, \*out ) - -Returns a signed 16-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_int16( const uint8_t *idx, int16_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] int16_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_uint8( \*idx, \*out ) - -Returns an unsigned 8-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_uint8( const uint8_t *idx, uint8_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] uint8_t *` output address. - -Notes: - -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_int8( \*idx, \*out ) - -Returns a signed 8-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_int8( const uint8_t *idx, int8_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] int8_t *` output address. - -Notes: - -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_complex128( \*idx, \*out ) - -Returns a double-precision complex floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_complex128( const uint8_t *idx, stdlib_complex128_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] stdlib_complex128_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_complex64( \*idx, \*out ) - -Returns a single-precision complex floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_complex64( const uint8_t *idx, stdlib_complex64_t *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] stdlib_complex64_t *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_get_ptr_bool( \*idx, \*out ) - -Returns a boolean ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_get_ptr_bool( const uint8_t *idx, bool *out ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t *` byte array pointer to an ndarray data element. -- **out**: `[out] bool *` output address. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -* * * - -#### stdlib_ndarray_iget( \*arr, idx, \*out ) - -Returns an ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget( const struct ndarray *arr, const int64_t idx, void *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] void *` output address. - -Notes: - -- The function returns `-1` if unable to get an element and `0` otherwise. -- The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. -- The function places the burden on the user to ensure that the output address is compatible with the data type of input ndarray data elements. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_float64( \*arr, idx, \*out ) - -Returns a double-precision floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_float64( const struct ndarray *arr, const int64_t idx, double *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] double *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_float32( \*arr, idx, \*out ) - -Returns a single-precision floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_float32( const struct ndarray *arr, const int64_t idx, float *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] float *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_uint64( \*arr, idx, \*out ) - -Returns an unsigned 64-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_uint64( const struct ndarray *arr, const int64_t idx, uint64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] uint64_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_int64( \*arr, idx, \*out ) - -Returns a signed 64-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_int64( const struct ndarray *arr, const int64_t idx, int64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] int64_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_uint32( \*arr, idx, \*out ) - -Returns an unsigned 32-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_uint32( const struct ndarray *arr, const int64_t idx, uint32_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] uint32_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_int32( \*arr, idx, \*out ) - -Returns a signed 32-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_int32( const struct ndarray *arr, const int64_t idx, int32_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] int32_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_uint16( \*arr, idx, \*out ) - -Returns an unsigned 16-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_uint16( const struct ndarray *arr, const int64_t idx, uint16_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] uint16_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_int16( \*arr, idx, \*out ) - -Returns a signed 16-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_int16( const struct ndarray *arr, const int64_t idx, int16_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] int16_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_uint8( \*arr, idx, \*out ) - -Returns an unsigned 8-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_uint8( const struct ndarray *arr, const int64_t idx, uint8_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] uint8_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_int8( \*arr, idx, \*out ) - -Returns a signed 8-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_int8( const struct ndarray *arr, const int64_t idx, int8_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] int8_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_complex128( \*arr, idx, \*out ) - -Returns a double-precision complex floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_complex128( const struct ndarray *arr, const int64_t idx, stdlib_complex128_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] stdlib_complex128_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_complex64( \*arr, idx, \*out ) - -Returns a single-precision complex floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_complex64( const struct ndarray *arr, const int64_t idx, stdlib_complex64_t *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] stdlib_complex64_t *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iget_bool( \*arr, idx, \*out ) - -Returns a boolean ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iget_bool( const struct ndarray *arr, const int64_t idx, bool *out ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **out**: `[out] bool *` output address. - -Notes: - -- The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -- The function returns `-1` if unable to get an element and `0` otherwise. -- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. - -* * * - -#### stdlib_ndarray_iget_ptr( \*arr, idx ) - -Returns a pointer in the underlying byte array for an ndarray data element located at a specified linear index. - -```c -uint8_t * stdlib_ndarray_iget_ptr( const struct ndarray *arr, const int64_t idx ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. - -For zero-dimensional arrays, the function returns a pointer to the first (and only) indexed element, regardless of the value of `idx`. - -* * * - -#### stdlib_ndarray_iset( \*arr, idx, \*v ) - -Sets an ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset( const struct ndarray *arr, const int64_t idx, const void *v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] void*` value to set. - -Notes: - -- The function returns `-1` if unable to set an element and `0` otherwise. -- The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. -- The function has no way of determining whether `v` actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_float64( \*arr, idx, v ) - -Sets a double-precision floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_float64( const struct ndarray *arr, const int64_t idx, const double v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] double` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_float32( \*arr, idx, v ) - -Sets a single-precision floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_float32( const struct ndarray *arr, const int64_t idx, const float v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] float` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_uint64( \*arr, idx, v ) - -Sets an unsigned 64-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_uint64( const struct ndarray *arr, const int64_t idx, const uint64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] uint64_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_int64( \*arr, idx, v ) - -Sets a signed 64-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_int64( const struct ndarray *arr, const int64_t idx, const int64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] int64_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_uint32( \*arr, idx, v ) - -Sets an unsigned 32-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_uint32( const struct ndarray *arr, const int64_t idx, const uint32_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] uint32_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_int32( \*arr, idx, v ) - -Sets a signed 32-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_int32( const struct ndarray *arr, const int64_t idx, const int32_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] int32_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_uint16( \*arr, idx, v ) - -Sets an unsigned 16-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_uint16( const struct ndarray *arr, const int64_t idx, const uint16_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] uint16_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_int16( \*arr, idx, v ) - -Sets a signed 16-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_int16( const struct ndarray *arr, const int64_t idx, const int16_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] int16_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_uint8( \*arr, idx, v ) - -Sets an unsigned 8-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_uint8( const struct ndarray *arr, const int64_t idx, const uint8_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] uint8_t` value to set. - -Notes: - -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_int8( \*arr, idx, v ) - -Sets a signed 8-bit integer ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_int8( const struct ndarray *arr, const int64_t idx, const int8_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] int8_t` value to set. - -Notes: - -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_complex128( \*arr, idx, v ) - -Sets a double-precision complex floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_complex128( const struct ndarray *arr, const int64_t idx, const stdlib_complex128_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] stdlib_complex128_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_complex64( \*arr, idx, v ) - -Sets a single-precision complex floating-point ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_complex64( const struct ndarray *arr, const int64_t idx, const stdlib_complex64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] stdlib_complex64_t` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -#### stdlib_ndarray_iset_bool( \*arr, idx, v ) - -Sets a boolean ndarray data element located at a specified linear index. - -```c -int8_t stdlib_ndarray_iset_bool( const struct ndarray *arr, const int64_t idx, const bool v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] int64_t` linear view index. -- **v**: `[in] bool` value to set. - -Notes: - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. - -* * * - -#### stdlib_ndarray_set( \*arr, \*sub, \*v ) - -Sets an ndarray data element. - -```c -int8_t stdlib_ndarray_set( const struct ndarray *arr, const int64_t *sub, const void *v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] void*` value to set. - -Notes - -- The function returns `-1` if unable to set an element and `0` otherwise. -- The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. -- The function has no way of determining whether `v` actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. - -#### stdlib_ndarray_set_float64( \*arr, \*sub, v ) - -Sets a double-precision floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_set_float64( const struct ndarray *arr, const int64_t *sub, const double v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] double` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_float32( \*arr, \*sub, v ) - -Sets a single-precision floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_set_float32( const struct ndarray *arr, const int64_t *sub, const float v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] float` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_uint64( \*arr, \*sub, v ) - -Sets an unsigned 64-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_uint64( const struct ndarray *arr, const int64_t *sub, const uint64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] uint64_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_int64( \*arr, \*sub, v ) - -Sets a signed 64-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_int64( const struct ndarray *arr, const int64_t *sub, const int64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] int64_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_uint32( \*arr, \*sub, v ) - -Sets an unsigned 32-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_uint32( const struct ndarray *arr, const int64_t *sub, const uint32_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] uint32_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_int32( \*arr, \*sub, v ) - -Sets a signed 32-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_int32( const struct ndarray *arr, const int64_t *sub, const int32_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] int32_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_uint16( \*arr, \*sub, v ) - -Sets an unsigned 16-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_uint16( const struct ndarray *arr, const int64_t *sub, const uint16_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] uint16_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_int16( \*arr, \*sub, v ) - -Sets a signed 16-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_int16( const struct ndarray *arr, const int64_t *sub, const int16_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] int16_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_uint8( \*arr, \*sub, v ) - -Sets an unsigned 8-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_uint8( const struct ndarray *arr, const int64_t *sub, const uint8_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] uint8_t` value to set. - -Notes - -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_int8( \*arr, \*sub, v ) - -Sets a signed 8-bit integer ndarray data element. - -```c -int8_t stdlib_ndarray_set_int8( const struct ndarray *arr, const int64_t *sub, const int8_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] int8_t` value to set. - -Notes - -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_complex128( \*arr, \*sub, v ) - -Sets a double-precision complex floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_set_complex128( const struct ndarray *arr, const int64_t *sub, const stdlib_complex128_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] stdlib_complex128_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_complex64( \*arr, \*sub, v ) - -Sets a single-precision complex floating-point ndarray data element. - -```c -int8_t stdlib_ndarray_set_complex64( const struct ndarray *arr, const int64_t *sub, const stdlib_complex64_t v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] stdlib_complex64_t` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -#### stdlib_ndarray_set_bool( \*arr, \*sub, v ) - -Sets a boolean ndarray data element. - -```c -int8_t stdlib_ndarray_set_bool( const struct ndarray *arr, const int64_t *sub, const bool v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **sub**: `[in] int64_t*` ndarray subscripts. -- **v**: `[in] bool` value to set. - -Notes - -- The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. - -* * * - -#### stdlib_ndarray_set_ptr_value( \*arr, \*idx, \*v ) - -Sets an ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_value( const struct ndarray *arr, uint8_t *idx, const void *v ); -``` - -The function accepts the following arguments: - -- **arr**: `[in] struct ndarray*` input ndarray. -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] void*` value to set. - -Notes: - -- The function does **not** perform bounds checking, and, thus, the function does **not** prevent you from overwriting **unowned** memory. Accordingly, the function **assumes** you know what you are doing. -- The function returns `-1` if unable to set an element and `0` otherwise. -- The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. - -#### stdlib_ndarray_set_ptr_float64( \*idx, v ) - -Sets a double-precision floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_float64( uint8_t *idx, const double v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] double` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_float32( \*idx, v ) - -Sets a single-precision floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_float32( uint8_t *idx, const float v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] float` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_uint64( \*idx, v ) - -Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_uint64( uint8_t *idx, const uint64_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] uint64_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_int64( \*idx, v ) - -Sets a signed 64-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_int64( uint8_t *idx, const int64_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] int64_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_uint32( \*idx, v ) - -Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_uint32( uint8_t *idx, const uint32_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] uint32_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_int32( \*idx, v ) - -Sets a signed 32-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_int32( uint8_t *idx, const int32_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] int32_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_uint16( \*idx, v ) - -Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_uint16( uint8_t *idx, const uint16_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] uint16_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_int16( \*idx, v ) - -Sets a signed 16-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_int16( uint8_t *idx, const int16_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] int16_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_uint8( \*idx, v ) - -Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_uint8( uint8_t *idx, const uint8_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] uint8_t` value to set. - -Notes: - -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_int8( \*idx, v ) - -Sets a signed 8-bit integer ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_int8( uint8_t *idx, const int8_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] int8_t` value to set. - -Notes: - -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_complex128( \*idx, v ) - -Sets a double-precision complex floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_complex128( uint8_t *idx, const stdlib_complex128_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] stdlib_complex128_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_complex64( \*idx, v ) - -Sets a single-precision complex floating-point ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_complex64( uint8_t *idx, const stdlib_complex64_t v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] stdlib_complex64_t` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -#### stdlib_ndarray_set_ptr_bool( \*idx, v ) - -Sets a boolean ndarray data element specified by a byte array pointer. - -```c -int8_t stdlib_ndarray_set_ptr_bool( uint8_t *idx, const bool v ); -``` - -The function accepts the following arguments: - -- **idx**: `[in] uint8_t*` byte array pointer to an ndarray data element. -- **v**: `[in] bool` value to set. - -Notes: - -- The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -- The function always returns `0`. - -
- - - - - -
- -
- - - - - -* * * - -
- -### Examples - -```c -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include "stdlib/ndarray/base/dtype_char.h" -#include -#include -#include -#include - -void print_ndarray_contents( const struct ndarray *x ) { - int64_t i; - double v; - int8_t s; - - for ( i = 0; i < stdlib_ndarray_length( x ); i++ ) { - s = stdlib_ndarray_iget_float64( x, i, &v ); // WARNING: assumes `x->dtype` is float64 - if ( s != 0 ) { - printf( "Unable to resolve data element.\n" ); - exit( 1 ); - } - printf( "data[%"PRId64"] = %f\n", i, v ); - } -} - -int main( void ) { - // Manually create an ndarray (WARNING: this is for illustration purposes only, as the fields of an ndarray are subject to change; for ABI compatibility, use utility functions for accessing ndarray data)... - struct ndarray *x1 = malloc( sizeof( struct ndarray ) ); - if ( x1 == NULL ) { - printf( "Error allocating memory.\n" ); - exit( 1 ); - } - - // Specify the underlying data type: - enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; - x1->dtype = dtype; - - // Create an underlying byte array: - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - x1->data = buffer; - - // Explicitly specify the number of bytes per element: - x1->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; - - // Specify the array shape: - int64_t shape[] = { 3 }; // vector consisting of 3 doubles - x1->shape = shape; - - // Specify the array strides: - int64_t strides[] = { x1->BYTES_PER_ELEMENT }; - x1->strides = strides; - - // Specify the byte offset: - x1->offset = 0; - - // Specify the array order (note: this does not matter for a 1-dimensional array): - enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; - x1->order = order; - - // Specify the index mode: - enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; - x1->imode = imode; - - // Specify the subscript index modes: - int8_t submodes[] = { imode }; - x1->submodes = submodes; - x1->nsubmodes = 1; - - // Explicitly specify the number of array dimensions: - x1->ndims = 1; // vector - - // Explicitly specify the number of array elements (doubles): - x1->length = x1->shape[ 0 ]; - - // Explicitly specify the number of bytes: - x1->byteLength = (x1->length) * (x1->BYTES_PER_ELEMENT); - - // Explicitly set the array flags: - x1->flags = stdlib_ndarray_flags( x1 ); - - printf( "dtype = %u\n", stdlib_ndarray_dtype( x1 ) ); - printf( "length = %"PRId64"\n", stdlib_ndarray_length( x1 ) ); - printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x1 ) ); - printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x1 ) ) ); - printf( "\n" ); - - // Use the function interface to create an ndarray (NOTE: for future ABI compatibility, using the following function interface should be preferred)... - struct ndarray *x2 = stdlib_ndarray_allocate( dtype, buffer, 1, shape, strides, 0, order, imode, 1, submodes ); - if ( x2 == NULL ) { - printf( "Error allocating memory.\n" ); - exit( 1 ); - } - - printf( "dtype = %u\n", stdlib_ndarray_dtype( x2 ) ); - printf( "length = %"PRId64"\n", stdlib_ndarray_length( x2 ) ); - printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x2 ) ); - printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x2 ) ) ); - printf( "\n" ); - - // Set values in the underlying byte array using pointers: - int64_t sub[] = { 0 }; - uint8_t *ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 1.0; - - sub[ 0 ] = 1; - ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 2.0; - - sub[ 0 ] = 2; - ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 3.0; - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Set values in the underlying byte array using a "generic" function: - sub[ 0 ] = 0; - double v = 4.0; - int8_t status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 1; - v = 5.0; - status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 2; - v = 6.0; - status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Set values in the underlying byte array using a specialized function: - sub[ 0 ] = 0; - status = stdlib_ndarray_set_float64( x2, sub, 7.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 1; - status = stdlib_ndarray_set_float64( x2, sub, 8.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 2; - status = stdlib_ndarray_set_float64( x2, sub, 9.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Free allocated memory: - stdlib_ndarray_free( x1 ); - stdlib_ndarray_free( x2 ); -} -``` - -
- - - -
- @@ -3595,7 +751,7 @@ int main( void ) { ## 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]. @@ -3660,17 +816,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/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders +[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders/tree/esm -[@stdlib/ndarray/index-modes]: https://github.com/stdlib-js/ndarray-index-modes +[@stdlib/ndarray/index-modes]: https://github.com/stdlib-js/ndarray-index-modes/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/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/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.attributes.js b/benchmark/benchmark.attributes.js deleted file mode 100644 index 2a6431a..0000000 --- a/benchmark/benchmark.attributes.js +++ /dev/null @@ -1,655 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -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(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index d198ce4..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,783 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d: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 = [ 6 ]; - 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[ 1 ] = i; - v = out.get( i%6 ); - 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+'::1d:get:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%20)-10 ); - 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+'::1d:get:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%20)-10 ); - 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+'::1d:get:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%12)-6 ); - 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+'::2d: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 ] = i; - v = out.get( i%3, 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+'::2d:get:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%30)-15, 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+'::2d:get:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%30)-15, 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+'::2d:get:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( (i%6)-3, 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+'::3d: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 = [ 1, 3, 2 ]; - strides = [ 6, 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 ] = i; - v = out.get( 0, i%3, 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+'::3d:get:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, (i%30)-15, 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+'::3d:get:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, (i%30)-15, 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+'::3d:get:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, (i%6)-3, 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+'::4d: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 = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 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 ] = i; - v = out.get( 0, 0, i%3, 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+'::4d:get:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, (i%30)-15, 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+'::4d:get:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, (i%30)-15, 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+'::4d:get:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, (i%6)-3, 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+'::5d: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 = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 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 ] = i; - v = out.get( 0, 0, 0, i%3, 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+'::5d:get:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, 0, (i%30)-15, 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+'::5d:get:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, 0, (i%30)-15, 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+'::5d:get:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.get( 0, 0, 0, (i%6)-3, 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(); -}); diff --git a/benchmark/benchmark.iget.js b/benchmark/benchmark.iget.js deleted file mode 100644 index edcd737..0000000 --- a/benchmark/benchmark.iget.js +++ /dev/null @@ -1,383 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d:iget', 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 = [ 6 ]; - 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[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::1d:iget:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::1d:iget:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::1d:iget:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( (i%12)-6 ); - 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+'::2d,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 ] = i; - v = out.iget( i%6 ); - 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+'::2d,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 ] = i; - v = out.iget( i%6 ); - 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+'::2d,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 = 5; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::2d,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 = 5; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::2d,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 = 4; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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+'::2d,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 = 4; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 1 ] = i; - v = out.iget( i%6 ); - 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(); -}); diff --git a/benchmark/benchmark.instantiation.js b/benchmark/benchmark.instantiation.js deleted file mode 100644 index 32c7532..0000000 --- a/benchmark/benchmark.instantiation.js +++ /dev/null @@ -1,338 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,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 = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::1d,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 = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::2d,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 ] = i; - 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+'::2d,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 ] = i; - 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+'::3d,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 = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::3d,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 = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::4d,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 = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::4d,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 = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::5d,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 = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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+'::5d,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 = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - buffer[ 0 ] = i; - 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(); -}); diff --git a/benchmark/benchmark.iset.js b/benchmark/benchmark.iset.js deleted file mode 100644 index 9f2f492..0000000 --- a/benchmark/benchmark.iset.js +++ /dev/null @@ -1,406 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d:iset', 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 = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - 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+'::1d:iset:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.iset( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.iget( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d:iset:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.iset( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.iget( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d:iset:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%12) - 6; - tmp = out.iset( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.iget( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,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 = i; - j = i % 6; - 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+'::2d,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 = i; - j = i % 6; - 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+'::2d,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 = 5; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - out.iset( j, v ); - if ( buffer[ 5-j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ 5-j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,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 = 5; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - out.iset( j, v ); - if ( buffer[ 5-j ] !== v ) { - b.fail( 'should set value' ); - } - } - b.toc(); - if ( buffer[ 5-j ] !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,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 = 4; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - 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+'::2d,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 = 4; - order = 'column-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - 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(); -}); diff --git a/benchmark/benchmark.set.js b/benchmark/benchmark.set.js deleted file mode 100644 index 6e37d2e..0000000 --- a/benchmark/benchmark.set.js +++ /dev/null @@ -1,838 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d: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 = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = i % 6; - out.set( 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+'::1d:set:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%20) - 10; - tmp = out.set( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d:set:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%20) - 10; - tmp = out.set( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d:set:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 6 ]; - strides = [ 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%12) - 6; - tmp = out.set( j, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d: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 = i; - j = i % 3; - 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+'::2d:set:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d:set:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d:set:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%6) - 3; - tmp = out.set( j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d: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 = [ 1, 3, 2 ]; - strides = [ 6, 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 = i; - j = i % 3; - out.set( 0, 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+'::3d:set:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d:set:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d:set:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 3, 2 ]; - strides = [ 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%6) - 3; - tmp = out.set( 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d: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 = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 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 = i; - j = i % 3; - out.set( 0, 0, 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+'::4d:set:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d:set:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d:set:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 3, 2 ]; - strides = [ 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%6) - 3; - tmp = out.set( 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d: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 = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 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 = i; - j = i % 3; - out.set( 0, 0, 0, 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+'::5d:set:mode=wrap', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'wrap' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d:set:mode=clamp', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'clamp' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%30) - 15; - tmp = out.set( 0, 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d:set:mode=normalize', function benchmark( b ) { - var strides; - var buffer; - var offset; - var shape; - var order; - var opts; - var out; - var tmp; - var v; - var i; - var j; - - opts = { - 'mode': 'normalize' - }; - - buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - shape = [ 1, 1, 1, 3, 2 ]; - strides = [ 6, 6, 6, 2, 1 ]; - offset = 0; - order = 'row-major'; - - out = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = i; - j = (i%6) - 3; - tmp = out.set( 0, 0, 0, j, 1, v ); - if ( typeof tmp !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.get( 0, 0, 0, j, 1 ) !== v ) { - b.fail( 'should set value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index 747482b..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -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 ] = i; - 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(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 798733e..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var ndarray = require( './../lib' ); - - -// MAIN // - -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 ] = i; - 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(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index d9f6eb6..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,3640 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include -#include -#include -#include -#include -#include -#include - -#define NAME "ndarray" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL || arr->ndims != 2 ) { - printf( "unexpected result\n" ); - break; - } - if ( i < ITERATIONS-1 ) { - stdlib_ndarray_free( arr ); - } - } - elapsed = tic() - t; - - if ( arr == NULL || arr->ndims != 2 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_bytelength( arr ); - if ( v != 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - uint8_t *v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - buffer[ 0 ] = i % 255; // cppcheck-suppress unreadVariable - v = stdlib_ndarray_data( arr ); - if ( v[ 0 ] != (i%255) ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v[ 0 ] != ((i-1)%255) ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - enum STDLIB_NDARRAY_DTYPE v; - double elapsed; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_dtype( arr ); - if ( v != STDLIB_NDARRAY_UINT8 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != STDLIB_NDARRAY_UINT8 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - v = stdlib_ndarray_flags( arr ); - if ( v < 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v < 0 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_length( arr ); - if ( v != (arr->length) ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != (arr->length) ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_ndims( arr ); - if ( v != ndims ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != ndims ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_offset( arr ); - if ( v != offset ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != offset ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - enum STDLIB_NDARRAY_ORDER v; - double elapsed; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_order( arr ); - if ( v != STDLIB_NDARRAY_ROW_MAJOR ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != STDLIB_NDARRAY_ROW_MAJOR ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t *v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_shape( arr ); - if ( v[ 0 ] != shape[ 0 ] || v[ 1 ] != shape[ 1 ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v[ 0 ] != shape[ 0 ] || v[ 1 ] != shape[ 1 ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t *v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_strides( arr ); - if ( v[ 0 ] != strides[ 0 ] || v[ 1 ] != strides[ 1 ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v[ 0 ] != strides[ 0 ] || v[ 1 ] != strides[ 1 ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( rand_double()*shape[0] ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v != buffer[ sub[0] ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v != buffer[ sub[0] ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark13( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*20.0)-10.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark14( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*20.0)-10.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 ) { - printf( "unexpected result\n" ); - } else if ( sub[0] < 0 && v != buffer[ 0 ] ) { - printf( "unexpected result when negative subscript: %u != %u\n", buffer[ 0 ], v ); - } else if ( sub[0] >= shape[0] && v != buffer[ shape[0]-1 ] ) { - printf( "unexpected result when subscript exceeds dimensions: %u != %u\n", buffer[ shape[0]-1 ], v ); - } else if ( sub[0] >= 0 && sub[0] < shape[0] && v != buffer[ sub[0] ] ) { - printf( "unexpected result for normal subscript: %u != %u\n", buffer[ sub[0] ], v ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark15( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( rand_double()*shape[0] ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark16( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark17( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark18( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( (rand_double()*shape[1])-0.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark19( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark20( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark21( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*shape[2])-0.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark22( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark23( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark24( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( (rand_double()*shape[3])-0.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark25( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark26( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_get( arr, sub, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark27( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*shape[0])-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark28( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result: idx=%"PRId64", v=%u\n", idx, v ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark29( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*30.0)-15.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark30( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark31( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 1, 3 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark32( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark33( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -1, -3 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark34( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, 1 }; - int64_t offset = 4; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark35( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 1, -3 }; - int64_t offset = 3; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - s = stdlib_ndarray_iget( arr, idx, (void *)&v ); - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || v > 6 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark36( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( rand_double()*shape[0] ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 || buffer[ sub[0] ] != v ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || buffer[ sub[0] ] != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark37( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark38( void ) { - double elapsed; - int64_t sub[1]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 ) { - printf( "unexpected result\n" ); - } else if ( sub[0] < 0 && buffer[ 0 ] != v ) { - printf( "unexpected result when negative subscript: %u != %u\n", buffer[ 0 ], v ); - } else if ( sub[0] >= shape[0] && buffer[ shape[0]-1 ] != v ) { - printf( "unexpected result when subscript exceeds dimensions: %u != %u\n", buffer[ shape[0]-1 ], v ); - } else if ( sub[0] >= 0 && sub[0] < shape[0] && buffer[ sub[0] ] != v ) { - printf( "unexpected result for normal subscript: %u != %u\n", buffer[ sub[0] ], v ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark39( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( rand_double()*shape[0] ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark40( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark41( void ) { - double elapsed; - int64_t sub[2]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 1 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 0 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark42( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( rand_double()*shape[1] ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark43( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark44( void ) { - double elapsed; - int64_t sub[3]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 3; - int64_t shape[] = { 1, 3, 2 }; - int64_t strides[] = { 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 2 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 1 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark45( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*shape[2] ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark46( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark47( void ) { - double elapsed; - int64_t sub[4]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 4; - int64_t shape[] = { 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 3 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark48( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( rand_double()*shape[3] ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark49( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark50( void ) { - double elapsed; - int64_t sub[5]; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 5; - int64_t shape[] = { 1, 1, 1, 3, 2 }; - int64_t strides[] = { 6, 6, 6, 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - sub[ 0 ] = 0; - sub[ 1 ] = 0; - sub[ 2 ] = 0; - sub[ 4 ] = 1; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 3 ] = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_set( arr, sub, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_get_ptr( arr, sub )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark51( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*shape[0])-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 || buffer[ idx ] != v ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || buffer[ idx ] != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark52( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_WRAP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx)) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark53( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 1; - int64_t shape[] = { 6 }; - int64_t strides[] = { 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_CLAMP; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*30.0)-15.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 ) { - printf( "unexpected result\n" ); - } else if ( idx < 0 && buffer[ 0 ] != v ) { - printf( "unexpected result when negative linear index: %u != %u\n", buffer[ 0 ], v ); - } else if ( idx >= shape[0] && buffer[ shape[0]-1 ] != v ) { - printf( "unexpected result when linear index exceeds dimensions: %u != %u\n", buffer[ shape[0]-1 ], v ); - } else if ( idx >= 0 && idx < shape[0] && buffer[ idx ] != v ) { - printf( "unexpected result for normal linear index: %u != %u\n", buffer[ idx ], v ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark54( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark55( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 1, 3 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark56( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx)) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark57( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -1, -3 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark58( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, 1 }; - int64_t offset = 4; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark59( void ) { - double elapsed; - int64_t idx; - uint8_t v; - double t; - int8_t s; - int i; - - uint8_t buffer[] = { 1, 2, 3, 4, 5, 6 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 1, -3 }; - int64_t offset = 3; - int64_t nsubmodes = 1; - enum STDLIB_NDARRAY_INDEX_MODE mode = STDLIB_NDARRAY_INDEX_ERROR; - int8_t submodes[] = { mode }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_COLUMN_MAJOR, mode, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - idx = (int64_t)( (rand_double()*6.0)-0.0 ); - v = (uint8_t)( rand_double()*255.0 ); - s = stdlib_ndarray_iset( arr, idx, (void *)&v ); - if ( s != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( s != 0 || *(stdlib_ndarray_iget_ptr( arr, idx )) != v ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark60( void ) { - double elapsed; - int64_t v; - int64_t j; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - j = (int64_t)( rand_double()*ndims ); - v = stdlib_ndarray_dimension( arr, j ); - if ( v != shape[ j ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != shape[ j ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark61( void ) { - double elapsed; - int64_t v; - int64_t j; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - j = (int64_t)( rand_double()*ndims ); - v = stdlib_ndarray_stride( arr, j ); - if ( v != strides[ j ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != strides[ j ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark62( void ) { - enum STDLIB_NDARRAY_INDEX_MODE v; - double elapsed; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_index_mode( arr ); - if ( v != STDLIB_NDARRAY_INDEX_ERROR ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != STDLIB_NDARRAY_INDEX_ERROR ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark63( void ) { - double elapsed; - int8_t *v; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { 2, 1 }; - int64_t offset = 0; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - // NOTE: this is likely to be optimized away by a modern compiler, making this benchmark meaningless. - v = stdlib_ndarray_submodes( arr ); - if ( v[ 0 ] != submodes[ 0 ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v[ 0 ] != submodes[ 0 ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark64( void ) { - enum STDLIB_NDARRAY_INDEX_MODE v; - double elapsed; - int64_t j; - double t; - int i; - - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0 }; - int64_t ndims = 2; - int64_t shape[] = { 3, 2 }; - int64_t strides[] = { -2, -1 }; - int64_t offset = 5; - int64_t nsubmodes = 1; - int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; - - struct ndarray *arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, buffer, ndims, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, nsubmodes, submodes ); - if ( arr == NULL ) { - printf( "unable to allocate memory\n" ); - exit( 1 ); - } - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - j = (int64_t)( rand_double()*ndims ); - v = stdlib_ndarray_submode( arr, j ); - if ( v != submodes[ 0 ] ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - - if ( v != submodes[ 0 ] ) { - printf( "unexpected result\n" ); - } - stdlib_ndarray_free( arr ); - - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::instantiation\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:byteLength\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:data\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:dtype\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:flags\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:length\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:ndims\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:offset\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:order\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:shape\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:strides\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:get:mode=error\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:get:mode=wrap\n", NAME ); - elapsed = benchmark13(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:get:mode=clamp\n", NAME ); - elapsed = benchmark14(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:get:mode=error\n", NAME ); - elapsed = benchmark15(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:get:mode=wrap\n", NAME ); - elapsed = benchmark16(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:get:mode=clamp\n", NAME ); - elapsed = benchmark17(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:get:mode=error\n", NAME ); - elapsed = benchmark18(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:get:mode=wrap\n", NAME ); - elapsed = benchmark19(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:get:mode=clamp\n", NAME ); - elapsed = benchmark20(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:get:mode=error\n", NAME ); - elapsed = benchmark21(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:get:mode=wrap\n", NAME ); - elapsed = benchmark22(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:get:mode=clamp\n", NAME ); - elapsed = benchmark23(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:get:mode=error\n", NAME ); - elapsed = benchmark24(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:get:mode=wrap\n", NAME ); - elapsed = benchmark25(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:get:mode=clamp\n", NAME ); - elapsed = benchmark26(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iget:mode=error\n", NAME ); - elapsed = benchmark27(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iget:mode=wrap\n", NAME ); - elapsed = benchmark28(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iget:mode=clamp\n", NAME ); - elapsed = benchmark29(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_positive_strides:iget:mode=error,order=row-major\n", NAME ); - elapsed = benchmark30(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_positive_strides:iget:mode=error,order=column-major\n", NAME ); - elapsed = benchmark31(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_negative_strides:iget:mode=error,order=row-major\n", NAME ); - elapsed = benchmark32(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_negative_strides:iget:mode=error,order=column-major\n", NAME ); - elapsed = benchmark33(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,mixed_sign_strides:iget:mode=error,order=row-major\n", NAME ); - elapsed = benchmark34(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,mixed_sign_strides:iget:mode=error,order=column-major\n", NAME ); - elapsed = benchmark35(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:set:mode=error\n", NAME ); - elapsed = benchmark36(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:set:mode=wrap\n", NAME ); - elapsed = benchmark37(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:set:mode=clamp\n", NAME ); - elapsed = benchmark38(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:set:mode=error\n", NAME ); - elapsed = benchmark39(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:set:mode=wrap\n", NAME ); - elapsed = benchmark40(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d:set:mode=clamp\n", NAME ); - elapsed = benchmark41(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:set:mode=error\n", NAME ); - elapsed = benchmark42(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:set:mode=wrap\n", NAME ); - elapsed = benchmark43(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::3d:set:mode=clamp\n", NAME ); - elapsed = benchmark44(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:set:mode=error\n", NAME ); - elapsed = benchmark45(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:set:mode=wrap\n", NAME ); - elapsed = benchmark46(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::4d:set:mode=clamp\n", NAME ); - elapsed = benchmark47(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:set:mode=error\n", NAME ); - elapsed = benchmark48(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:set:mode=wrap\n", NAME ); - elapsed = benchmark49(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::5d:set:mode=clamp\n", NAME ); - elapsed = benchmark50(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iset:mode=error\n", NAME ); - elapsed = benchmark51(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iset:mode=wrap\n", NAME ); - elapsed = benchmark52(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::1d:iset:mode=clamp\n", NAME ); - elapsed = benchmark53(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_positive_strides:iset:mode=error,order=row-major\n", NAME ); - elapsed = benchmark54(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_positive_strides:iset:mode=error,order=column-major\n", NAME ); - elapsed = benchmark55(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_negative_strides:iset:mode=error,order=row-major\n", NAME ); - elapsed = benchmark56(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,all_negative_strides:iset:mode=error,order=column-major\n", NAME ); - elapsed = benchmark57(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,mixed_sign_strides:iset:mode=error,order=row-major\n", NAME ); - elapsed = benchmark58(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::2d,mixed_sign_strides:iset:mode=error,order=column-major\n", NAME ); - elapsed = benchmark59(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:dimension\n", NAME ); - elapsed = benchmark60(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:stride\n", NAME ); - elapsed = benchmark61(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:index_mode\n", NAME ); - elapsed = benchmark62(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:submodes\n", NAME ); - elapsed = benchmark63(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s::get:submode\n", NAME ); - elapsed = benchmark64(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index 4ae2dc7..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,342 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import BenchmarkTools -using Printf - -# Benchmark variables: -repeats = 3; -samples = 1e4; -count = 0; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark( setup, expr ) - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Arguments - -* `setup`: setup expression -* `expr`: expression to benchmark - -# Examples - -``` julia -julia> out = benchmark( :(), :( sin( 3.14 ) ) ); -``` -""" -function benchmark( setup, expr ) - t = eval( :( BenchmarkTools.@benchmark $expr samples=$samples setup=($setup) ) ) - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - bench( name, setup, expr ) - -Run a named benchmark. - -# Arguments - -* `name`: benchmark name (suffix) -* `setup`: setup expression -* `expr`: expression to benchmark - -# Examples - -``` julia -julia> bench( "sin", :(), :( sin( 3.14 ) ) ); -``` -""" -function bench( name, setup, expr ) - for i in 1:repeats - @printf( "# julia::%s\n", name ); - global count += 1; - results = benchmark( setup, expr ); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", count ); - end -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - - name = "ndarray::instantiation"; - setup = :(); - stmt = :( A = Array{Float64}( undef, 3, 2 ) ); - bench( name, setup, stmt ); - - name = "ndarray::get::dtype"; - setup = :( A = Array{Float64}( undef, 3, 2 ) ); - stmt = quote - d = eltype( A ); - if d != Float64 - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::get::length"; - setup = :( A = Array{Float64}( undef, 3, 2 ) ); - stmt = quote - N = length( A ); - if N != 6 - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::get::ndims"; - setup = :( A = Array{Float64}( undef, 3, 2 ) ); - stmt = quote - M = ndims( A ); - if M != 2 - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::get::shape"; - setup = :( A = Array{Float64}( undef, 3, 2 ) ); - stmt = quote - shape = size( A ); - if shape[ 1 ] != 3 - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::get::strides"; - setup = :( A = Array{Float64}( undef, 3, 2 ) ); - stmt = quote - s = strides( A ); - if s[ 1 ] != 1 - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::1d:get"; - setup = :( A = rand( Float64, 6 ) ); - stmt = quote - j = Int( floor( rand()*6.0 ) ) + 1; - v = A[ j ]; - if v != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::2d:get"; - setup = :( A = rand( Float64, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = A[ j, 2 ]; - if v != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::3d:get"; - setup = :( A = rand( Float64, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = A[ 1, j, 2 ]; - if v != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::4d:get"; - setup = :( A = rand( Float64, 1, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = A[ 1, 1, j, 2 ]; - if v != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::5d:get"; - setup = :( A = rand( Float64, 1, 1, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = A[ 1, 1, 1, j, 2 ]; - if v != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::1d:set"; - setup = :( A = rand( Float64, 6 ) ); - stmt = quote - j = Int( floor( rand()*6.0 ) ) + 1; - v = rand(); - A[ j ] = v; - if A[ j ] != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::2d:set"; - setup = :( A = rand( Float64, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = rand(); - A[ j, 2 ] = v; - if A[ j, 2 ] != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::3d:set"; - setup = :( A = rand( Float64, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = rand(); - A[ 1, j, 2 ] = v; - if A[ 1, j, 2 ] != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::4d:set"; - setup = :( A = rand( Float64, 1, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = rand(); - A[ 1, 1, j, 2 ] = v; - if A[ 1, 1, j, 2 ] != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - name = "ndarray::5d:set"; - setup = :( A = rand( Float64, 1, 1, 1, 3, 2 ) ); - stmt = quote - j = Int( floor( rand()*3.0 ) ) + 1; - v = rand(); - A[ 1, 1, 1, j, 2 ] = v; - if A[ 1, 1, 1, j, 2 ] != v - throw( error( "unexpected value" ) ); - end - end - bench( name, setup, stmt ); - - print_summary( count, count ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 39b1520..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,290 +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.""" - # pylint: disable=too-many-statements - 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 = "::1d:get" - setup = "import numpy as np; from math import floor; from random import random; shape = [6]; 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()*6.0))]" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::2d: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 = "::3d:get" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 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[0, int(floor(random()*3.0)), 1]" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::4d:get" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 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[0, 0, int(floor(random()*3.0)), 1]" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::5d:get" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 1, 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[0, 0, 0, int(floor(random()*3.0)), 1]" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::1d:set" - setup = "import numpy as np; from math import floor; from random import random; shape = [6]; 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()*6.0))] = random()" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::2d: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 = "::3d:set" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 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[0, int(floor(random()*3.0)), 1] = random()" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::4d:set" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 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[0, 0, int(floor(random()*3.0)), 1] = random()" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::5d:set" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 1, 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[0, 0, 0, int(floor(random()*3.0)), 1] = random()" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::1d:iget" - setup = "import numpy as np; from math import floor; from random import random; shape = [6]; 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()*6.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::2d: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()*6.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::3d:iget" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 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()*6.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::4d:iget" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 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()*6.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::5d:iget" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 1, 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()*6.0)))" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::1d:iset" - setup = "import numpy as np; from math import floor; from random import random; shape = [6]; 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()*6.0)), random())" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::2d: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()*6.0)), random())" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::3d:iset" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 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()*6.0)), random())" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::4d:iset" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 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()*6.0)), random())" - iterations = 1000000 - benchmark(name, setup, stmt, iterations) - - name = "::5d:iset" - setup = "import numpy as np; from math import floor; from random import random; shape = [1, 1, 1, 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()*6.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 26b1a61..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/ctor" -%% click B href "https://github.com/stdlib-js/ndarray-ctor/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-ctor/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-ctor/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-ctor/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-ctor/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor -[production-url]: https://github.com/stdlib-js/ndarray-ctor/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-ctor/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-ctor/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-ctor/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-ctor/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-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 fff993e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,i){return function(){return i||e((i={exports:{}}).exports,i),i.exports}};var p=o(function(Ve,y){"use strict";var Y=require("@stdlib/assert-is-integer").isPrimitive,B=require("@stdlib/ndarray-base-ind"),X=require("@stdlib/ndarray-base-ctor"),G=require("@stdlib/string-format"),w=X.prototype.iget;function H(e){if(this._ndims>0){if(!Y(e))throw new TypeError(G("invalid argument. Index must be an integer. Value: `%s`.",e));return e=B(e,this._length-1,this._mode),w.call(this,e)}return w.call(this)}y.exports=H});var _=o(function(xe,E){"use strict";var J=require("@stdlib/assert-is-integer").isPrimitive,K=require("@stdlib/ndarray-base-ind"),Q=require("@stdlib/ndarray-base-ctor"),U=require("@stdlib/string-format"),q=Q.prototype.iset;function W(e,i){if(this._flags.READONLY)throw new Error("invalid invocation. Cannot write to a read-only array.");if(this._ndims>0){if(!J(e))throw new TypeError(U("invalid argument. Index must be an integer. Value: `%s`.",e));e=K(e,this._length-1,this._mode),q.call(this,e,i)}else q.call(this,e);return this}E.exports=W});var O=o(function(Ne,T){"use strict";var Z=require("@stdlib/assert-is-integer").isPrimitive,$=require("@stdlib/ndarray-base-ind"),I=require("@stdlib/string-format");function ee(){var e,i,t,r;if(arguments.length!==this._ndims)throw new RangeError(I("invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.",this._ndims,arguments.length));for(e=this._offset,t=this._submode.length,r=0;r0))throw new TypeError(n("invalid argument. Third argument must be an array-like object containing nonnegative integers. Value: `%s`.",t));if(s=t.length,s>M)throw new RangeError(n("invalid argument. Number of dimensions must not exceed %u due to stack limits. Value: `%u`.",M,s));if(!de(r))throw new TypeError(n("invalid argument. Fourth argument must be an array-like object containing integers. Value: `%s`.",r));if(s>0){if(r.length!==s)throw new RangeError(n("invalid argument. Fourth argument length must match the number of dimensions. Expected number of dimensions: `%u`. Strides length: `%u`.",s,r.length))}else{if(r.length!==1)throw new RangeError("invalid argument. Fourth argument length must be equal to 1 when creating a zero-dimensional ndarray.");if(r[0]!==0)throw new RangeError(n("invalid argument. Fourth argument must contain a single element equal to 0. Value: `%d`.",r[0]))}if(!ge(m))throw new TypeError(n("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",m));if(!le(d))throw new TypeError(n("invalid argument. Sixth argument must be a supported order. Value: `%s`.",d));if(s>0&&!ve(i.length,t,r,m)&&fe(t)>0)throw new Error("invalid arguments. Input buffer is incompatible with the specified meta data. Ensure that the offset is valid with regard to the strides array and that the buffer has enough elements to satisfy the desired array shape.");if(u={},u.mode=_e,u.readonly=Ie,arguments.length>6&&(h=Ee(u,f),h))throw h;return this._mode=u.mode,u.submode===void 0&&(u.submode=[this._mode]),this._submode=u.submode,c=L(t,s),b=L(r,s||1),z.call(this,e,i,c,b,m,d),this._flags.READONLY=u.readonly,this}be(a,z);l(a,"name","ndarray");l(a.prototype,"get",pe);l(a.prototype,"iget",we);l(a.prototype,"set",qe);l(a.prototype,"iset",ye);S.exports=a});var Te=C();module.exports=Te; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 81910a4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/iget.js", "../lib/iset.js", "../lib/get.js", "../lib/set.js", "../lib/copy_array.js", "../lib/validate.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\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-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar getIndex = require( '@stdlib/ndarray-base-ind' );\nvar parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar base = parent.prototype.iget;\n\n\n// MAIN //\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* @private\n* @param {integer} [idx] - linear view index\n* @throws {TypeError} index must be an integer\n* @throws {RangeError} index exceeds array dimensions\n* @returns {*} array element\n*/\nfunction iget( idx ) {\n\tif ( this._ndims > 0 ) {\n\t\tif ( !isInteger( idx ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Index must be an integer. Value: `%s`.', idx ) );\n\t\t}\n\t\tidx = getIndex( idx, this._length-1, this._mode );\n\t\treturn base.call( this, idx );\n\t}\n\treturn base.call( this );\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/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// METHODS //\n\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar getIndex = require( '@stdlib/ndarray-base-ind' );\nvar parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar base = parent.prototype.iset;\n\n\n// MAIN //\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* @private\n* @param {integer} [idx] - linear view index\n* @param {*} v - value to set\n* @throws {Error} cannot write to a read-only array\n* @throws {TypeError} index must be an integer\n* @throws {RangeError} index exceeds array dimensions\n* @returns {ndarray} ndarray instance\n*/\nfunction iset( idx, v ) {\n\tif ( this._flags.READONLY ) {\n\t\tthrow new Error( 'invalid invocation. Cannot write to a read-only array.' );\n\t}\n\tif ( this._ndims > 0 ) {\n\t\tif ( !isInteger( idx ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Index must be an integer. Value: `%s`.', idx ) );\n\t\t}\n\t\tidx = getIndex( idx, this._length-1, this._mode );\n\t\tbase.call( this, idx, v );\n\t} else {\n\t\tbase.call( this, idx );\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/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar getIndex = require( '@stdlib/ndarray-base-ind' );\nvar format = require( '@stdlib/string-format' );\n\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* @throws {TypeError} provided indices must be integer valued\n* @throws {RangeError} index exceeds array dimensions\n* @throws {RangeError} number of indices must equal the number of dimensions\n* @returns {*} array element\n*/\nfunction get() {\n\tvar idx;\n\tvar ind;\n\tvar M;\n\tvar i;\n\n\tif ( arguments.length !== this._ndims ) {\n\t\tthrow new RangeError( format( 'invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.', this._ndims, arguments.length ) );\n\t}\n\tidx = this._offset;\n\tM = this._submode.length;\n\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Indices must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\tind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len\n\t\tidx += this._strides[ i ] * ind;\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) 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-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar getIndex = require( '@stdlib/ndarray-base-ind' );\nvar format = require( '@stdlib/string-format' );\n\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* @throws {Error} cannot write to a read-only array\n* @throws {TypeError} provided indices must be integer valued\n* @throws {RangeError} index exceeds array dimensions\n* @throws {RangeError} number of indices must equal the number of dimensions\n* @returns {ndarray} ndarray instance\n*/\nfunction set() {\n\tvar idx;\n\tvar ind;\n\tvar M;\n\tvar i;\n\n\tif ( this._flags.READONLY ) {\n\t\tthrow new Error( 'invalid invocation. Cannot write to a read-only array.' );\n\t}\n\tif ( arguments.length !== this._ndims+1 ) {\n\t\tthrow new RangeError( format( 'invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.', this._ndims, arguments.length ) );\n\t}\n\tidx = this._offset;\n\tM = this._submode.length;\n\tfor ( i = 0; i < arguments.length-1; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Indices must be integer valued. Argument: `%i`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\tind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len\n\t\tidx += this._strides[ i ] * ind;\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* Copies the contents of array-like value to a new array.\n*\n* @private\n* @param {ArrayLike} arr - input array\n* @param {NonNegativeInteger} len - array length\n* @returns {Array} output array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0 ];\n*\n* var out = copy( arr, arr.length );\n* // returns [ 1.0, 2.0, 3.0 ]\n*\n* var bool = ( arr === out );\n* // returns false\n*/\nfunction copy( arr, len ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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 isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'clamp',\n* 'submode': [ 'throw', 'wrap', 'clamp' ]\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isIndexMode( opts.mode ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a recognized mode. Option: `%s`.', 'mode', opts.mode ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t\tif ( !isArrayLikeObject( opts.submode ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode ) );\n\t\t}\n\t\tif ( opts.submode.length === 0 ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode.join( ',' ) ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.submode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.submode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( 'invalid option. Each submode must be a recognized mode. Option: `%s`.', opts.submode[ i ] ) );\n\t\t\t}\n\t\t}\n\t\topts.submode = opts.submode.slice();\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t\tif ( !isBoolean( opts.readonly ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', opts.readonly ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isIntegerArray = require( '@stdlib/assert-is-integer-array' ).primitives;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isBufferLengthCompatible = require( '@stdlib/ndarray-base-assert-is-buffer-length-compatible' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare\nvar defaults = require( '@stdlib/ndarray-defaults' );\nvar inherit = require( '@stdlib/utils-inherit' );\nvar format = require( '@stdlib/string-format' );\nvar iget = require( './iget.js' );\nvar iset = require( './iset.js' );\nvar get = require( './get.js' );\nvar set = require( './set.js' );\nvar copy = require( './copy_array.js' );\nvar validate = require( './validate.js' );\n\n\n// VARIABLES //\n\n/*\n* See the following references:\n*\n* - https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept\n* - https://bugs.webkit.org/show_bug.cgi?id=80797\n* - https://github.com/numpy/numpy/issues/5744\n*\n* Note that the maximum number of function arguments can vary from engine to engine. Here, we choose something of a lowest common denominator which may **not** be valid everywhere.\n*/\nvar MAX_DIMS = 32767|0;\n\nvar INDEX_MODE = defaults.get( 'index_mode' );\nvar READONLY = false;\n\n\n// MAIN //\n\n/**\n* ndarray constructor.\n*\n* @constructor\n* @param {string} dtype - data type\n* @param {Collection} 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* @param {Options} [options] - function options\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only\n* @throws {TypeError} `dtype` argument must be a supported ndarray data type\n* @throws {TypeError} `buffer` argument must be an array-like object, typed-array-like, or a Buffer\n* @throws {TypeError} `buffer` argument `get` and `set` properties must be functions\n* @throws {TypeError} `shape` argument must be an array-like object containing nonnegative integers\n* @throws {Error} `shape` argument length must equal the number of dimensions\n* @throws {TypeError} `strides` argument must be an array-like object containing integers\n* @throws {Error} `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`)\n* @throws {Error} for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0`\n* @throws {TypeError} `offset` argument must be a nonnegative integer\n* @throws {TypeError} `order` argument must be a supported ndarray order\n* @throws {Error} `buffer` argument must be compatible with specified meta data\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {RangeError} too many dimensions\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\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, options ) {\n\tvar ndims;\n\tvar opts;\n\tvar err;\n\tvar sh;\n\tvar st;\n\n\tif ( !(this instanceof ndarray) ) {\n\t\tif ( arguments.length < 7 ) {\n\t\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order );\n\t\t}\n\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order, options ); // eslint-disable-line max-len\n\t}\n\tif ( !isDataType( dtype ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a supported ndarray data type. Value: `%s`.', dtype ) );\n\t}\n\tif ( !isCollection( buffer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object, typed-array-like, or a Buffer. Value: `%s`.', buffer ) );\n\t} else if ( buffer.get && buffer.set && ( !isFunction( buffer.get ) || !isFunction( buffer.set ) ) ) { // eslint-disable-line max-len\n\t\tthrow new TypeError( format( 'invalid argument. Second argument `get` and `set` properties must be functions. Value: `%s`.', buffer ) );\n\t}\n\tif ( !isNonNegativeIntegerArray( shape ) ) {\n\t\tif ( !isCollection( shape) || shape.length > 0 ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) );\n\t\t}\n\t}\n\tndims = shape.length;\n\tif ( ndims > MAX_DIMS ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of dimensions must not exceed %u due to stack limits. Value: `%u`.', MAX_DIMS, ndims ) );\n\t}\n\tif ( !isIntegerArray( strides ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be an array-like object containing integers. Value: `%s`.', strides ) );\n\t}\n\tif ( ndims > 0 ) {\n\t\tif ( strides.length !== ndims ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Fourth argument length must match the number of dimensions. Expected number of dimensions: `%u`. Strides length: `%u`.', ndims, strides.length ) );\n\t\t}\n\t} else if ( strides.length !== 1 ) {\n\t\tthrow new RangeError( 'invalid argument. Fourth argument length must be equal to 1 when creating a zero-dimensional ndarray.' );\n\t} else if ( strides[ 0 ] !== 0 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Fourth argument must contain a single element equal to 0. Value: `%d`.', strides[ 0 ] ) );\n\t}\n\tif ( !isNonNegativeInteger( offset ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', offset ) );\n\t}\n\tif ( !isOrder( order ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a supported order. Value: `%s`.', order ) );\n\t}\n\tif ( ndims > 0 && !isBufferLengthCompatible( buffer.length, shape, strides, offset ) && numel( shape ) > 0 ) { // eslint-disable-line max-len\n\t\tthrow new Error( 'invalid arguments. Input buffer is incompatible with the specified meta data. Ensure that the offset is valid with regard to the strides array and that the buffer has enough elements to satisfy the desired array shape.' );\n\t}\n\topts = {};\n\topts.mode = INDEX_MODE;\n\topts.readonly = READONLY;\n\tif ( arguments.length > 6 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tthis._mode = opts.mode;\n\tif ( opts.submode === void 0 ) {\n\t\topts.submode = [ this._mode ];\n\t}\n\tthis._submode = opts.submode;\n\n\t// Copy `shape` and `strides` to prevent external mutation:\n\tsh = copy( shape, ndims );\n\tst = copy( strides, ndims || 1 );\n\n\t// Call the parent constructor:\n\tparent.call( this, dtype, buffer, sh, st, offset, order );\n\tthis._flags.READONLY = opts.readonly;\n\n\treturn this;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n// Inherit from the parent constructor:\ninherit( ndarray, parent );\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* 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', get );\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', iget );\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', set );\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', iset );\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-ctor\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n*\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\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*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EAK1CC,EAAOF,EAAO,UAAU,KAkB5B,SAASG,EAAMC,EAAM,CACpB,GAAK,KAAK,OAAS,EAAI,CACtB,GAAK,CAACN,EAAWM,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,2DAA4DG,CAAI,CAAE,EAEhG,OAAAA,EAAML,EAAUK,EAAK,KAAK,QAAQ,EAAG,KAAK,KAAM,EACzCF,EAAK,KAAM,KAAME,CAAI,CAC7B,CACA,OAAOF,EAAK,KAAM,IAAK,CACxB,CAKAL,EAAO,QAAUM,IChEjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,2BAA4B,EAC9CC,EAAS,QAAS,uBAAwB,EAK1CC,EAAOF,EAAO,UAAU,KAoB5B,SAASG,EAAMC,EAAKC,EAAI,CACvB,GAAK,KAAK,OAAO,SAChB,MAAM,IAAI,MAAO,wDAAyD,EAE3E,GAAK,KAAK,OAAS,EAAI,CACtB,GAAK,CAACP,EAAWM,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,2DAA4DG,CAAI,CAAE,EAEhGA,EAAML,EAAUK,EAAK,KAAK,QAAQ,EAAG,KAAK,KAAM,EAChDF,EAAK,KAAM,KAAME,EAAKC,CAAE,CACzB,MACCH,EAAK,KAAM,KAAME,CAAI,EAEtB,OAAO,IACR,CAKAP,EAAO,QAAUM,ICvEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAmB9C,SAASC,IAAM,CACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,KAAK,OAC9B,MAAM,IAAI,WAAYL,EAAQ,sGAAuG,KAAK,OAAQ,UAAU,MAAO,CAAE,EAItK,IAFAE,EAAM,KAAK,QACXE,EAAI,KAAK,SAAS,OACZC,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAAM,CACxC,GAAK,CAACP,EAAW,UAAWO,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWL,EAAQ,iFAAkFK,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEpIF,EAAMJ,EAAU,UAAWM,CAAE,EAAG,KAAK,OAAQA,CAAE,EAAE,EAAG,KAAK,SAAUA,EAAED,CAAE,CAAE,EACzEF,GAAO,KAAK,SAAUG,CAAE,EAAIF,CAC7B,CACA,OAAK,KAAK,WACF,KAAK,QAAQ,IAAKD,CAAI,EAEvB,KAAK,QAASA,CAAI,CAC1B,CAKAL,EAAO,QAAUI,KCxEjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAW,QAAS,0BAA2B,EAC/CC,EAAS,QAAS,uBAAwB,EAqB9C,SAASC,IAAM,CACd,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,KAAK,OAAO,SAChB,MAAM,IAAI,MAAO,wDAAyD,EAE3E,GAAK,UAAU,SAAW,KAAK,OAAO,EACrC,MAAM,IAAI,WAAYL,EAAQ,sGAAuG,KAAK,OAAQ,UAAU,MAAO,CAAE,EAItK,IAFAE,EAAM,KAAK,QACXE,EAAI,KAAK,SAAS,OACZC,EAAI,EAAGA,EAAI,UAAU,OAAO,EAAGA,IAAM,CAC1C,GAAK,CAACP,GAAW,UAAWO,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWL,EAAQ,iFAAkFK,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEpIF,EAAMJ,GAAU,UAAWM,CAAE,EAAG,KAAK,OAAQA,CAAE,EAAE,EAAG,KAAK,SAAUA,EAAED,CAAE,CAAE,EACzEF,GAAO,KAAK,SAAUG,CAAE,EAAIF,CAC7B,CACA,OAAK,KAAK,WACT,KAAK,QAAQ,IAAK,UAAWE,CAAE,EAAGH,CAAI,EAEtC,KAAK,QAASA,CAAI,EAAI,UAAWG,CAAE,EAE7B,IACR,CAKAR,EAAO,QAAUI,KC/EjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAuCA,SAASC,GAAMC,EAAKC,EAAM,CACzB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAI,KAAMF,EAAKG,CAAE,CAAE,EAEpB,OAAOD,CACR,CAKAJ,EAAO,QAAUC,KCrDjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,GAAoB,QAAS,qCAAsC,EACnEC,EAAc,QAAS,2CAA4C,EACnEC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,uBAAwB,EA2B9C,SAASC,GAAUC,EAAMC,EAAU,CAClC,IAAIC,EACJ,GAAK,CAACT,GAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACL,EAAaI,EAAK,IAAK,GAC5B,OAAO,IAAI,UAAWF,EAAQ,uEAAwE,OAAQE,EAAK,IAAK,CAAE,EAG5H,GAAKN,EAAYO,EAAS,SAAU,EAAI,CAEvC,GADAD,EAAK,QAAUC,EAAQ,QAClB,CAACN,GAAmBK,EAAK,OAAQ,EACrC,OAAO,IAAI,UAAWF,EAAQ,0FAA2F,UAAWE,EAAK,OAAQ,CAAE,EAEpJ,GAAKA,EAAK,QAAQ,SAAW,EAC5B,OAAO,IAAI,UAAWF,EAAQ,0FAA2F,UAAWE,EAAK,QAAQ,KAAM,GAAI,CAAE,CAAE,EAEhK,IAAME,EAAI,EAAGA,EAAIF,EAAK,QAAQ,OAAQE,IACrC,GAAK,CAACN,EAAaI,EAAK,QAASE,CAAE,CAAE,EACpC,OAAO,IAAI,UAAWJ,EAAQ,wEAAyEE,EAAK,QAASE,CAAE,CAAE,CAAE,EAG7HF,EAAK,QAAUA,EAAK,QAAQ,MAAM,CACnC,CACA,OAAKN,EAAYO,EAAS,UAAW,IACpCD,EAAK,SAAWC,EAAQ,SACnB,CAACJ,GAAWG,EAAK,QAAS,GACvB,IAAI,UAAWF,EAAQ,+DAAgE,WAAYE,EAAK,QAAS,CAAE,EAGrH,IACR,CAKAR,EAAO,QAAUO,KC5FjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAe,QAAS,8BAA+B,EACvDC,GAA4B,QAAS,6CAA8C,EAAE,WACrFC,GAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAiB,QAAS,iCAAkC,EAAE,WAC9DC,EAAa,QAAS,4BAA6B,EACnDC,GAAU,QAAS,sCAAuC,EAC1DC,GAAa,QAAS,0CAA2C,EACjEC,GAA2B,QAAS,yDAA0D,EAC9FC,GAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,2BAA4B,EAC9CC,GAAW,QAAS,0BAA2B,EAC/CC,GAAU,QAAS,uBAAwB,EAC3CC,EAAS,QAAS,uBAAwB,EAC1CC,GAAO,IACPC,GAAO,IACPC,GAAM,IACNC,GAAM,IACNC,EAAO,IACPC,GAAW,IAcXC,EAAW,MAEXC,GAAaV,GAAS,IAAK,YAAa,EACxCW,GAAW,GA2Cf,SAASC,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,EAAOC,EAAU,CACzE,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,EAAE,gBAAgBZ,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,CAAM,EAE3D,IAAIN,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,EAAOC,CAAQ,EAE3E,GAAK,CAACvB,GAAYiB,CAAM,EACvB,MAAM,IAAI,UAAWX,EAAQ,uFAAwFW,CAAM,CAAE,EAE9H,GAAMvB,EAAcwB,CAAO,GAEpB,GAAKA,EAAO,KAAOA,EAAO,MAAS,CAACpB,EAAYoB,EAAO,GAAI,GAAK,CAACpB,EAAYoB,EAAO,GAAI,GAC9F,MAAM,IAAI,UAAWZ,EAAQ,+FAAgGY,CAAO,CAAE,MAFtI,OAAM,IAAI,UAAWZ,EAAQ,8GAA+GY,CAAO,CAAE,EAItJ,GAAK,CAACvB,GAA2BwB,CAAM,IACjC,CAACzB,EAAcyB,CAAK,GAAKA,EAAM,OAAS,GAC5C,MAAM,IAAI,UAAWb,EAAQ,8GAA+Ga,CAAM,CAAE,EAItJ,GADAK,EAAQL,EAAM,OACTK,EAAQX,EACZ,MAAM,IAAI,WAAYP,EAAQ,8FAA+FO,EAAUW,CAAM,CAAE,EAEhJ,GAAK,CAAC3B,GAAgBuB,CAAQ,EAC7B,MAAM,IAAI,UAAWd,EAAQ,mGAAoGc,CAAQ,CAAE,EAE5I,GAAKI,EAAQ,GACZ,GAAKJ,EAAQ,SAAWI,EACvB,MAAM,IAAI,WAAYlB,EAAQ,2IAA4IkB,EAAOJ,EAAQ,MAAO,CAAE,MAE7L,IAAKA,EAAQ,SAAW,EAC9B,MAAM,IAAI,WAAY,uGAAwG,EACxH,GAAKA,EAAS,CAAE,IAAM,EAC5B,MAAM,IAAI,WAAYd,EAAQ,2FAA4Fc,EAAS,CAAE,CAAE,CAAE,EAE1I,GAAK,CAACxB,GAAsByB,CAAO,EAClC,MAAM,IAAI,UAAWf,EAAQ,+EAAgFe,CAAO,CAAE,EAEvH,GAAK,CAACtB,GAASuB,CAAM,EACpB,MAAM,IAAI,UAAWhB,EAAQ,2EAA4EgB,CAAM,CAAE,EAElH,GAAKE,EAAQ,GAAK,CAACvB,GAA0BiB,EAAO,OAAQC,EAAOC,EAASC,CAAO,GAAKnB,GAAOiB,CAAM,EAAI,EACxG,MAAM,IAAI,MAAO,4NAA6N,EAK/O,GAHAM,EAAO,CAAC,EACRA,EAAK,KAAOX,GACZW,EAAK,SAAWV,GACX,UAAU,OAAS,IACvBW,EAAMd,GAAUa,EAAMF,CAAQ,EACzBG,GACJ,MAAMA,EAGR,YAAK,MAAQD,EAAK,KACbA,EAAK,UAAY,SACrBA,EAAK,QAAU,CAAE,KAAK,KAAM,GAE7B,KAAK,SAAWA,EAAK,QAGrBE,EAAKhB,EAAMQ,EAAOK,CAAM,EACxBI,EAAKjB,EAAMS,EAASI,GAAS,CAAE,EAG/BrB,EAAO,KAAM,KAAMc,EAAOC,EAAQS,EAAIC,EAAIP,EAAQC,CAAM,EACxD,KAAK,OAAO,SAAWG,EAAK,SAErB,IAGR,CAGApB,GAASW,EAASb,CAAO,EAczBV,EAAauB,EAAS,OAAQ,SAAU,EA0BxCvB,EAAauB,EAAQ,UAAW,MAAOP,EAAI,EA0B3ChB,EAAauB,EAAQ,UAAW,OAAQT,EAAK,EAmC7Cd,EAAauB,EAAQ,UAAW,MAAON,EAAI,EAmC3CjB,EAAauB,EAAQ,UAAW,OAAQR,EAAK,EAK7ChB,EAAO,QAAUwB,IC9RjB,IAAIa,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_iget", "__commonJSMin", "exports", "module", "isInteger", "getIndex", "parent", "format", "base", "iget", "idx", "require_iset", "__commonJSMin", "exports", "module", "isInteger", "getIndex", "parent", "format", "base", "iset", "idx", "v", "require_get", "__commonJSMin", "exports", "module", "isInteger", "getIndex", "format", "get", "idx", "ind", "M", "i", "require_set", "__commonJSMin", "exports", "module", "isInteger", "getIndex", "format", "set", "idx", "ind", "M", "i", "require_copy_array", "__commonJSMin", "exports", "module", "copy", "arr", "len", "out", "i", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArrayLikeObject", "isIndexMode", "isBoolean", "format", "validate", "opts", "options", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isCollection", "isNonNegativeIntegerArray", "isNonNegativeInteger", "isIntegerArray", "isFunction", "isOrder", "isDataType", "isBufferLengthCompatible", "numel", "parent", "defaults", "inherit", "format", "iget", "iset", "get", "set", "copy", "validate", "MAX_DIMS", "INDEX_MODE", "READONLY", "ndarray", "dtype", "buffer", "shape", "strides", "offset", "order", "options", "ndims", "opts", "err", "sh", "st", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 87b9798..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,474 +0,0 @@ - -{{alias}}( dtype, buffer, shape, strides, offset, order[, options] ) - 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). - - options: Object (optional) - Options. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. If equal - to 'throw', an ndarray instance throws an error when an index exceeds - array dimensions. If equal to 'normalize', an ndarray instance - normalizes negative indices and throws an error when an index exceeds - array dimensions. If equal to 'wrap', an ndarray instance wraps around - indices exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to 'throw', an ndarray - instance throws an error when a subscript exceeds array dimensions. If - equal to 'normalize', an ndarray instance normalizes negative - subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', an ndarray instance wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. If the - number of modes is fewer than the number of dimensions, the function - recycles modes using modulo arithmetic. Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - ndarray: ndarray - ndarray instance. - - Examples - -------- - // Create a new instance... - > var b = [ 1.0, 2.0, 3.0, 4.0 ]; // 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.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - -{{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 - 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 5346156..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,203 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import ndarray = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - - let x = ndarray( 'float64', [ 1, 2, 3, 4 ], shape, strides, 0, 'row-major' ); // $ExpectType ndarray - x = new ndarray( 'float64', [ 1, 2, 3, 4 ], shape, strides, 0, 'row-major' ); // $ExpectType ndarray - - const buffer = new Int32Array( [ 1, 2, 3 ] ); - const order = 'column-major'; - - x = ndarray( 'int32', buffer, shape, strides, 0, order ); // $ExpectType ndarray - x = new ndarray( 'int32', buffer, shape, strides, 0, order ); // $ExpectType ndarray - - x = ndarray( 'int32', buffer, shape, strides, 0, order, { 'mode': 'clamp' } ); // $ExpectType ndarray - x = new ndarray( 'int32', buffer, shape, strides, 0, order, { 'mode': 'clamp' } ); // $ExpectType ndarray - - x = ndarray( 'int32', buffer, shape, strides, 0, order, { 'submode': [ 'throw' ] } ); // $ExpectType ndarray - x = new ndarray( 'int32', buffer, shape, strides, 0, order, { 'submode': [ 'throw' ] } ); // $ExpectType ndarray - - if ( x.shape[ 0 ] !== x.shape[ 0 ] ) { - throw new Error( 'unexpected error' ); - } -} - -// 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 a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': 'abc' } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': 123 } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': true } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': false } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': null } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': [] } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': {} } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an ndarray of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': 'abc' } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': 123 } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': true } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': false } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': null } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': {} } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - const shape = [ 2, 2 ]; - const strides = [ 2, 1 ]; - const offset = 0; - const order = 'row-major'; - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': 'abc' } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': 123 } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': [] } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': null } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': {} } ); // $ExpectError - ndarray( 'float64', buffer, shape, strides, offset, order, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided and invalid number of 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 - ndarray( 'uint16', buffer, shape, strides, offset, 'row-major', {}, {} ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 95c1664..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 1f6cc96..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,206 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include "stdlib/ndarray/base/dtype_char.h" -#include -#include -#include -#include - -void print_ndarray_contents( const struct ndarray *x ) { - int64_t i; - double v; - int8_t s; - - for ( i = 0; i < stdlib_ndarray_length( x ); i++ ) { - s = stdlib_ndarray_iget_float64( x, i, &v ); // WARNING: assumes `x->dtype` is float64 - if ( s != 0 ) { - printf( "Unable to resolve data element.\n" ); - exit( 1 ); - } - printf( "data[%"PRId64"] = %f\n", i, v ); - } -} - -int main( void ) { - // Manually create an ndarray (WARNING: this is for illustration purposes only, as the fields of an ndarray are subject to change; for ABI compatibility, use utility functions for accessing ndarray data)... - struct ndarray *x1 = malloc( sizeof( struct ndarray ) ); - if ( x1 == NULL ) { - printf( "Error allocating memory.\n" ); - exit( 1 ); - } - - // Specify the underlying data type: - enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; - x1->dtype = dtype; - - // Create an underlying byte array: - uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - x1->data = buffer; - - // Explicitly specify the number of bytes per element: - x1->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; - - // Specify the array shape: - int64_t shape[] = { 3 }; // vector consisting of 3 doubles - x1->shape = shape; - - // Specify the array strides: - int64_t strides[] = { x1->BYTES_PER_ELEMENT }; - x1->strides = strides; - - // Specify the byte offset: - x1->offset = 0; - - // Specify the array order (note: this does not matter for a 1-dimensional array): - enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; - x1->order = order; - - // Specify the index mode: - enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; - x1->imode = imode; - - // Specify the subscript index modes: - int8_t submodes[] = { imode }; - x1->submodes = submodes; - x1->nsubmodes = 1; - - // Explicitly specify the number of array dimensions: - x1->ndims = 1; // vector - - // Explicitly specify the number of array elements (doubles): - x1->length = x1->shape[ 0 ]; - - // Explicitly specify the number of bytes: - x1->byteLength = (x1->length) * (x1->BYTES_PER_ELEMENT); - - // Explicitly set the array flags: - x1->flags = stdlib_ndarray_flags( x1 ); - - printf( "dtype = %d\n", stdlib_ndarray_dtype( x1 ) ); - printf( "length = %"PRId64"\n", stdlib_ndarray_length( x1 ) ); - printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x1 ) ); - printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x1 ) ) ); - printf( "\n" ); - - // Use the function interface to create an ndarray (NOTE: for future ABI compatibility, using the following function interface should be preferred)... - struct ndarray *x2 = stdlib_ndarray_allocate( dtype, buffer, 1, shape, strides, 0, order, imode, 1, submodes ); - if ( x2 == NULL ) { - printf( "Error allocating memory.\n" ); - exit( 1 ); - } - - printf( "dtype = %d\n", stdlib_ndarray_dtype( x2 ) ); - printf( "length = %"PRId64"\n", stdlib_ndarray_length( x2 ) ); - printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x2 ) ); - printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x2 ) ) ); - printf( "\n" ); - - // Set values in the underlying byte array using pointers: - int64_t sub[] = { 0 }; - uint8_t *ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 1.0; // cppcheck-suppress invalidPointerCast - - sub[ 0 ] = 1; - ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 2.0; // cppcheck-suppress invalidPointerCast - - sub[ 0 ] = 2; - ptr = stdlib_ndarray_get_ptr( x2, sub ); - if ( ptr == NULL ) { - printf( "Unable to resolve data pointer.\n" ); - exit( 1 ); - } - *(double *)ptr = 3.0; // cppcheck-suppress invalidPointerCast - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Set values in the underlying byte array using a "generic" function: - sub[ 0 ] = 0; - double v = 4.0; - int8_t status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 1; - v = 5.0; - status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 2; - v = 6.0; - status = stdlib_ndarray_set( x2, sub, (void *)&v ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Set values in the underlying byte array using a specialized function: - sub[ 0 ] = 0; - status = stdlib_ndarray_set_float64( x2, sub, 7.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 1; - status = stdlib_ndarray_set_float64( x2, sub, 8.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - sub[ 0 ] = 2; - status = stdlib_ndarray_set_float64( x2, sub, 9.0 ); - if ( status != 0 ) { - printf( "Unable to set data element.\n" ); - exit( 1 ); - } - - // Print out the current ndarray elements: - print_ndarray_contents( x2 ); - printf( "\n" ); - - // Free allocated memory: - stdlib_ndarray_free( x1 ); - stdlib_ndarray_free( x2 ); -} 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/include/stdlib/ndarray/ctor.h b/include/stdlib/ndarray/ctor.h deleted file mode 100644 index df8053b..0000000 --- a/include/stdlib/ndarray/ctor.h +++ /dev/null @@ -1,146 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_H -#define STDLIB_NDARRAY_CTOR_H - -#include - -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" - -// The following #includes contain additional APIs which should be exposed along with the prototypes contained in this file... -#include "ctor/get.h" -#include "ctor/get_ptr.h" -#include "ctor/iget.h" -#include "ctor/iget_ptr.h" -#include "ctor/iset.h" -#include "ctor/macros.h" -#include "ctor/ndarray.h" -#include "ctor/set.h" -#include "ctor/set_ptr.h" - -// NOTE: keep declarations in alphabetical order... - -/** -* Returns a pointer to a dynamically allocated ndarray. -*/ -struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int8_t order, int8_t imode, int64_t nsubmodes, int8_t *submodes ); - -/** -* Returns the size of an ndarray (in bytes). -*/ -int64_t stdlib_ndarray_bytelength( const struct ndarray *arr ); - -/** -* Returns a pointer to an ndarray's underlying byte array. -*/ -uint8_t * stdlib_ndarray_data( const struct ndarray *arr ); - -/** -* Returns an ndarray dimension. -*/ -int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i ); - -/** -* Disables specified ndarray flags. -*/ -int8_t stdlib_ndarray_disable_flags( struct ndarray *arr, const int64_t flags ); - -/** -* Returns an ndarray data type. -*/ -int16_t stdlib_ndarray_dtype( const struct ndarray *arr ); - -/** -* Enables specified ndarray flags. -*/ -int8_t stdlib_ndarray_enable_flags( struct ndarray *arr, const int64_t flags ); - -/** -* Returns ndarray flags. -*/ -int64_t stdlib_ndarray_flags( const struct ndarray *arr ); - -/** -* Frees an ndarray's allocated memory. -*/ -void stdlib_ndarray_free( struct ndarray *arr ); - -/** -* Tests whether an ndarray has specified flags enabled. -*/ -int8_t stdlib_ndarray_has_flags( const struct ndarray *arr, const int64_t flags ); - -/** -* Returns the index mode of an ndarray. -*/ -int8_t stdlib_ndarray_index_mode( const struct ndarray *arr ); - -/** -* Returns the number of elements in an ndarray. -*/ -int64_t stdlib_ndarray_length( const struct ndarray *arr ); - -/** -* Returns the number of ndarray dimensions. -*/ -int64_t stdlib_ndarray_ndims( const struct ndarray *arr ); - -/** -* Returns an ndarray index offset (in bytes). -*/ -int64_t stdlib_ndarray_offset( const struct ndarray *arr ); - -/** -* Returns the order of an ndarray. -*/ -int8_t stdlib_ndarray_order( const struct ndarray *arr ); - -/** -* Returns the number of ndarray subscript modes. -*/ -int64_t stdlib_ndarray_nsubmodes( const struct ndarray *arr ); - -/** -* Returns a pointer to an array containing an ndarray shape (dimensions). -*/ -int64_t * stdlib_ndarray_shape( const struct ndarray *arr ); - -/** -* Returns an ndarray stride (in bytes). -*/ -int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i ); - -/** -* Returns a pointer to an array containing ndarray strides (in bytes). -*/ -int64_t * stdlib_ndarray_strides( const struct ndarray *arr ); - -/** -* Returns ndarray subscript modes. -*/ -int8_t * stdlib_ndarray_submodes( const struct ndarray *arr ); - -/** -* Returns an ndarray subscript mode. -*/ -int8_t stdlib_ndarray_submode( const struct ndarray *arr, const int64_t i ); - -#endif // !STDLIB_NDARRAY_CTOR_H diff --git a/include/stdlib/ndarray/ctor/get.h b/include/stdlib/ndarray/ctor/get.h deleted file mode 100644 index c900457..0000000 --- a/include/stdlib/ndarray/ctor/get.h +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_GET_H -#define STDLIB_NDARRAY_CTOR_GET_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Returns an ndarray data element. -*/ -int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out ); - -/** -* Returns a double-precision floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_get_float64( const struct ndarray *arr, const int64_t *sub, double *out ); - -/** -* Returns a single-precision floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_get_float32( const struct ndarray *arr, const int64_t *sub, float *out ); - -/** -* Returns an unsigned 64-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_uint64( const struct ndarray *arr, const int64_t *sub, uint64_t *out ); - -/** -* Returns a signed 64-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_int64( const struct ndarray *arr, const int64_t *sub, int64_t *out ); - -/** -* Returns an unsigned 32-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_uint32( const struct ndarray *arr, const int64_t *sub, uint32_t *out ); - -/** -* Returns a signed 32-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_int32( const struct ndarray *arr, const int64_t *sub, int32_t *out ); - -/** -* Returns an unsigned 16-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_uint16( const struct ndarray *arr, const int64_t *sub, uint16_t *out ); - -/** -* Returns a signed 16-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_int16( const struct ndarray *arr, const int64_t *sub, int16_t *out ); - -/** -* Returns an unsigned 8-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_uint8( const struct ndarray *arr, const int64_t *sub, uint8_t *out ); - -/** -* Returns a signed 8-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_get_int8( const struct ndarray *arr, const int64_t *sub, int8_t *out ); - -/** -* Returns a double-precision complex floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_get_complex128( const struct ndarray *arr, const int64_t *sub, stdlib_complex128_t *out ); - -/** -* Returns a single-precision complex floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_get_complex64( const struct ndarray *arr, const int64_t *sub, stdlib_complex64_t *out ); - -/** -* Returns a boolean ndarray data element. -*/ -int8_t stdlib_ndarray_get_bool( const struct ndarray *arr, const int64_t *sub, bool *out ); - -#endif // !STDLIB_NDARRAY_CTOR_GET_H diff --git a/include/stdlib/ndarray/ctor/get_ptr.h b/include/stdlib/ndarray/ctor/get_ptr.h deleted file mode 100644 index d0093ca..0000000 --- a/include/stdlib/ndarray/ctor/get_ptr.h +++ /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. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_GET_PTR_H -#define STDLIB_NDARRAY_CTOR_GET_PTR_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Returns a pointer to an ndarray data element in the underlying byte array. -*/ -uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub ); - -/** -* Returns an ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out ); - -/** -* Returns a double-precision floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_float64( const uint8_t *idx, double *out ); - -/** -* Returns a single-precision floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_float32( const uint8_t *idx, float *out ); - -/** -* Returns an unsigned 64-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_uint64( const uint8_t *idx, uint64_t *out ); - -/** -* Returns a signed 64-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_int64( const uint8_t *idx, int64_t *out ); - -/** -* Returns an unsigned 32-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_uint32( const uint8_t *idx, uint32_t *out ); - -/** -* Returns a signed 32-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_int32( const uint8_t *idx, int32_t *out ); - -/** -* Returns an unsigned 16-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_uint16( const uint8_t *idx, uint16_t *out ); - -/** -* Returns a signed 16-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_int16( const uint8_t *idx, int16_t *out ); - -/** -* Returns an unsigned 8-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_uint8( const uint8_t *idx, uint8_t *out ); - -/** -* Returns a signed 8-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_int8( const uint8_t *idx, int8_t *out ); - -/** -* Returns a double-precision complex floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_complex128( const uint8_t *idx, stdlib_complex128_t *out ); - -/** -* Returns a single-precision complex floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_complex64( const uint8_t *idx, stdlib_complex64_t *out ); - -/** -* Returns a boolean ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_get_ptr_bool( const uint8_t *idx, bool *out ); - -#endif // !STDLIB_NDARRAY_CTOR_GET_PTR_H diff --git a/include/stdlib/ndarray/ctor/iget.h b/include/stdlib/ndarray/ctor/iget.h deleted file mode 100644 index 074e575..0000000 --- a/include/stdlib/ndarray/ctor/iget.h +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_IGET_H -#define STDLIB_NDARRAY_CTOR_IGET_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Returns an ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget( const struct ndarray *arr, const int64_t idx, void *out ); - -/** -* Returns a double-precision floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_float64( const struct ndarray *arr, const int64_t idx, double *out ); - -/** -* Returns a single-precision floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_float32( const struct ndarray *arr, const int64_t idx, float *out ); - -/** -* Returns an unsigned 64-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_uint64( const struct ndarray *arr, const int64_t idx, uint64_t *out ); - -/** -* Returns a signed 64-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_int64( const struct ndarray *arr, const int64_t idx, int64_t *out ); - -/** -* Returns an unsigned 32-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_uint32( const struct ndarray *arr, const int64_t idx, uint32_t *out ); - -/** -* Returns a signed 32-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_int32( const struct ndarray *arr, const int64_t idx, int32_t *out ); - -/** -* Returns an unsigned 16-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_uint16( const struct ndarray *arr, const int64_t idx, uint16_t *out ); - -/** -* Returns a signed 16-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_int16( const struct ndarray *arr, const int64_t idx, int16_t *out ); - -/** -* Returns an unsigned 8-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_uint8( const struct ndarray *arr, const int64_t idx, uint8_t *out ); - -/** -* Returns a signed 8-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_int8( const struct ndarray *arr, const int64_t idx, int8_t *out ); - -/** -* Returns a double-precision complex floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_complex128( const struct ndarray *arr, const int64_t idx, stdlib_complex128_t *out ); - -/** -* Returns a single-precision complex floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_complex64( const struct ndarray *arr, const int64_t idx, stdlib_complex64_t *out ); - -/** -* Returns a boolean ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iget_bool( const struct ndarray *arr, const int64_t idx, bool *out ); - -#endif // !STDLIB_NDARRAY_CTOR_IGET_H diff --git a/include/stdlib/ndarray/ctor/iget_ptr.h b/include/stdlib/ndarray/ctor/iget_ptr.h deleted file mode 100644 index f09aef2..0000000 --- a/include/stdlib/ndarray/ctor/iget_ptr.h +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_IGET_PTR_H -#define STDLIB_NDARRAY_CTOR_IGET_PTR_H - -#include "ndarray.h" -#include - -/** -* Returns a pointer in the underlying byte array for an ndarray data element located at a specified linear index. -*/ -uint8_t * stdlib_ndarray_iget_ptr( const struct ndarray *arr, const int64_t idx ); - -#endif // !STDLIB_NDARRAY_CTOR_IGET_PTR_H diff --git a/include/stdlib/ndarray/ctor/iset.h b/include/stdlib/ndarray/ctor/iset.h deleted file mode 100644 index 01e3199..0000000 --- a/include/stdlib/ndarray/ctor/iset.h +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_ISET_H -#define STDLIB_NDARRAY_CTOR_ISET_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Sets an ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset( const struct ndarray *arr, const int64_t idx, const void *v ); - -/** -* Sets a double-precision floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_float64( const struct ndarray *arr, const int64_t idx, const double v ); - -/** -* Sets a single-precision floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_float32( const struct ndarray *arr, const int64_t idx, const float v ); - -/** -* Sets an unsigned 64-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_uint64( const struct ndarray *arr, const int64_t idx, const uint64_t v ); - -/** -* Sets a signed 64-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_int64( const struct ndarray *arr, const int64_t idx, const int64_t v ); - -/** -* Sets an unsigned 32-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_uint32( const struct ndarray *arr, const int64_t idx, const uint32_t v ); - -/** -* Sets a signed 32-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_int32( const struct ndarray *arr, const int64_t idx, const int32_t v ); - -/** -* Sets an unsigned 16-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_uint16( const struct ndarray *arr, const int64_t idx, const uint16_t v ); - -/** -* Sets a signed 16-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_int16( const struct ndarray *arr, const int64_t idx, const int16_t v ); - -/** -* Sets an unsigned 8-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_uint8( const struct ndarray *arr, const int64_t idx, const uint8_t v ); - -/** -* Sets a signed 8-bit integer ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_int8( const struct ndarray *arr, const int64_t idx, const int8_t v ); - -/** -* Sets a double-precision complex floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_complex128( const struct ndarray *arr, const int64_t idx, const stdlib_complex128_t v ); - -/** -* Sets a single-precision complex floating-point ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_complex64( const struct ndarray *arr, const int64_t idx, const stdlib_complex64_t v ); - -/** -* Sets a boolean ndarray data element located at a specified linear index. -*/ -int8_t stdlib_ndarray_iset_bool( const struct ndarray *arr, const int64_t idx, const bool v ); - -#endif // !STDLIB_NDARRAY_CTOR_ISET_H diff --git a/include/stdlib/ndarray/ctor/macros.h b/include/stdlib/ndarray/ctor/macros.h deleted file mode 100644 index 8443b43..0000000 --- a/include/stdlib/ndarray/ctor/macros.h +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_MACROS_H -#define STDLIB_NDARRAY_CTOR_MACROS_H - -/** -* Flag indicating whether an ndarray is row-major (C-style) contiguous. -* -* ## Notes -* -* - Row-major order indicates that the last ndarray index varies the fastest. -* - Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory. -* - `strides` array is in reverse order to that of column-major order. -* - An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional). -*/ -#define STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG 0x0000000000000001 - -/** -* Flag indicating whether an ndarray is column-major (Fortran-style) contiguous. -* -* ## Notes -* -* - Column-major order indicates that the first ndarray index varies the fastest. -* - Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory. -* - `strides` array is in reverse order to that of row-major order. -* - An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional). -*/ -#define STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG 0x0000000000000002 - -#endif // !STDLIB_NDARRAY_CTOR_MACROS_H diff --git a/include/stdlib/ndarray/ctor/ndarray.h b/include/stdlib/ndarray/ctor/ndarray.h deleted file mode 100644 index 7e8f0bb..0000000 --- a/include/stdlib/ndarray/ctor/ndarray.h +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_NDARRAY_H -#define STDLIB_NDARRAY_CTOR_NDARRAY_H - -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include - -/** -* ndarray structure. -* -* @example -* #include "stdlib/ndarray/ctor.h" -* #include "stdlib/ndarray/dtypes.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bytes_per_element.h" -* #include -* #include -* #include -* -* struct ndarray *x = malloc( sizeof( struct ndarray ) ); -* if ( x == NULL ) { -* fprintf( stderr, "Error allocating memory.\n" ); -* exit( 1 ); -* } -* -* // Create an underlying byte array: -* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -* x->data = buffer; -* -* // Specify the underlying data type: -* x->dtype = STDLIB_NDARRAY_FLOAT64; -* -* // Explicitly specify the number of bytes per element: -* x->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; -* -* // Specify the array shape: -* int64_t shape[] = { 3 }; // vector consisting of 3 doubles -* x->shape = shape; -* -* // Specify the array strides: -* int64_t strides[] = { x->BYTES_PER_ELEMENT }; -* x->strides = strides; -* -* // Specify the byte offset: -* x->offset = 0; -* -* // Specify the array order (note: this does not matter for a 1-dimensional array): -* x->order = STDLIB_NDARRAY_ROW_MAJOR; -* -* // Specify the index mode: -* x->imode = STDLIB_NDARRAY_INDEX_ERROR; -* -* // Specify subscript index modes: -* x->submodes = { STDLIB_NDARRAY_INDEX_ERROR }; -* x->nsubmodes = 1; -* -* // Explicitly specify the number of array dimensions: -* x->ndims = 1; // vector -* -* // Explicitly specify the number of array elements (doubles): -* x->length = x->shape[ 0 ]; -* -* // Explicitly specify the number of bytes: -* x->byteLength = (x->length) * (x->BYTES_PER_ELEMENT); -* -* // Explicitly set the array flags: -* x->flags = stdlib_ndarray_flags( x ); -* -* // Free allocated memory: -* stdlib_ndarray_free( x ); -*/ -struct ndarray { - // Underlying data type: - int16_t dtype; - - // Pointer to the underlying byte array: - uint8_t *data; - - // Number of array dimensions: - int64_t ndims; - - // Array shape (dimensions): - int64_t *shape; - - // Array strides (in bytes) specifying how to iterate over a strided array: - int64_t *strides; - - // Byte offset which specifies the location at which to start iterating over array elements: - int64_t offset; - - // Array order (either row-major (C-style) or column-major (Fortran-style)): - int8_t order; - - // Mode specifying how to handle indices which exceed array dimensions: - int8_t imode; - - // Number of subscript modes: - int64_t nsubmodes; - - // Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis: - int8_t *submodes; - - // Number of array elements: - int64_t length; - - // Size in bytes: - int64_t byteLength; - - // Number of bytes per element (i.e., item size): - int64_t BYTES_PER_ELEMENT; - - // Bit mask providing information regarding the memory layout of the array (e.g., see macros): - int64_t flags; -}; - -#endif // !STDLIB_NDARRAY_CTOR_NDARRAY_H diff --git a/include/stdlib/ndarray/ctor/set.h b/include/stdlib/ndarray/ctor/set.h deleted file mode 100644 index c9130d2..0000000 --- a/include/stdlib/ndarray/ctor/set.h +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_SET_H -#define STDLIB_NDARRAY_CTOR_SET_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Sets an ndarray data element. -*/ -int8_t stdlib_ndarray_set( const struct ndarray *arr, const int64_t *sub, const void *v ); - -/** -* Sets a double-precision floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_set_float64( const struct ndarray *arr, const int64_t *sub, const double v ); - -/** -* Sets a single-precision floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_set_float32( const struct ndarray *arr, const int64_t *sub, const float v ); - -/** -* Sets an unsigned 64-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_uint64( const struct ndarray *arr, const int64_t *sub, const uint64_t v ); - -/** -* Sets a signed 64-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_int64( const struct ndarray *arr, const int64_t *sub, const int64_t v ); - -/** -* Sets an unsigned 32-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_uint32( const struct ndarray *arr, const int64_t *sub, const uint32_t v ); - -/** -* Sets a signed 32-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_int32( const struct ndarray *arr, const int64_t *sub, const int32_t v ); - -/** -* Sets an unsigned 16-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_uint16( const struct ndarray *arr, const int64_t *sub, const uint16_t v ); - -/** -* Sets a signed 16-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_int16( const struct ndarray *arr, const int64_t *sub, const int16_t v ); - -/** -* Sets an unsigned 8-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_uint8( const struct ndarray *arr, const int64_t *sub, const uint8_t v ); - -/** -* Sets a signed 8-bit integer ndarray data element. -*/ -int8_t stdlib_ndarray_set_int8( const struct ndarray *arr, const int64_t *sub, const int8_t v ); - -/** -* Sets a double-precision complex floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_set_complex128( const struct ndarray *arr, const int64_t *sub, const stdlib_complex128_t v ); - -/** -* Sets a single-precision complex floating-point ndarray data element. -*/ -int8_t stdlib_ndarray_set_complex64( const struct ndarray *arr, const int64_t *sub, const stdlib_complex64_t v ); - -/** -* Sets a boolean ndarray data element. -*/ -int8_t stdlib_ndarray_set_bool( const struct ndarray *arr, const int64_t *sub, const bool v ); - -#endif // !STDLIB_NDARRAY_CTOR_SET_H diff --git a/include/stdlib/ndarray/ctor/set_ptr.h b/include/stdlib/ndarray/ctor/set_ptr.h deleted file mode 100644 index acefb98..0000000 --- a/include/stdlib/ndarray/ctor/set_ptr.h +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_CTOR_SET_PTR_H -#define STDLIB_NDARRAY_CTOR_SET_PTR_H - -#include "ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Sets an ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_value( const struct ndarray *arr, uint8_t *idx, const void *v ); - -/** -* Sets a double-precision floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_float64( uint8_t *idx, const double v ); - -/** -* Sets a single-precision floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_float32( uint8_t *idx, const float v ); - -/** -* Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_uint64( uint8_t *idx, const uint64_t v ); - -/** -* Sets a signed 64-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_int64( uint8_t *idx, const int64_t v ); - -/** -* Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_uint32( uint8_t *idx, const uint32_t v ); - -/** -* Sets a signed 32-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_int32( uint8_t *idx, const int32_t v ); - -/** -* Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_uint16( uint8_t *idx, const uint16_t v ); - -/** -* Sets a signed 16-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_int16( uint8_t *idx, const int16_t v ); - -/** -* Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_uint8( uint8_t *idx, const uint8_t v ); - -/** -* Sets a signed 8-bit integer ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_int8( uint8_t *idx, const int8_t v ); - -/** -* Sets a double-precision complex floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_complex128( uint8_t *idx, const stdlib_complex128_t v ); - -/** -* Sets a single-precision complex floating-point ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_complex64( uint8_t *idx, const stdlib_complex64_t v ); - -/** -* Sets a boolean ndarray data element specified by a byte array pointer. -*/ -int8_t stdlib_ndarray_set_ptr_bool( uint8_t *idx, const bool v ); - -#endif // !STDLIB_NDARRAY_CTOR_SET_PTR_H diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 3318045..83641a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, ArrayLike } from '@stdlib/types/array'; import { ndarray, DataType, Mode, Order, Shape, Strides } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4d250e3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import{primitives as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import{primitives as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-buffer-length-compatible@v0.1.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-inherit@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import{isPrimitive as f}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ind@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.2-esm/index.mjs";import{isPrimitive as c}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";var y=p.prototype.iget;var _=p.prototype.iset;function E(e,r){var s,t;for(s=[],t=0;t0))throw new TypeError(j("0jp5S",a));if((R=a.length)>32767)throw new RangeError(j("0jp5T",32767,R));if(!i(f))throw new TypeError(j("0jp5U",f));if(R>0){if(f.length!==R)throw new RangeError(j("0jp5V",R,f.length))}else{if(1!==f.length)throw new RangeError(j("0jp0f"));if(0!==f[0])throw new RangeError(j("0jpDt",f[0]))}if(!t(g))throw new TypeError(j("0jp5X",g));if(!o(y))throw new TypeError(j("0jp5Y",y));if(R>0&&!m(l.length,a,f,g)&&h(a)>0)throw new Error(j("0jpCz"));if((D={}).mode=x,D.readonly=false,arguments.length>6&&(O=function(e,r){var s;if(!b(r))return new TypeError(j("0jp2V",r));if(u(r,"mode")&&(e.mode=r.mode,!w(e.mode)))return new TypeError(j("0jp5a","mode",e.mode));if(u(r,"submode")){if(e.submode=r.submode,!v(e.submode))return new TypeError(j("0jp5b","submode",e.submode));if(0===e.submode.length)return new TypeError(j("0jp5b","submode",e.submode.join(",")));for(s=0;s0){if(!f(e))throw new TypeError(j("0jp5O",e));return e=g(e,this._length-1,this._mode),y.call(this,e)}return y.call(this)})),e(T.prototype,"set",(function(){var e,r,s,t;if(this._flags.READONLY)throw new Error(j("0jp0e"));if(arguments.length!==this._ndims+1)throw new RangeError(j("0jp5M",this._ndims,arguments.length));for(e=this._offset,s=this._submode.length,t=0;t0){if(!f(e))throw new TypeError(j("0jp5O",e));e=g(e,this._length-1,this._mode),_.call(this,e,r)}else _.call(this,e);return this}));export{T as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a4bfb40 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/iget.js","../lib/iset.js","../lib/copy_array.js","../lib/main.js","../lib/validate.js","../lib/get.js","../lib/set.js"],"sourcesContent":["/**\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-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport getIndex from '@stdlib/ndarray-base-ind';\nimport parent from '@stdlib/ndarray-base-ctor'; // eslint-disable-line stdlib/no-redeclare\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar base = parent.prototype.iget;\n\n\n// MAIN //\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* @private\n* @param {integer} [idx] - linear view index\n* @throws {TypeError} index must be an integer\n* @throws {RangeError} index exceeds array dimensions\n* @returns {*} array element\n*/\nfunction iget( idx ) {\n\tif ( this._ndims > 0 ) {\n\t\tif ( !isInteger( idx ) ) {\n\t\t\tthrow new TypeError( format( '0jp5O', idx ) );\n\t\t}\n\t\tidx = getIndex( idx, this._length-1, this._mode );\n\t\treturn base.call( this, idx );\n\t}\n\treturn base.call( this );\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/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// METHODS //\n\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport getIndex from '@stdlib/ndarray-base-ind';\nimport parent from '@stdlib/ndarray-base-ctor'; // eslint-disable-line stdlib/no-redeclare\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// VARIABLES //\n\nvar base = parent.prototype.iset;\n\n\n// MAIN //\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* @private\n* @param {integer} [idx] - linear view index\n* @param {*} v - value to set\n* @throws {Error} cannot write to a read-only array\n* @throws {TypeError} index must be an integer\n* @throws {RangeError} index exceeds array dimensions\n* @returns {ndarray} ndarray instance\n*/\nfunction iset( idx, v ) {\n\tif ( this._flags.READONLY ) {\n\t\tthrow new Error( format('0jp0e') );\n\t}\n\tif ( this._ndims > 0 ) {\n\t\tif ( !isInteger( idx ) ) {\n\t\t\tthrow new TypeError( format( '0jp5O', idx ) );\n\t\t}\n\t\tidx = getIndex( idx, this._length-1, this._mode );\n\t\tbase.call( this, idx, v );\n\t} else {\n\t\tbase.call( this, idx );\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// MAIN //\n\n/**\n* Copies the contents of array-like value to a new array.\n*\n* @private\n* @param {ArrayLike} arr - input array\n* @param {NonNegativeInteger} len - array length\n* @returns {Array} output array\n*\n* @example\n* var arr = [ 1.0, 2.0, 3.0 ];\n*\n* var out = copy( arr, arr.length );\n* // returns [ 1.0, 2.0, 3.0 ]\n*\n* var bool = ( arr === out );\n* // returns false\n*/\nfunction copy( arr, len ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default copy;\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-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isCollection from '@stdlib/assert-is-collection';\nimport { primitives as isNonNegativeIntegerArray } from '@stdlib/assert-is-nonnegative-integer-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport { primitives as isIntegerArray } from '@stdlib/assert-is-integer-array';\nimport isFunction from '@stdlib/assert-is-function';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isBufferLengthCompatible from '@stdlib/ndarray-base-assert-is-buffer-length-compatible';\nimport numel from '@stdlib/ndarray-base-numel';\nimport parent from '@stdlib/ndarray-base-ctor'; // eslint-disable-line stdlib/no-redeclare\nimport defaults from '@stdlib/ndarray-defaults';\nimport inherit from '@stdlib/utils-inherit';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport iget from './iget.js';\nimport iset from './iset.js';\nimport get from './get.js';\nimport set from './set.js';\nimport copy from './copy_array.js';\nimport validate from './validate.js';\n\n\n// VARIABLES //\n\n/*\n* See the following references:\n*\n* - https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept\n* - https://bugs.webkit.org/show_bug.cgi?id=80797\n* - https://github.com/numpy/numpy/issues/5744\n*\n* Note that the maximum number of function arguments can vary from engine to engine. Here, we choose something of a lowest common denominator which may **not** be valid everywhere.\n*/\nvar MAX_DIMS = 32767|0;\n\nvar INDEX_MODE = defaults.get( 'index_mode' );\nvar READONLY = false;\n\n\n// MAIN //\n\n/**\n* ndarray constructor.\n*\n* @constructor\n* @param {string} dtype - data type\n* @param {Collection} 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* @param {Options} [options] - function options\n* @param {string} [options.mode=\"throw\"] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode=[\"throw\"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis\n* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only\n* @throws {TypeError} `dtype` argument must be a supported ndarray data type\n* @throws {TypeError} `buffer` argument must be an array-like object, typed-array-like, or a Buffer\n* @throws {TypeError} `buffer` argument `get` and `set` properties must be functions\n* @throws {TypeError} `shape` argument must be an array-like object containing nonnegative integers\n* @throws {Error} `shape` argument length must equal the number of dimensions\n* @throws {TypeError} `strides` argument must be an array-like object containing integers\n* @throws {Error} `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`)\n* @throws {Error} for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0`\n* @throws {TypeError} `offset` argument must be a nonnegative integer\n* @throws {TypeError} `order` argument must be a supported ndarray order\n* @throws {Error} `buffer` argument must be compatible with specified meta data\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {RangeError} too many dimensions\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\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, options ) {\n\tvar ndims;\n\tvar opts;\n\tvar err;\n\tvar sh;\n\tvar st;\n\n\tif ( !(this instanceof ndarray) ) {\n\t\tif ( arguments.length < 7 ) {\n\t\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order );\n\t\t}\n\t\treturn new ndarray( dtype, buffer, shape, strides, offset, order, options ); // eslint-disable-line max-len\n\t}\n\tif ( !isDataType( dtype ) ) {\n\t\tthrow new TypeError( format( '0jp5P', dtype ) );\n\t}\n\tif ( !isCollection( buffer ) ) {\n\t\tthrow new TypeError( format( '0jp5Q', buffer ) );\n\t} else if ( buffer.get && buffer.set && ( !isFunction( buffer.get ) || !isFunction( buffer.set ) ) ) { // eslint-disable-line max-len\n\t\tthrow new TypeError( format( '0jp5R', buffer ) );\n\t}\n\tif ( !isNonNegativeIntegerArray( shape ) ) {\n\t\tif ( !isCollection( shape) || shape.length > 0 ) {\n\t\t\tthrow new TypeError( format( '0jp5S', shape ) );\n\t\t}\n\t}\n\tndims = shape.length;\n\tif ( ndims > MAX_DIMS ) {\n\t\tthrow new RangeError( format( '0jp5T', MAX_DIMS, ndims ) );\n\t}\n\tif ( !isIntegerArray( strides ) ) {\n\t\tthrow new TypeError( format( '0jp5U', strides ) );\n\t}\n\tif ( ndims > 0 ) {\n\t\tif ( strides.length !== ndims ) {\n\t\t\tthrow new RangeError( format( '0jp5V', ndims, strides.length ) );\n\t\t}\n\t} else if ( strides.length !== 1 ) {\n\t\tthrow new RangeError( format('0jp0f') );\n\t} else if ( strides[ 0 ] !== 0 ) {\n\t\tthrow new RangeError( format( '0jpDt', strides[ 0 ] ) );\n\t}\n\tif ( !isNonNegativeInteger( offset ) ) {\n\t\tthrow new TypeError( format( '0jp5X', offset ) );\n\t}\n\tif ( !isOrder( order ) ) {\n\t\tthrow new TypeError( format( '0jp5Y', order ) );\n\t}\n\tif ( ndims > 0 && !isBufferLengthCompatible( buffer.length, shape, strides, offset ) && numel( shape ) > 0 ) { // eslint-disable-line max-len\n\t\tthrow new Error( format('0jpCz') );\n\t}\n\topts = {};\n\topts.mode = INDEX_MODE;\n\topts.readonly = READONLY;\n\tif ( arguments.length > 6 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tthis._mode = opts.mode;\n\tif ( opts.submode === void 0 ) {\n\t\topts.submode = [ this._mode ];\n\t}\n\tthis._submode = opts.submode;\n\n\t// Copy `shape` and `strides` to prevent external mutation:\n\tsh = copy( shape, ndims );\n\tst = copy( strides, ndims || 1 );\n\n\t// Call the parent constructor:\n\tparent.call( this, dtype, buffer, sh, st, offset, order );\n\tthis._flags.READONLY = opts.readonly;\n\n\treturn this;\n\n\t/* eslint-enable no-invalid-this */\n}\n\n// Inherit from the parent constructor:\ninherit( ndarray, parent );\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* 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', get );\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', iget );\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', set );\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', iset );\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 isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions\n* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions\n* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'clamp',\n* 'submode': [ 'throw', 'wrap', 'clamp' ]\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0jp2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isIndexMode( opts.mode ) ) {\n\t\t\treturn new TypeError( format( '0jp5a', 'mode', opts.mode ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\topts.submode = options.submode;\n\t\tif ( !isArrayLikeObject( opts.submode ) ) {\n\t\t\treturn new TypeError( format( '0jp5b', 'submode', opts.submode ) );\n\t\t}\n\t\tif ( opts.submode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0jp5b', 'submode', opts.submode.join( ',' ) ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.submode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.submode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0jp5c', opts.submode[ i ] ) );\n\t\t\t}\n\t\t}\n\t\topts.submode = opts.submode.slice();\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\topts.readonly = options.readonly;\n\t\tif ( !isBoolean( opts.readonly ) ) {\n\t\t\treturn new TypeError( format( '0jp2o', 'readonly', opts.readonly ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport getIndex from '@stdlib/ndarray-base-ind';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\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* @throws {TypeError} provided indices must be integer valued\n* @throws {RangeError} index exceeds array dimensions\n* @throws {RangeError} number of indices must equal the number of dimensions\n* @returns {*} array element\n*/\nfunction get() {\n\tvar idx;\n\tvar ind;\n\tvar M;\n\tvar i;\n\n\tif ( arguments.length !== this._ndims ) {\n\t\tthrow new RangeError( format( '0jp5M', this._ndims, arguments.length ) );\n\t}\n\tidx = this._offset;\n\tM = this._submode.length;\n\tfor ( i = 0; i < arguments.length; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0jp5N', i, arguments[ i ] ) );\n\t\t}\n\t\tind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len\n\t\tidx += this._strides[ i ] * ind;\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/* eslint-disable no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport getIndex from '@stdlib/ndarray-base-ind';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\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* @throws {Error} cannot write to a read-only array\n* @throws {TypeError} provided indices must be integer valued\n* @throws {RangeError} index exceeds array dimensions\n* @throws {RangeError} number of indices must equal the number of dimensions\n* @returns {ndarray} ndarray instance\n*/\nfunction set() {\n\tvar idx;\n\tvar ind;\n\tvar M;\n\tvar i;\n\n\tif ( this._flags.READONLY ) {\n\t\tthrow new Error( format('0jp0e') );\n\t}\n\tif ( arguments.length !== this._ndims+1 ) {\n\t\tthrow new RangeError( format( '0jp5M', this._ndims, arguments.length ) );\n\t}\n\tidx = this._offset;\n\tM = this._submode.length;\n\tfor ( i = 0; i < arguments.length-1; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0jpDu', i, arguments[ i ] ) );\n\t\t}\n\t\tind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len\n\t\tidx += this._strides[ i ] * ind;\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"],"names":["base","parent","prototype","iget","iset","copy","arr","len","out","i","push","INDEX_MODE","defaults","get","ndarray","dtype","buffer","shape","strides","offset","order","options","ndims","opts","err","sh","st","this","arguments","length","isDataType","TypeError","format","isCollection","set","isFunction","isNonNegativeIntegerArray","RangeError","isIntegerArray","isNonNegativeInteger","isOrder","isBufferLengthCompatible","numel","Error","mode","readonly","isObject","hasOwnProp","isIndexMode","submode","isArrayLikeObject","join","slice","isBoolean","validate","_mode","_submode","call","_flags","READONLY","inherit","setReadOnly","idx","ind","M","_ndims","_offset","isInteger","getIndex","_shape","_strides","_accessors","_buffer","_length","v"],"mappings":";;snEAgCA,IAAIA,EAAOC,EAAOC,UAAUC,KCA5B,IAAIH,EAAOC,EAAOC,UAAUE,KCO5B,SAASC,EAAMC,EAAKC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAMJ,EAAKG,IAEhB,OAAOD,CACR,CCSA,IAEIG,EAAaC,EAASC,IAAK,cA4C/B,SAASC,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,EAAOC,GAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,KAAOC,gBAAgBb,GACtB,OAAKc,UAAUC,OAAS,EAChB,IAAIf,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,GAErD,IAAIN,EAASC,EAAOC,EAAQC,EAAOC,EAASC,EAAQC,EAAOC,GAEnE,IAAMS,EAAYf,GACjB,MAAM,IAAIgB,UAAWC,EAAQ,QAASjB,IAEvC,IAAMkB,EAAcjB,GACnB,MAAM,IAAIe,UAAWC,EAAQ,QAAShB,IAChC,GAAKA,EAAOH,KAAOG,EAAOkB,OAAUC,EAAYnB,EAAOH,OAAUsB,EAAYnB,EAAOkB,MAC1F,MAAM,IAAIH,UAAWC,EAAQ,QAAShB,IAEvC,IAAMoB,EAA2BnB,MAC1BgB,EAAchB,IAAUA,EAAMY,OAAS,GAC5C,MAAM,IAAIE,UAAWC,EAAQ,QAASf,IAIxC,IADAK,EAAQL,EAAMY,QAxEA,MA0Eb,MAAM,IAAIQ,WAAYL,EAAQ,QA1EjB,MA0EoCV,IAElD,IAAMgB,EAAgBpB,GACrB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKI,EAAQ,GACZ,GAAKJ,EAAQW,SAAWP,EACvB,MAAM,IAAIe,WAAYL,EAAQ,QAASV,EAAOJ,EAAQW,aAEjD,IAAwB,IAAnBX,EAAQW,OACnB,MAAM,IAAIQ,WAAYL,EAAO,UACvB,GAAsB,IAAjBd,EAAS,GACpB,MAAM,IAAImB,WAAYL,EAAQ,QAASd,EAAS,IAChD,CACD,IAAMqB,EAAsBpB,GAC3B,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAEvC,IAAMqB,EAASpB,GACd,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,GAAKE,EAAQ,IAAMmB,EAA0BzB,EAAOa,OAAQZ,EAAOC,EAASC,IAAYuB,EAAOzB,GAAU,EACxG,MAAM,IAAI0B,MAAOX,EAAO,UAKzB,IAHAT,EAAO,CAAA,GACFqB,KAAOjC,EACZY,EAAKsB,SAhGS,MAiGTjB,UAAUC,OAAS,IACvBL,ECxGF,SAAmBD,EAAMF,GACxB,IAAIZ,EACJ,IAAMqC,EAAUzB,GACf,OAAO,IAAIU,UAAWC,EAAQ,QAASX,IAExC,GAAK0B,EAAY1B,EAAS,UACzBE,EAAKqB,KAAOvB,EAAQuB,MACdI,EAAazB,EAAKqB,OACvB,OAAO,IAAIb,UAAWC,EAAQ,QAAS,OAAQT,EAAKqB,OAGtD,GAAKG,EAAY1B,EAAS,WAAc,CAEvC,GADAE,EAAK0B,QAAU5B,EAAQ4B,SACjBC,EAAmB3B,EAAK0B,SAC7B,OAAO,IAAIlB,UAAWC,EAAQ,QAAS,UAAWT,EAAK0B,UAExD,GAA6B,IAAxB1B,EAAK0B,QAAQpB,OACjB,OAAO,IAAIE,UAAWC,EAAQ,QAAS,UAAWT,EAAK0B,QAAQE,KAAM,OAEtE,IAAM1C,EAAI,EAAGA,EAAIc,EAAK0B,QAAQpB,OAAQpB,IACrC,IAAMuC,EAAazB,EAAK0B,QAASxC,IAChC,OAAO,IAAIsB,UAAWC,EAAQ,QAAST,EAAK0B,QAASxC,KAGvDc,EAAK0B,QAAU1B,EAAK0B,QAAQG,OAC5B,CACD,OAAKL,EAAY1B,EAAS,cACzBE,EAAKsB,SAAWxB,EAAQwB,UAClBQ,EAAW9B,EAAKsB,WACd,IAAId,UAAWC,EAAQ,QAAS,WAAYT,EAAKsB,WAGnD,IACR,CDuEQS,CAAU/B,EAAMF,GACjBG,GACJ,MAAMA,EAiBR,OAdAG,KAAK4B,MAAQhC,EAAKqB,UACI,IAAjBrB,EAAK0B,UACT1B,EAAK0B,QAAU,CAAEtB,KAAK4B,QAEvB5B,KAAK6B,SAAWjC,EAAK0B,QAGrBxB,EAAKpB,EAAMY,EAAOK,GAClBI,EAAKrB,EAAMa,EAASI,GAAS,GAG7BrB,EAAOwD,KAAM9B,KAAMZ,EAAOC,EAAQS,EAAIC,EAAIP,EAAQC,GAClDO,KAAK+B,OAAOC,SAAWpC,EAAKsB,SAErBlB,IAGR,CAGAiC,EAAS9C,EAASb,GAclB4D,EAAa/C,EAAS,OAAQ,WA0B9B+C,EAAa/C,EAAQZ,UAAW,OElLhC,WACC,IAAI4D,EACAC,EACAC,EACAvD,EAEJ,GAAKmB,UAAUC,SAAWF,KAAKsC,OAC9B,MAAM,IAAI5B,WAAYL,EAAQ,QAASL,KAAKsC,OAAQrC,UAAUC,SAI/D,IAFAiC,EAAMnC,KAAKuC,QACXF,EAAIrC,KAAK6B,SAAS3B,OACZpB,EAAI,EAAGA,EAAImB,UAAUC,OAAQpB,IAAM,CACxC,IAAM0D,EAAWvC,UAAWnB,IAC3B,MAAM,IAAIsB,UAAWC,EAAQ,QAASvB,EAAGmB,UAAWnB,KAErDsD,EAAMK,EAAUxC,UAAWnB,GAAKkB,KAAK0C,OAAQ5D,GAAI,EAAGkB,KAAK6B,SAAU/C,EAAEuD,IACrEF,GAAOnC,KAAK2C,SAAU7D,GAAMsD,CAC5B,CACD,OAAKpC,KAAK4C,WACF5C,KAAK6C,QAAQ3D,IAAKiD,GAEnBnC,KAAK6C,QAASV,EACtB,IFsLAD,EAAa/C,EAAQZ,UAAW,QHvMhC,SAAe4D,GACd,GAAKnC,KAAKsC,OAAS,EAAI,CACtB,IAAME,EAAWL,GAChB,MAAM,IAAI/B,UAAWC,EAAQ,QAAS8B,IAGvC,OADAA,EAAMM,EAAUN,EAAKnC,KAAK8C,QAAQ,EAAG9C,KAAK4B,OACnCvD,EAAKyD,KAAM9B,KAAMmC,EACxB,CACD,OAAO9D,EAAKyD,KAAM9B,KACnB,IGiOAkC,EAAa/C,EAAQZ,UAAW,OG7OhC,WACC,IAAI4D,EACAC,EACAC,EACAvD,EAEJ,GAAKkB,KAAK+B,OAAOC,SAChB,MAAM,IAAIhB,MAAOX,EAAO,UAEzB,GAAKJ,UAAUC,SAAWF,KAAKsC,OAAO,EACrC,MAAM,IAAI5B,WAAYL,EAAQ,QAASL,KAAKsC,OAAQrC,UAAUC,SAI/D,IAFAiC,EAAMnC,KAAKuC,QACXF,EAAIrC,KAAK6B,SAAS3B,OACZpB,EAAI,EAAGA,EAAImB,UAAUC,OAAO,EAAGpB,IAAM,CAC1C,IAAM0D,EAAWvC,UAAWnB,IAC3B,MAAM,IAAIsB,UAAWC,EAAQ,QAASvB,EAAGmB,UAAWnB,KAErDsD,EAAMK,EAAUxC,UAAWnB,GAAKkB,KAAK0C,OAAQ5D,GAAI,EAAGkB,KAAK6B,SAAU/C,EAAEuD,IACrEF,GAAOnC,KAAK2C,SAAU7D,GAAMsD,CAC5B,CAMD,OALKpC,KAAK4C,WACT5C,KAAK6C,QAAQtC,IAAKN,UAAWnB,GAAKqD,GAElCnC,KAAK6C,QAASV,GAAQlC,UAAWnB,GAE3BkB,IACR,IHqPAkC,EAAa/C,EAAQZ,UAAW,QF3QhC,SAAe4D,EAAKY,GACnB,GAAK/C,KAAK+B,OAAOC,SAChB,MAAM,IAAIhB,MAAOX,EAAO,UAEzB,GAAKL,KAAKsC,OAAS,EAAI,CACtB,IAAME,EAAWL,GAChB,MAAM,IAAI/B,UAAWC,EAAQ,QAAS8B,IAEvCA,EAAMM,EAAUN,EAAKnC,KAAK8C,QAAQ,EAAG9C,KAAK4B,OAC1CvD,EAAKyD,KAAM9B,KAAMmC,EAAKY,EACxB,MACE1E,EAAKyD,KAAM9B,KAAMmC,GAElB,OAAOnC,IACR"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 2b7c36d..0000000 --- a/lib/copy_array.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'; - -// MAIN // - -/** -* Copies the contents of array-like value to a new array. -* -* @private -* @param {ArrayLike} arr - input array -* @param {NonNegativeInteger} len - array length -* @returns {Array} output array -* -* @example -* var arr = [ 1.0, 2.0, 3.0 ]; -* -* var out = copy( arr, arr.length ); -* // returns [ 1.0, 2.0, 3.0 ] -* -* var bool = ( arr === out ); -* // returns false -*/ -function copy( arr, len ) { - var out; - var i; - - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copy; diff --git a/lib/get.js b/lib/get.js deleted file mode 100644 index aa0b526..0000000 --- a/lib/get.js +++ /dev/null @@ -1,73 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-invalid-this */ - -'use strict'; - -// MODULES // - -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var getIndex = require( '@stdlib/ndarray-base-ind' ); -var format = require( '@stdlib/string-format' ); - - -// 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 -* @throws {TypeError} provided indices must be integer valued -* @throws {RangeError} index exceeds array dimensions -* @throws {RangeError} number of indices must equal the number of dimensions -* @returns {*} array element -*/ -function get() { - var idx; - var ind; - var M; - var i; - - if ( arguments.length !== this._ndims ) { - throw new RangeError( format( 'invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.', this._ndims, arguments.length ) ); - } - idx = this._offset; - M = this._submode.length; - for ( i = 0; i < arguments.length; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Indices must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - ind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len - idx += this._strides[ i ] * ind; - } - 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 58487d2..0000000 --- a/lib/iget.js +++ /dev/null @@ -1,65 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-invalid-this */ - -'use strict'; - -// MODULES // - -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var getIndex = require( '@stdlib/ndarray-base-ind' ); -var parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare -var format = require( '@stdlib/string-format' ); - - -// VARIABLES // - -var base = parent.prototype.iget; - - -// MAIN // - -/** -* 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. -* -* @private -* @param {integer} [idx] - linear view index -* @throws {TypeError} index must be an integer -* @throws {RangeError} index exceeds array dimensions -* @returns {*} array element -*/ -function iget( idx ) { - if ( this._ndims > 0 ) { - if ( !isInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Index must be an integer. Value: `%s`.', idx ) ); - } - idx = getIndex( idx, this._length-1, this._mode ); - return base.call( this, idx ); - } - return base.call( this ); -} - - -// EXPORTS // - -module.exports = iget; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 194ceb8..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-ctor -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var out = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/iset.js b/lib/iset.js deleted file mode 100644 index d1df9cf..0000000 --- a/lib/iset.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-invalid-this */ - -'use strict'; - -// METHODS // - -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var getIndex = require( '@stdlib/ndarray-base-ind' ); -var parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare -var format = require( '@stdlib/string-format' ); - - -// VARIABLES // - -var base = parent.prototype.iset; - - -// MAIN // - -/** -* 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. -* -* @private -* @param {integer} [idx] - linear view index -* @param {*} v - value to set -* @throws {Error} cannot write to a read-only array -* @throws {TypeError} index must be an integer -* @throws {RangeError} index exceeds array dimensions -* @returns {ndarray} ndarray instance -*/ -function iset( idx, v ) { - if ( this._flags.READONLY ) { - throw new Error( 'invalid invocation. Cannot write to a read-only array.' ); - } - if ( this._ndims > 0 ) { - if ( !isInteger( idx ) ) { - throw new TypeError( format( 'invalid argument. Index must be an integer. Value: `%s`.', idx ) ); - } - idx = getIndex( idx, this._length-1, this._mode ); - base.call( this, idx, v ); - } else { - base.call( this, idx ); - } - return this; -} - - -// EXPORTS // - -module.exports = iset; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 9f1aa64..0000000 --- a/lib/main.js +++ /dev/null @@ -1,325 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isIntegerArray = require( '@stdlib/assert-is-integer-array' ).primitives; -var isFunction = require( '@stdlib/assert-is-function' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isBufferLengthCompatible = require( '@stdlib/ndarray-base-assert-is-buffer-length-compatible' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var parent = require( '@stdlib/ndarray-base-ctor' ); // eslint-disable-line stdlib/no-redeclare -var defaults = require( '@stdlib/ndarray-defaults' ); -var inherit = require( '@stdlib/utils-inherit' ); -var format = require( '@stdlib/string-format' ); -var iget = require( './iget.js' ); -var iset = require( './iset.js' ); -var get = require( './get.js' ); -var set = require( './set.js' ); -var copy = require( './copy_array.js' ); -var validate = require( './validate.js' ); - - -// VARIABLES // - -/* -* See the following references: -* -* - https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept -* - https://bugs.webkit.org/show_bug.cgi?id=80797 -* - https://github.com/numpy/numpy/issues/5744 -* -* Note that the maximum number of function arguments can vary from engine to engine. Here, we choose something of a lowest common denominator which may **not** be valid everywhere. -*/ -var MAX_DIMS = 32767|0; - -var INDEX_MODE = defaults.get( 'index_mode' ); -var READONLY = false; - - -// MAIN // - -/** -* ndarray constructor. -* -* @constructor -* @param {string} dtype - data type -* @param {Collection} 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) -* @param {Options} [options] - function options -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only -* @throws {TypeError} `dtype` argument must be a supported ndarray data type -* @throws {TypeError} `buffer` argument must be an array-like object, typed-array-like, or a Buffer -* @throws {TypeError} `buffer` argument `get` and `set` properties must be functions -* @throws {TypeError} `shape` argument must be an array-like object containing nonnegative integers -* @throws {Error} `shape` argument length must equal the number of dimensions -* @throws {TypeError} `strides` argument must be an array-like object containing integers -* @throws {Error} `strides` argument length must equal the number of dimensions (except for zero-dimensional arrays; in which case, the `strides` argument length must be equal to `1`) -* @throws {Error} for zero-dimensional ndarrays, the `strides` argument must contain a single element equal to `0` -* @throws {TypeError} `offset` argument must be a nonnegative integer -* @throws {TypeError} `order` argument must be a supported ndarray order -* @throws {Error} `buffer` argument must be compatible with specified meta data -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} too many dimensions -* @returns {ndarray} ndarray instance -* -* @example -* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* 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, options ) { - var ndims; - var opts; - var err; - var sh; - var st; - - if ( !(this instanceof ndarray) ) { - if ( arguments.length < 7 ) { - return new ndarray( dtype, buffer, shape, strides, offset, order ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, options ); // eslint-disable-line max-len - } - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a supported ndarray data type. Value: `%s`.', dtype ) ); - } - if ( !isCollection( buffer ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object, typed-array-like, or a Buffer. Value: `%s`.', buffer ) ); - } else if ( buffer.get && buffer.set && ( !isFunction( buffer.get ) || !isFunction( buffer.set ) ) ) { // eslint-disable-line max-len - throw new TypeError( format( 'invalid argument. Second argument `get` and `set` properties must be functions. Value: `%s`.', buffer ) ); - } - if ( !isNonNegativeIntegerArray( shape ) ) { - if ( !isCollection( shape) || shape.length > 0 ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); - } - } - ndims = shape.length; - if ( ndims > MAX_DIMS ) { - throw new RangeError( format( 'invalid argument. Number of dimensions must not exceed %u due to stack limits. Value: `%u`.', MAX_DIMS, ndims ) ); - } - if ( !isIntegerArray( strides ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an array-like object containing integers. Value: `%s`.', strides ) ); - } - if ( ndims > 0 ) { - if ( strides.length !== ndims ) { - throw new RangeError( format( 'invalid argument. Fourth argument length must match the number of dimensions. Expected number of dimensions: `%u`. Strides length: `%u`.', ndims, strides.length ) ); - } - } else if ( strides.length !== 1 ) { - throw new RangeError( 'invalid argument. Fourth argument length must be equal to 1 when creating a zero-dimensional ndarray.' ); - } else if ( strides[ 0 ] !== 0 ) { - throw new RangeError( format( 'invalid argument. Fourth argument must contain a single element equal to 0. Value: `%d`.', strides[ 0 ] ) ); - } - if ( !isNonNegativeInteger( offset ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', offset ) ); - } - if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a supported order. Value: `%s`.', order ) ); - } - if ( ndims > 0 && !isBufferLengthCompatible( buffer.length, shape, strides, offset ) && numel( shape ) > 0 ) { // eslint-disable-line max-len - throw new Error( 'invalid arguments. Input buffer is incompatible with the specified meta data. Ensure that the offset is valid with regard to the strides array and that the buffer has enough elements to satisfy the desired array shape.' ); - } - opts = {}; - opts.mode = INDEX_MODE; - opts.readonly = READONLY; - if ( arguments.length > 6 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - this._mode = opts.mode; - if ( opts.submode === void 0 ) { - opts.submode = [ this._mode ]; - } - this._submode = opts.submode; - - // Copy `shape` and `strides` to prevent external mutation: - sh = copy( shape, ndims ); - st = copy( strides, ndims || 1 ); - - // Call the parent constructor: - parent.call( this, dtype, buffer, sh, st, offset, order ); - this._flags.READONLY = opts.readonly; - - return this; - - /* eslint-enable no-invalid-this */ -} - -// Inherit from the parent constructor: -inherit( ndarray, parent ); - -/** -* Constructor name. -* -* @name name -* @memberof ndarray -* @type {string} -* @default 'ndarray' -* -* @example -* var str = ndarray.name; -* // returns 'ndarray' -*/ -setReadOnly( ndarray, 'name', 'ndarray' ); - -/** -* 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', get ); - -/** -* 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', iget ); - -/** -* 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', set ); - -/** -* 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', iset ); - - -// EXPORTS // - -module.exports = ndarray; diff --git a/lib/set.js b/lib/set.js deleted file mode 100644 index e15e187..0000000 --- a/lib/set.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-invalid-this */ - -'use strict'; - -// MODULES // - -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var getIndex = require( '@stdlib/ndarray-base-ind' ); -var format = require( '@stdlib/string-format' ); - - -// 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 -* @throws {Error} cannot write to a read-only array -* @throws {TypeError} provided indices must be integer valued -* @throws {RangeError} index exceeds array dimensions -* @throws {RangeError} number of indices must equal the number of dimensions -* @returns {ndarray} ndarray instance -*/ -function set() { - var idx; - var ind; - var M; - var i; - - if ( this._flags.READONLY ) { - throw new Error( 'invalid invocation. Cannot write to a read-only array.' ); - } - if ( arguments.length !== this._ndims+1 ) { - throw new RangeError( format( 'invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.', this._ndims, arguments.length ) ); - } - idx = this._offset; - M = this._submode.length; - for ( i = 0; i < arguments.length-1; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Indices must be integer valued. Argument: `%i`. Value: `%s`.', i, arguments[ i ] ) ); - } - ind = getIndex( arguments[ i ], this._shape[ i ]-1, this._submode[ i%M ] ); // eslint-disable-line max-len - idx += this._strides[ i ] * ind; - } - 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/validate.js b/lib/validate.js deleted file mode 100644 index 5927ec4..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions -* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'clamp', -* 'submode': [ 'throw', 'wrap', 'clamp' ] -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isIndexMode( opts.mode ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a recognized mode. Option: `%s`.', 'mode', opts.mode ) ); - } - } - if ( hasOwnProp( options, 'submode' ) ) { - opts.submode = options.submode; - if ( !isArrayLikeObject( opts.submode ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode ) ); - } - if ( opts.submode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode.join( ',' ) ) ); - } - for ( i = 0; i < opts.submode.length; i++ ) { - if ( !isIndexMode( opts.submode[ i ] ) ) { - return new TypeError( format( 'invalid option. Each submode must be a recognized mode. Option: `%s`.', opts.submode[ i ] ) ); - } - } - opts.submode = opts.submode.slice(); - } - if ( hasOwnProp( options, 'readonly' ) ) { - opts.readonly = options.readonly; - if ( !isBoolean( opts.readonly ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', opts.readonly ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 3268cb7..0000000 --- a/manifest.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/get.c", - "./src/get_ptr.c", - "./src/iget.c", - "./src/iget_ptr.c", - "./src/iset.c", - "./src/main.c", - "./src/set.c", - "./src/set_ptr.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/complex-float32-ctor", - "@stdlib/complex-float64-ctor", - "@stdlib/ndarray-base-bytes-per-element", - "@stdlib/ndarray-base-dtype-char", - "@stdlib/ndarray-base-ind", - "@stdlib/ndarray-base-iteration-order", - "@stdlib/ndarray-base-minmax-view-buffer-index", - "@stdlib/ndarray-base-numel", - "@stdlib/ndarray-base-strides2order", - "@stdlib/ndarray-dtypes", - "@stdlib/ndarray-index-modes", - "@stdlib/ndarray-orders" - ] - } - ] -} diff --git a/package.json b/package.json index 4407706..adc8237 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,8 @@ "version": "0.2.2", "description": "Multidimensional array constructor.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "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", @@ -38,73 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-integer-array": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/ndarray-base-assert-is-buffer-length-compatible": "^0.1.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-bytes-per-element": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-dtype-char": "^0.2.2", - "@stdlib/ndarray-base-ind": "^0.2.2", - "@stdlib/ndarray-base-iteration-order": "^0.2.2", - "@stdlib/ndarray-base-minmax-view-buffer-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/ndarray-orders": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-inherit": "^0.2.2", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@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-property": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -125,7 +33,6 @@ "ctor", "numpy.ndarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/get.c b/src/get.c deleted file mode 100644 index f40084c..0000000 --- a/src/get.c +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/get.h" -#include "stdlib/ndarray/ctor/get_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include -#include - -/** -* Returns an ndarray data element. -* -* ## Notes -* -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_value( arr, idx, out ); -} - -/** -* Returns a double-precision floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_float64( const struct ndarray *arr, const int64_t *sub, double *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_float64( idx, out ); -} - -/** -* Returns a single-precision floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_float32( const struct ndarray *arr, const int64_t *sub, float *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_float32( idx, out ); -} - -/** -* Returns an unsigned 64-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_uint64( const struct ndarray *arr, const int64_t *sub, uint64_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint64( idx, out ); -} - -/** -* Returns a signed 64-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_int64( const struct ndarray *arr, const int64_t *sub, int64_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int64( idx, out ); -} - -/** -* Returns an unsigned 32-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_uint32( const struct ndarray *arr, const int64_t *sub, uint32_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint32( idx, out ); -} - -/** -* Returns a signed 32-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_int32( const struct ndarray *arr, const int64_t *sub, int32_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int32( idx, out ); -} - -/** -* Returns an unsigned 16-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_uint16( const struct ndarray *arr, const int64_t *sub, uint16_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint16( idx, out ); -} - -/** -* Returns a signed 16-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_int16( const struct ndarray *arr, const int64_t *sub, int16_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int16( idx, out ); -} - -/** -* Returns an unsigned 8-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_uint8( const struct ndarray *arr, const int64_t *sub, uint8_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint8( idx, out ); -} - -/** -* Returns a signed 8-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_int8( const struct ndarray *arr, const int64_t *sub, int8_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int8( idx, out ); -} - -/** -* Returns a double-precision complex floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_complex128( const struct ndarray *arr, const int64_t *sub, stdlib_complex128_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_complex128( idx, out ); -} - -/** -* Returns a single-precision complex floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_complex64( const struct ndarray *arr, const int64_t *sub, stdlib_complex64_t *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_complex64( idx, out ); -} - -/** -* Returns a boolean ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_bool( const struct ndarray *arr, const int64_t *sub, bool *out ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_bool( idx, out ); -} diff --git a/src/get_ptr.c b/src/get_ptr.c deleted file mode 100644 index ea52e4d..0000000 --- a/src/get_ptr.c +++ /dev/null @@ -1,344 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/get_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/base/ind.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include -#include - -/** -* Returns a pointer to an ndarray data element in the underlying byte array. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @return underlying byte array pointer -*/ -uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub ) { - int8_t *submodes; - int64_t *strides; - int64_t *shape; - int64_t ndims; - uint8_t *idx; - int64_t ind; - int64_t M; - int64_t i; - - ndims = arr->ndims; - shape = arr->shape; - strides = arr->strides; - submodes = arr->submodes; - M = arr->nsubmodes; - - idx = (arr->data) + (arr->offset); // pointer arithmetic - for ( i = 0; i < ndims; i++ ) { - ind = stdlib_ndarray_ind( sub[ i ], shape[ i ]-1, submodes[ i%M ] ); - if ( ind < 0 ) { - return NULL; - } - idx += strides[ i ] * ind; // pointer arithmetic - } - return idx; -} - -/** -* Returns an ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function does **not** perform bounds checking and **assumes** you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. -* -* @param arr input ndarray -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out ) { - switch ( arr->dtype ) { - case STDLIB_NDARRAY_FLOAT64: - *(double *)out = *(double *)idx; - return 0; - case STDLIB_NDARRAY_FLOAT32: - *(float *)out = *(float *)idx; - return 0; - case STDLIB_NDARRAY_UINT64: - *(uint64_t *)out = *(uint64_t *)idx; - return 0; - case STDLIB_NDARRAY_INT64: - *(int64_t *)out = *(int64_t *)idx; - return 0; - case STDLIB_NDARRAY_UINT32: - *(uint32_t *)out = *(uint32_t *)idx; - return 0; - case STDLIB_NDARRAY_INT32: - *(int32_t *)out = *(int32_t *)idx; - return 0; - case STDLIB_NDARRAY_UINT16: - *(uint16_t *)out = *(uint16_t *)idx; - return 0; - case STDLIB_NDARRAY_INT16: - *(int16_t *)out = *(int16_t *)idx; - return 0; - case STDLIB_NDARRAY_UINT8: - *(uint8_t *)out = *(uint8_t *)idx; - return 0; - case STDLIB_NDARRAY_UINT8C: - *(uint8_t *)out = *(uint8_t *)idx; - return 0; - case STDLIB_NDARRAY_INT8: - *(int8_t *)out = *(int8_t *)idx; - return 0; - case STDLIB_NDARRAY_COMPLEX128: - *(stdlib_complex128_t *)out = *(stdlib_complex128_t *)idx; - return 0; - case STDLIB_NDARRAY_COMPLEX64: - *(stdlib_complex64_t *)out = *(stdlib_complex64_t *)idx; - return 0; - case STDLIB_NDARRAY_BOOL: - *(bool *)out = *(bool *)idx; - return 0; - default: - return -1; - } -} - -/** -* Returns a double-precision floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_float64( const uint8_t *idx, double *out ) { - *out = *(double *)idx; - return 0; -} - -/** -* Returns a single-precision floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_float32( const uint8_t *idx, float *out ) { - *out = *(float *)idx; - return 0; -} - -/** -* Returns an unsigned 64-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_uint64( const uint8_t *idx, uint64_t *out ) { - *out = *(uint64_t *)idx; - return 0; -} - -/** -* Returns a signed 64-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_int64( const uint8_t *idx, int64_t *out ) { - *out = *(int64_t *)idx; - return 0; -} - -/** -* Returns an unsigned 32-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_uint32( const uint8_t *idx, uint32_t *out ) { - *out = *(uint32_t *)idx; - return 0; -} - -/** -* Returns a signed 32-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_int32( const uint8_t *idx, int32_t *out ) { - *out = *(int32_t *)idx; - return 0; -} - -/** -* Returns an unsigned 16-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_uint16( const uint8_t *idx, uint16_t *out ) { - *out = *(uint16_t *)idx; - return 0; -} - -/** -* Returns a signed 16-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_int16( const uint8_t *idx, int16_t *out ) { - *out = *(int16_t *)idx; - return 0; -} - -/** -* Returns an unsigned 8-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_uint8( const uint8_t *idx, uint8_t *out ) { - *out = *(uint8_t *)idx; - return 0; -} - -/** -* Returns a signed 8-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_int8( const uint8_t *idx, int8_t *out ) { - *out = *(int8_t *)idx; - return 0; -} - -/** -* Returns a double-precision complex floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_complex128( const uint8_t *idx, stdlib_complex128_t *out ) { - *out = *(stdlib_complex128_t *)idx; - return 0; -} - -/** -* Returns a single-precision complex floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_complex64( const uint8_t *idx, stdlib_complex64_t *out ) { - *out = *(stdlib_complex64_t *)idx; - return 0; -} - -/** -* Returns a boolean ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_get_ptr_bool( const uint8_t *idx, bool *out ) { - *out = *(bool *)idx; - return 0; -} diff --git a/src/iget.c b/src/iget.c deleted file mode 100644 index 4ce3811..0000000 --- a/src/iget.c +++ /dev/null @@ -1,336 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/iget.h" -#include "stdlib/ndarray/ctor/iget_ptr.h" -#include "stdlib/ndarray/ctor/get_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include -#include - -/** -* Returns an ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types. -* - The function places the burden on the user to ensure that the output address is compatible with the data type of input ndarray data elements. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget( const struct ndarray *arr, const int64_t idx, void *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_value( arr, ptr, out ); -} - -/** -* Returns a double-precision floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_float64( const struct ndarray *arr, const int64_t idx, double *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_float64( ptr, out ); -} - -/** -* Returns a single-precision floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_float32( const struct ndarray *arr, const int64_t idx, float *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_float32( ptr, out ); -} - -/** -* Returns an unsigned 64-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_uint64( const struct ndarray *arr, const int64_t idx, uint64_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint64( ptr, out ); -} - -/** -* Returns a signed 64-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_int64( const struct ndarray *arr, const int64_t idx, int64_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int64( ptr, out ); -} - -/** -* Returns an unsigned 32-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_uint32( const struct ndarray *arr, const int64_t idx, uint32_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint32( ptr, out ); -} - -/** -* Returns a signed 32-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_int32( const struct ndarray *arr, const int64_t idx, int32_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int32( ptr, out ); -} - -/** -* Returns an unsigned 16-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_uint16( const struct ndarray *arr, const int64_t idx, uint16_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint16( ptr, out ); -} - -/** -* Returns a signed 16-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_int16( const struct ndarray *arr, const int64_t idx, int16_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int16( ptr, out ); -} - -/** -* Returns an unsigned 8-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_uint8( const struct ndarray *arr, const int64_t idx, uint8_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_uint8( ptr, out ); -} - -/** -* Returns a signed 8-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_int8( const struct ndarray *arr, const int64_t idx, int8_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_int8( ptr, out ); -} - -/** -* Returns a double-precision complex floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_complex128( const struct ndarray *arr, const int64_t idx, stdlib_complex128_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_complex128( ptr, out ); -} - -/** -* Returns a single-precision complex floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_complex64( const struct ndarray *arr, const int64_t idx, stdlib_complex64_t *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_complex64( ptr, out ); -} - -/** -* Returns a boolean ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the output address type matches the underlying input ndarray data type and **assumes** that you know what you are doing. -* - The function returns `-1` if unable to get an element and `0` otherwise. -* - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param out output address -* @return status code -*/ -int8_t stdlib_ndarray_iget_bool( const struct ndarray *arr, const int64_t idx, bool *out ) { - uint8_t *ptr = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ptr == NULL ) { - return -1; - } - return stdlib_ndarray_get_ptr_bool( ptr, out ); -} diff --git a/src/iget_ptr.c b/src/iget_ptr.c deleted file mode 100644 index d34e4b7..0000000 --- a/src/iget_ptr.c +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/iget_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/ndarray/ctor/macros.h" -#include "stdlib/ndarray/orders.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include "stdlib/ndarray/base/ind.h" -#include "stdlib/ndarray/base/iteration_order.h" -#include -#include - -/** -* Returns a pointer in the underlying byte array for an ndarray data element located at a specified linear index. -* -* ## Notes -* -* - For zero-dimensional arrays, the function returns a pointer to the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @return underlying byte array pointer -*/ -uint8_t * stdlib_ndarray_iget_ptr( const struct ndarray *arr, const int64_t idx ) { - int64_t *strides; - int64_t *shape; - int64_t ndims; - uint8_t *ind; - int64_t s; - int64_t i; - int64_t j; - int8_t io; - - // Retrieve the number of dimensions - ndims = arr->ndims; - - // For zero-dimensional ndarrays, we ignore the index argument and return a pointer to the first (and only) indexed element... - if ( ndims == 0 ) { - return (arr->data) + (arr->offset); // pointer arithmetic - } - // Copy index argument to a mutable variable: - j = idx; - - // Resolve an ndarray index based on the ndarray index mode: - j = stdlib_ndarray_ind( j, (arr->length)-1, arr->imode ); - if ( j < 0 ) { - return NULL; - } - // Determine the pointer to the first indexed element: - ind = (arr->data) + (arr->offset); // pointer arithmetic - - // Determine the iteration order based on the ndarray strides: - strides = arr->strides; - io = stdlib_ndarray_iteration_order( ndims, strides ); - - // Check for trivial case... - if ( (arr->flags) & (STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG | STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG) ) { - // Trivial case where we have all positive strides... - if ( io == 1 ) { - return ind + (j*(arr->BYTES_PER_ELEMENT)); // pointer arithmetic - } - // Trivial case where we have all negative strides... - if ( io == -1 ) { - return ind - (j*(arr->BYTES_PER_ELEMENT)); // pointer arithmetic - } - } - // 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 byte array... - shape = arr->shape; - if ( (arr->order) == STDLIB_NDARRAY_COLUMN_MAJOR ) { - for ( i = 0; i < ndims; i++ ) { - s = j % shape[ i ]; - j -= s; - j /= shape[ i ]; - ind += s * strides[ i ]; // pointer arithmetic - } - return ind; - } - // Case: row-major - for ( i = ndims-1; i >= 0; i-- ) { - s = j % shape[ i ]; - j -= s; - j /= shape[ i ]; - ind += s * strides[ i ]; // pointer arithmetic - } - return ind; -} diff --git a/src/iset.c b/src/iset.c deleted file mode 100644 index 7c078b3..0000000 --- a/src/iset.c +++ /dev/null @@ -1,334 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/iset.h" -#include "stdlib/ndarray/ctor/iget_ptr.h" -#include "stdlib/ndarray/ctor/set_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include -#include - -/** -* Sets an ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. -* - The function has no way of determining whether `v` actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset( const struct ndarray *arr, const int64_t idx, const void *v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_value( arr, ind, v ); -} - -/** -* Sets a double-precision floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_float64( const struct ndarray *arr, const int64_t idx, const double v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_float64( ind, v ); -} - -/** -* Sets a single-precision floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_float32( const struct ndarray *arr, const int64_t idx, const float v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_float32( ind, v ); -} - -/** -* Sets an unsigned 64-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_uint64( const struct ndarray *arr, const int64_t idx, const uint64_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint64( ind, v ); -} - -/** -* Sets a signed 64-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_int64( const struct ndarray *arr, const int64_t idx, const int64_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int64( ind, v ); -} - -/** -* Sets an unsigned 32-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_uint32( const struct ndarray *arr, const int64_t idx, const uint32_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint32( ind, v ); -} - -/** -* Sets a signed 32-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_int32( const struct ndarray *arr, const int64_t idx, const int32_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int32( ind, v ); -} - -/** -* Sets an unsigned 16-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_uint16( const struct ndarray *arr, const int64_t idx, const uint16_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint16( ind, v ); -} - -/** -* Sets a signed 16-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_int16( const struct ndarray *arr, const int64_t idx, const int16_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int16( ind, v ); -} - -/** -* Sets an unsigned 8-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_uint8( const struct ndarray *arr, const int64_t idx, const uint8_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint8( ind, v ); -} - -/** -* Sets a signed 8-bit integer ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_int8( const struct ndarray *arr, const int64_t idx, const int8_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int8( ind, v ); -} - -/** -* Sets a double-precision complex floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_complex128( const struct ndarray *arr, const int64_t idx, const stdlib_complex128_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_complex128( ind, v ); -} - -/** -* Sets a single-precision complex floating-point ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_complex64( const struct ndarray *arr, const int64_t idx, const stdlib_complex64_t v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_complex64( ind, v ); -} - -/** -* Sets a boolean ndarray data element located at a specified linear index. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of `idx`. -* -* @param arr input ndarray -* @param idx linear view index -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_iset_bool( const struct ndarray *arr, const int64_t idx, const bool v ) { - uint8_t *ind = stdlib_ndarray_iget_ptr( arr, idx ); - if ( ind == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_bool( ind, v ); -} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 08f977d..0000000 --- a/src/main.c +++ /dev/null @@ -1,440 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor.h" -#include "stdlib/ndarray/base/bytes_per_element.h" -#include "stdlib/ndarray/base/iteration_order.h" -#include "stdlib/ndarray/base/minmax_view_buffer_index.h" -#include "stdlib/ndarray/base/numel.h" -#include "stdlib/ndarray/base/strides2order.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/ndarray/index_modes.h" -#include "stdlib/ndarray/orders.h" -#include -#include - -// NOTE: keep functions in alphabetical order... - -/** -* Returns a pointer to a dynamically allocated ndarray. -* -* ## Notes -* -* - The user is responsible for freeing the allocated memory. -* -* - To create a zero-dimensional array, -* -* - provide an `ndims` argument equal to `0`. -* - a `shape` argument equal to a null pointer. -* - a `strides` argument containing a single element equal to `0`. -* -* The `order` argument can be either row-major or column-major and has no effect on data storage or access. -* -* ```javascript -* #include "stdlib/ndarray/ctor.h" -* #include "stdlib/ndarray/dtypes.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include -* -* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -* int64_t *shape = NULL; -* int64_t strides = { 0 }; -* int64_t offset = 0; -* -* struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, buffer, 0, shape, strides, offset, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, { STDLIB_NDARRAY_INDEX_ERROR } ); -* ``` -* -* @param dtype data type -* @param data pointer to the underlying byte array -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides (in bytes) -* @param offset byte offset specifying the location of the first element -* @param order specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @param imode specifies how to handle indices which exceed array dimensions -* @param nsubmodes number of subscript modes -* @param submodes specifies how to handle subscripts which exceed array dimensions on a per dimension basis (if provided fewer submodes than dimensions, submodes are recycled using modulo arithmetic) -* @return pointer to a dynamically allocated ndarray or, if unable to allocate memory, a null pointer -* -* @example -* #include "stdlib/ndarray/ctor.h" -* #include "stdlib/ndarray/dtypes.h" -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/orders.h" -* #include "stdlib/ndarray/base/bytes_per_element.h" -* #include -* #include -* #include -* -* // Specify the underlying data type: -* enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; -* -* // Create an underlying byte array: -* uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -* -* // Specify the number of array dimensions: -* int64_t ndims = 1; -* -* // Specify the array shape: -* int64_t shape[] = { 3 }; // vector consisting of 3 doubles -* -* // Specify the array strides: -* int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; -* -* // Specify the byte offset: -* int64_t offset = 0; -* -* // Specify the array order (note: this does not matter for a 1-dimensional array): -* enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; -* -* // Specify the index mode: -* enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; -* -* // Specify the subscript index modes: -* int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* int64_t nsubmodes = 1; -* -* // Create an ndarray: -* struct ndarray *x = stdlib_ndarray_allocate( dtype, buffer, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); -* if ( x == NULL ) { -* fprintf( stderr, "Error allocating memory.\n" ); -* exit( 1 ); -* } -* -* // Free allocated memory: -* stdlib_ndarray_free( x ); -*/ -struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int8_t order, int8_t imode, int64_t nsubmodes, int8_t *submodes ) { - int64_t len; - - struct ndarray *arr = malloc( sizeof( struct ndarray ) ); - if ( arr == NULL ) { - return NULL; - } - arr->data = data; - arr->dtype = dtype; - arr->imode = imode; - arr->ndims = ndims; - arr->nsubmodes = nsubmodes; - arr->offset = offset; - arr->order = order; - arr->shape = shape; - arr->strides = strides; - arr->submodes = submodes; - - if ( shape == NULL ) { - len = 1; - } else { - len = stdlib_ndarray_numel( ndims, shape ); - } - arr->length = len; - - arr->BYTES_PER_ELEMENT = stdlib_ndarray_bytes_per_element( dtype ); - arr->byteLength = len * (arr->BYTES_PER_ELEMENT); - arr->flags = stdlib_ndarray_flags( arr ); - - return arr; -} - -/** -* Returns the size of an ndarray (in bytes). -* -* @param arr input ndarray -* @return array size -*/ -int64_t stdlib_ndarray_bytelength( const struct ndarray *arr ) { - return arr->byteLength; -} - -/** -* Returns a pointer to an ndarray's underlying byte array. -* -* @param arr input ndarray -* @return underlying byte array -*/ -uint8_t * stdlib_ndarray_data( const struct ndarray *arr ) { - return arr->data; -} - -/** -* Returns an ndarray dimension size. -* -* ## Notes -* -* - The function does not perform any sanity checks. -* - If an input ndarray is zero-dimensional, the function always returns `-1`. -* -* @param arr input ndarray -* @param i dimension index -* @return dimension size -*/ -int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i ) { - if ( arr->shape == NULL ) { - return -1; - } - return arr->shape[ i ]; -} - -/** -* Disables specified ndarray flags. -* -* ## Notes -* -* - The function does not perform any sanity checks and **assumes** the user knows what s/he is doing. -* -* @param arr input ndarray -* @param flags bit mask to disable flags -* @return status code -*/ -int8_t stdlib_ndarray_disable_flags( struct ndarray *arr, const int64_t flags ) { - arr->flags &= ~flags; - return 0; -} - -/** -* Returns an ndarray data type. -* -* @param arr input ndarray -* @return array data type -*/ -int16_t stdlib_ndarray_dtype( const struct ndarray *arr ) { - return arr->dtype; -} - -/** -* Enables specified ndarray flags. -* -* ## Notes -* -* - The function does not perform any sanity checks and **assumes** the user knows what s/he is doing. -* -* @param arr input ndarray -* @param flags bit mask to enable flags -* @return status code -*/ -int8_t stdlib_ndarray_enable_flags( struct ndarray *arr, const int64_t flags ) { - arr->flags |= flags; - return 0; -} - -/** -* Returns ndarray flags. -* -* @param arr input ndarray -* @return flags -*/ -int64_t stdlib_ndarray_flags( const struct ndarray *arr ) { - uint8_t contiguous; - int64_t *strides; - int64_t nbytes; - int64_t tmp[2]; - int64_t ndims; - int64_t flags; - int64_t len; - int8_t ord; - - // Cache various ndarray data: - len = arr->length; - ndims = arr->ndims; - strides = arr->strides; - nbytes = arr->BYTES_PER_ELEMENT; - - // Initialize the memory for `flags`: - flags = 0; - - // Determine if the array can be stored contiguously... - if ( len == 0 || stdlib_ndarray_iteration_order( ndims, strides ) == 0 ) { - // 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: - contiguous = 0; - } else if ( ndims == 0 ) { - // If an array is zero-dimensional, data consists of a single element which means it is trivially compatible with a single memory segment: - contiguous = 1; - } else { - // Ensure that the array is compatible with a single memory segment: - stdlib_ndarray_minmax_view_buffer_index( ndims, arr->shape, strides, arr->offset, tmp ); - if ( (len*nbytes) == ( (tmp[1]-tmp[0])+nbytes ) ) { - // Compatible: - contiguous = 1; - } else { - // Incompatible: - contiguous = 0; - } - } - // Determine if the array is row-major/column-major contiguous: - if ( contiguous == 1 ) { - // Infer the array "order" from the stride array (this is supplementary to `arr->order`): - ord = stdlib_ndarray_strides2order( ndims, strides ); - - if ( ord == 1 || ord == 3 ) { - flags |= STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG; - } - if ( ord == 2 || ord == 3 ) { - flags |= STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG; - } - } - return flags; -} - -/** -* Frees an ndarray's allocated memory. -* -* @param arr input ndarray -*/ -void stdlib_ndarray_free( struct ndarray *arr ) { - free( arr ); -} - -/** -* Tests whether an ndarray has specified flags enabled. -* -* @param arr input ndarray -* @param flags bit mask specifying the flags to test against -* @return `1` if flags are set and `0` otherwise -*/ -int8_t stdlib_ndarray_has_flags( const struct ndarray *arr, const int64_t flags ) { - if ( ( arr->flags & flags ) == flags ) { - return 1; - } - return 0; -} - -/** -* Returns the index mode of an ndarray. -* -* @param arr input ndarray -* @return index mode -*/ -int8_t stdlib_ndarray_index_mode( const struct ndarray *arr ) { - return arr->imode; -} - -/** -* Returns the number of elements in an ndarray. -* -* @param arr input ndarray -* @return number of elements -*/ -int64_t stdlib_ndarray_length( const struct ndarray *arr ) { - return arr->length; -} - -/** -* Returns the number of ndarray dimensions. -* -* @param arr input ndarray -* @return number of dimensions -*/ -int64_t stdlib_ndarray_ndims( const struct ndarray *arr ) { - return arr->ndims; -} - -/** -* Returns the number of ndarray subscript modes. -* -* @param arr input ndarray -* @return number of subscript modes -*/ -int64_t stdlib_ndarray_nsubmodes( const struct ndarray *arr ) { - return arr->nsubmodes; -} - -/** -* Returns an ndarray index offset (in bytes). -* -* @param arr input ndarray -* @return array strides -*/ -int64_t stdlib_ndarray_offset( const struct ndarray *arr ) { - return arr->offset; -} - -/** -* Returns the order of an ndarray. -* -* @param arr input ndarray -* @return array order -*/ -int8_t stdlib_ndarray_order( const struct ndarray *arr ) { - return arr->order; -} - -/** -* Returns a pointer to an array containing an ndarray shape (dimensions). -* -* ## Notes -* -* - If an input ndarray is zero-dimensional, the function returns a null pointer. -* -* @param arr input ndarray -* @return array shape (dimensions) -*/ -int64_t * stdlib_ndarray_shape( const struct ndarray *arr ) { - return arr->shape; -} - -/** -* Returns an ndarray stride (in bytes). -* -* ## Notes -* -* - The function does not perform any sanity checks. -* -* @param arr input ndarray -* @param i dimension index -* @return array stride -*/ -int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i ) { - return arr->strides[ i ]; -} - -/** -* Returns a pointer to an array containing ndarray strides (in bytes). -* -* @param arr input ndarray -* @return array strides -*/ -int64_t * stdlib_ndarray_strides( const struct ndarray *arr ) { - return arr->strides; -} - -/** -* Returns an ndarray subscript mode. -* -* ## Notes -* -* - If an ndarray has fewer subscript modes than dimensions, modes are recycled using modulo arithmetic. -* - The function does not perform any sanity checks. -* -* @param arr input ndarray -* @param i dimension index -* @return subscript mode -*/ -int8_t stdlib_ndarray_submode( const struct ndarray *arr, const int64_t i ) { - return arr->submodes[ i%(arr->nsubmodes) ]; -} - -/** -* Returns ndarray subscript modes. -* -* @param arr input ndarray -* @return subscript modes -*/ -int8_t * stdlib_ndarray_submodes( const struct ndarray *arr ) { - return arr->submodes; -} diff --git a/src/set.c b/src/set.c deleted file mode 100644 index 402c5b1..0000000 --- a/src/set.c +++ /dev/null @@ -1,320 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/set.h" -#include "stdlib/ndarray/ctor/set_ptr.h" -#include "stdlib/ndarray/ctor/get_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include -#include - -/** -* Sets an ndarray data element. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. -* - The function has no way of determining whether `v` actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing **unowned** memory is possible, and this function **assumes** you know what you are doing. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set( const struct ndarray *arr, const int64_t *sub, const void *v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_value( arr, idx, v ); -} - -/** -* Sets a double-precision floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_float64( const struct ndarray *arr, const int64_t *sub, const double v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_float64( idx, v ); -} - -/** -* Sets a single-precision floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_float32( const struct ndarray *arr, const int64_t *sub, const float v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_float32( idx, v ); -} - -/** -* Sets an unsigned 64-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_uint64( const struct ndarray *arr, const int64_t *sub, const uint64_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint64( idx, v ); -} - -/** -* Sets a signed 64-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_int64( const struct ndarray *arr, const int64_t *sub, const int64_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int64( idx, v ); -} - -/** -* Sets an unsigned 32-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_uint32( const struct ndarray *arr, const int64_t *sub, const uint32_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint32( idx, v ); -} - -/** -* Sets a signed 32-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_int32( const struct ndarray *arr, const int64_t *sub, const int32_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int32( idx, v ); -} - -/** -* Sets an unsigned 16-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_uint16( const struct ndarray *arr, const int64_t *sub, const uint16_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint16( idx, v ); -} - -/** -* Sets a signed 16-bit integer ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_int16( const struct ndarray *arr, const int64_t *sub, const int16_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int16( idx, v ); -} - -/** -* Sets an unsigned 8-bit integer ndarray data element. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_uint8( const struct ndarray *arr, const int64_t *sub, const uint8_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_uint8( idx, v ); -} - -/** -* Sets a signed 8-bit integer ndarray data element. -* -* ## Notes -* -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_int8( const struct ndarray *arr, const int64_t *sub, const int8_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_int8( idx, v ); -} - -/** -* Sets a double-precision complex floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_complex128( const struct ndarray *arr, const int64_t *sub, const stdlib_complex128_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_complex128( idx, v ); -} - -/** -* Sets a single-precision complex floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_complex64( const struct ndarray *arr, const int64_t *sub, const stdlib_complex64_t v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_complex64( idx, v ); -} - -/** -* Sets a boolean floating-point ndarray data element. -* -* ## Notes -* -* - The function does **not** verify that the type of `v` matches the underlying input ndarray data type, and, thus, overwriting **unowned** memory is possible. The function **assumes** that you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* -* @param arr input ndarray -* @param sub ndarray subscripts -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_bool( const struct ndarray *arr, const int64_t *sub, const bool v ) { - uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub ); - if ( idx == NULL ) { - return -1; - } - return stdlib_ndarray_set_ptr_bool( idx, v ); -} diff --git a/src/set_ptr.c b/src/set_ptr.c deleted file mode 100644 index f2581bb..0000000 --- a/src/set_ptr.c +++ /dev/null @@ -1,307 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/ctor/set_ptr.h" -#include "stdlib/ndarray/ctor/ndarray.h" -#include "stdlib/ndarray/dtypes.h" -#include "stdlib/complex/float32/ctor.h" -#include "stdlib/complex/float64/ctor.h" -#include -#include - -/** -* Sets an ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function does **not** perform bounds checking, and, thus, the function does **not** prevent you from overwriting **unowned** memory. Accordingly, the function **assumes** you know what you are doing. -* - The function returns `-1` if unable to set an element and `0` otherwise. -* - The function requires a pointer to a data value `v` in order to provide a generic API supporting ndarrays having different data types. -* -* @param arr input ndarray -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_value( const struct ndarray *arr, uint8_t *idx, const void *v ) { - switch ( arr->dtype ) { - case STDLIB_NDARRAY_FLOAT64: - *(double *)idx = *(double *)v; - return 0; - case STDLIB_NDARRAY_FLOAT32: - *(float *)idx = *(float *)v; - return 0; - case STDLIB_NDARRAY_UINT64: - *(uint64_t *)idx = *(uint64_t *)v; - return 0; - case STDLIB_NDARRAY_INT64: - *(int64_t *)idx = *(int64_t *)v; - return 0; - case STDLIB_NDARRAY_UINT32: - *(uint32_t *)idx = *(uint32_t *)v; - return 0; - case STDLIB_NDARRAY_INT32: - *(int32_t *)idx = *(int32_t *)v; - return 0; - case STDLIB_NDARRAY_UINT16: - *(uint16_t *)idx = *(uint16_t *)v; - return 0; - case STDLIB_NDARRAY_INT16: - *(int16_t *)idx = *(int16_t *)v; - return 0; - case STDLIB_NDARRAY_UINT8: - *(uint8_t *)idx = *(uint8_t *)v; - return 0; - case STDLIB_NDARRAY_UINT8C: - *(uint8_t *)idx = *(uint8_t *)v; - return 0; - case STDLIB_NDARRAY_INT8: - *(int8_t *)idx = *(int8_t *)v; - return 0; - case STDLIB_NDARRAY_COMPLEX128: - *(stdlib_complex128_t *)idx = *(stdlib_complex128_t *)v; - return 0; - case STDLIB_NDARRAY_COMPLEX64: - *(stdlib_complex64_t *)idx = *(stdlib_complex64_t *)v; - return 0; - case STDLIB_NDARRAY_BOOL: - *(bool *)idx = *(bool *)v; - return 0; - default: - return -1; - } -} - -/** -* Sets a double-precision floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_float64( uint8_t *idx, const double v ) { - *(double *)idx = v; - return 0; -} - -/** -* Sets a single-precision floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_float32( uint8_t *idx, const float v ) { - *(float *)idx = v; - return 0; -} - -/** -* Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_uint64( uint8_t *idx, const uint64_t v ) { - *(uint64_t *)idx = v; - return 0; -} - -/** -* Sets a signed 64-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_int64( uint8_t *idx, const int64_t v ) { - *(int64_t *)idx = v; - return 0; -} - -/** -* Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_uint32( uint8_t *idx, const uint32_t v ) { - *(uint32_t *)idx = v; - return 0; -} - -/** -* Sets a signed 32-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_int32( uint8_t *idx, const int32_t v ) { - *(int32_t *)idx = v; - return 0; -} - -/** -* Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_uint16( uint8_t *idx, const uint16_t v ) { - *(uint16_t *)idx = v; - return 0; -} - -/** -* Sets a signed 16-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_int16( uint8_t *idx, const int16_t v ) { - *(int16_t *)idx = v; - return 0; -} - -/** -* Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_uint8( uint8_t *idx, const uint8_t v ) { - *(uint8_t *)idx = v; - return 0; -} - -/** -* Sets a signed 8-bit integer ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_int8( uint8_t *idx, const int8_t v ) { - *(int8_t *)idx = v; - return 0; -} - -/** -* Sets a double-precision complex floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_complex128( uint8_t *idx, const stdlib_complex128_t v ) { - *(stdlib_complex128_t *)idx = v; - return 0; -} - -/** -* Sets a single-precision complex floating-point ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_complex64( uint8_t *idx, const stdlib_complex64_t v ) { - *(stdlib_complex64_t *)idx = v; - return 0; -} - -/** -* Sets a boolean ndarray data element specified by a byte array pointer. -* -* ## Notes -* -* - The function has no way of determining whether `idx` actually points to a compatible memory address. Accordingly, overwriting **unowned** memory is possible, and this function **assumes** you know what you are doing. -* - The function always returns `0`. -* -* @param idx byte array pointer to an ndarray data element -* @param v value to set -* @return status code -*/ -int8_t stdlib_ndarray_set_ptr_bool( uint8_t *idx, const bool v ) { - *(bool *)idx = v; - return 0; -} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01ffd0f --- /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.argument_validation.js b/test/test.argument_validation.js deleted file mode 100644 index 5ee8493..0000000 --- a/test/test.argument_validation.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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 constructor throws an error if not provided a valid `dtype` argument', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var order; - var shape; - var i; - - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value, buffer, shape, strides, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `dtype` argument (options)', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var order; - var shape; - var i; - - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value, buffer, shape, strides, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `buffer` argument', function test( t ) { - var strides; - var values; - var offset; - var dtype; - var order; - var shape; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - { - 'length': 10, - 'get': function noop() {}, - 'set': true - }, - { - 'length': 10, - 'get': true, - 'set': function noop() {} - }, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, value, shape, strides, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `buffer` argument (options)', function test( t ) { - var strides; - var values; - var offset; - var dtype; - var order; - var shape; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - { - 'length': 10, - 'get': function noop() {}, - 'set': true - }, - { - 'length': 10, - 'get': true, - 'set': function noop() {} - }, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, value, shape, strides, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `shape` argument', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ 1, 3.14 ], - [ -1, -2 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, value, strides, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `shape` argument (options)', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [ 1, 3.14 ], - [ -1, -2 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, value, strides, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if the number of ndarray dimensions may cause stack limits to be exceeded', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var order; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - 1e5, - 1e6 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var shape = new Float64Array( value ); - ndarray( dtype, buffer, shape, strides, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if the number of ndarray dimensions may cause stack limits to be exceeded (options)', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var order; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - 1e5, - 1e6 - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var shape = new Float64Array( value ); - ndarray( dtype, buffer, shape, strides, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 3.14 ], - [ -1, -3.14 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (0d)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = []; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 1.1 ], - [ 1, 3.14 ], - [ -1, -3.14 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (0d)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = []; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - [ 1 ], - [ 2 ], - [ 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (options)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 3.14 ], - [ -1, -3.14 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (options; 0d)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = []; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 1.1 ], - [ 1, 3.14 ], - [ -1, -3.14 ], - [ 1, '1' ], - [ 1, null ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (number of dimensions)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - [ 1 ], - [ 4, 2, 1 ], - [ 4, 4, 2, 1 ], - [ 4, 4, 4, 2, 1 ], - [ 4, 4, 4, 4, 2, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (number of dimensions; 0d)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = []; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - [], - [ 2, 1 ], - [ 4, 2, 1 ], - [ 4, 4, 2, 1 ], - [ 4, 4, 4, 2, 1 ], - [ 4, 4, 4, 4, 2, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (number of dimensions; options)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = [ 2, 2 ]; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - [ 1 ], - [ 4, 2, 1 ], - [ 4, 4, 2, 1 ], - [ 4, 4, 4, 2, 1 ], - [ 4, 4, 4, 4, 2, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `strides` argument (number of dimensions; options; 0d)', function test( t ) { - var values; - var offset; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - shape = []; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - order = 'row-major'; - offset = 0; - - values = [ - [], - [ 2, 1 ], - [ 4, 2, 1 ], - [ 4, 4, 2, 1 ], - [ 4, 4, 4, 2, 1 ], - [ 4, 4, 4, 4, 2, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, value, offset, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `offset` argument', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, strides, value, order ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `offset` argument (options)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var dtype; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, strides, value, order, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `order` argument', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var shape; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - 'c', - 'f', - 'c-style', - 'fortran', - 'fortran-style', - 'row', - 'column', - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, strides, offset, value ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid `order` argument (options)', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var shape; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - 'c', - 'f', - 'c-style', - 'fortran', - 'fortran-style', - 'row', - 'column', - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, strides, offset, value, {} ); - }; - } -}); - -tape( 'the constructor throws an error if not provided a valid options argument', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var shape; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( dtype, buffer, shape, strides, offset, order, value ); - }; - } -}); - -tape( 'the constructor throws an error if provided an invalid option', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var dtype; - var shape; - var order; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - ndarray( dtype, buffer, shape, strides, offset, order, opts ); - }; - } -}); - -tape( 'the constructor throws an error if not provided compatible input arguments', function test( t ) { - var strides; - var values; - var offset; - var buffer; - var order; - var dtype; - var shape; - var i; - - dtype = 'generic'; - buffer = [ 0.0, 1.0, 2.0, 3.0 ]; - shape = [ 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1 ]; - offset = 0; - - values = [ - [ dtype, [ 0.0 ], shape, strides, offset, order ], - [ dtype, buffer, [ 3, 2 ], strides, offset, order ], - [ dtype, buffer, shape, [ 2, 2 ], offset, order ], - [ dtype, buffer, shape, strides, 2, order ], - [ dtype, buffer, shape, strides, 20, order ], - [ dtype, buffer, shape, [ 2, -1 ], offset, order ], - [ dtype, buffer, shape, [ -2, 1 ], offset, order ], - [ dtype, buffer, shape, [ -2, 1 ], 1, order ], - [ dtype, buffer, shape, [ -2, -1 ], offset, order ], - [ dtype, buffer, shape, [ -2, -1 ], 1, order ], - [ dtype, buffer, shape, [ -2, -1 ], 2, order ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + JSON.stringify( values[ i ] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray.apply( null, value ); - }; - } -}); diff --git a/test/test.copy_array.js b/test/test.copy_array.js deleted file mode 100644 index 7259781..0000000 --- a/test/test.copy_array.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isArray = require( '@stdlib/assert-is-array' ); -var copy = require( './../lib/copy_array.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof copy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function copies the elements of an array-like input value and returns an output array', function test( t ) { - var arr; - var out; - - arr = [ 1.0, 2.0, 3.0 ]; - out = copy( arr, arr.length ); - - t.strictEqual( isArray( out ), true, 'returns an array' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.deepEqual( arr, out, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function copies the elements of an array-like input value and returns an output array (>64K elements)', function test( t ) { - var arr; - var out; - var i; - - arr = []; - for ( i = 0; i < 1e6; i++ ) { - arr.push( i ); - } - out = copy( arr, arr.length ); - - t.strictEqual( isArray( out ), true, 'returns an array' ); - t.notEqual( out, arr, 'returns a new instance' ); - t.deepEqual( arr, out, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get.js b/test/test.instance.get.js deleted file mode 100644 index f741422..0000000 --- a/test/test.instance.get.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 tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method', 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1, 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.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method (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 = 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.end(); -}); diff --git a/test/test.instance.get_0d.js b/test/test.instance.get_0d.js deleted file mode 100644 index 481496f..0000000 --- a/test/test.instance.get_0d.js +++ /dev/null @@ -1,131 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if provided any arguments (0d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 0, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array 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 = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get(), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element (0d; complex typed)', 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 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get(); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get_1d.js b/test/test.instance.get_1d.js deleted file mode 100644 index 7d126a2..0000000 --- a/test/test.instance.get_1d.js +++ /dev/null @@ -1,1221 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if not provided an integer value (1d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; complex typed)', 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 = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - v = arr.get( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - v = arr.get( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; complex typed)', 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 = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - v = arr.get( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - v = arr.get( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=wrap; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - v = arr.get( 4 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - v = arr.get( 5 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - v = arr.get( -2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - v = arr.get( -1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=clamp; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - v = arr.get( 4 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - v = arr.get( 5 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - v = arr.get( -2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - v = arr.get( -1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=throw; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -3 ), 2.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=normalize; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.get( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.get( -3 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -11 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -3 ), 2.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'normalize' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -3 ), 2.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -3 ), 2.0, 'returns expected value' ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[wrap,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; row-major; submode=[clamp,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'wrap' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (1d; column-major; submode=[clamp,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get_2d.js b/test/test.instance.get_2d.js deleted file mode 100644 index d65c514..0000000 --- a/test/test.instance.get_2d.js +++ /dev/null @@ -1,1136 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if not provided an integer value (2d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - return j; - - function i() { - arr.get( value, 0 ); - } - - function j() { - arr.get( 0, value ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; complex typed)', 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 ); - - v = arr.get( 0, 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.get( 0, 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.get( 1, 0 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.get( 1, 1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; complex typed)', 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 = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0, 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.get( 0, 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.get( 1, 0 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.get( 1, 1 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; 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( 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 constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 2, 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2, 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -20, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -20, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; submode=[clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 2, 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2, 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw', 'throw' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -2, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'normalize' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( -2, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -20, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; submode=[normalize,normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'normalize', 'normalize' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 4 ], - [ -20, -3 ], - [ 9, 10 ], - [ 3, 3 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 2, 3 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (2d; column-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - 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, opts ); - - t.strictEqual( arr.get( 2, 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, -3 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 9, 10 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 3, 3 ), 4.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get_3d.js b/test/test.instance.get_3d.js deleted file mode 100644 index 2e5b35e..0000000 --- a/test/test.instance.get_3d.js +++ /dev/null @@ -1,915 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if not provided an integer value (3d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 2 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - if ( dim === 1 ) { - return j; - } - return k; - - function i() { - arr.get( value, 0, 0 ); - } - - function j() { - arr.get( 0, value, 0 ); - } - - function k() { - arr.get( 0, 0, value ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; 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 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; complex typed)', 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0, 0, 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.get( 0, 0, 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.get( 0, 1, 0 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.get( 0, 1, 1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; 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 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -3, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -20, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -3, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; submode=[throw,throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw', 'throw', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -2, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'row-major'; - strides = [ 3, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -3, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -20, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; submode=[normalize,normalize,normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'normalize', 'normalize', 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - shape = [ 1, 3, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 3 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -3, 0 ), 1.0, 'returns expected value' ); - - values = [ - [ 2, 6, 100 ], - [ 0, -20, -4 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (3d; column-major; submode=[wrap,wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 2, 6, 100 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -2, -4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 2, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get_4d.js b/test/test.instance.get_4d.js deleted file mode 100644 index 2fc6d8c..0000000 --- a/test/test.instance.get_4d.js +++ /dev/null @@ -1,931 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if not provided an integer value (4d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 2 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 3 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - if ( dim === 1 ) { - return j; - } - if ( dim === 2 ) { - return k; - } - return l; - - function i() { - arr.get( value, 0, 0, 0 ); - } - - function j() { - arr.get( 0, value, 0, 0 ); - } - - function k() { - arr.get( 0, 0, value, 0 ); - } - - function l() { - arr.get( 0, 0, 0, value ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; 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 = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; complex typed)', 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0, 0, 0, 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.get( 0, 0, 0, 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.get( 0, 0, 1, 0 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.get( 0, 0, 1, 1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; 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 = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; submode=[clamp,clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; submode=[normalize,normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'normalize', 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 10, 2, 2, 0 ], - [ -2, 6, -1, 9 ], - [ -5, -3, 4, -5 ], - [ 5, 5, 5, 5 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (4d; column-major; submode=[wrap,wrap,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 10, 2, 2, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( -2, 6, -1, 9 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( -5, -3, 4, -5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 5, 5, 5, 5 ), 4.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.get_nd.js b/test/test.instance.get_nd.js deleted file mode 100644 index b80a4c7..0000000 --- a/test/test.instance.get_nd.js +++ /dev/null @@ -1,874 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `get` method which throws an error if not provided an integer value (>4d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - var j; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - for ( j = 0; j < shape.length; j++ ) { - t.throws( badValue( values[ i ], j ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - } - t.end(); - - function badValue( value, dim ) { - return function badValue() { - var args = new Array( shape.length ); - var i; - - for ( i = 0; i < args.length; i++ ) { - if ( i === dim ) { - args[ i ] = value; - } else { - args[ i ] = 0; - } - } - arr.get.apply( arr, args ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; 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 = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1, 0, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; complex typed)', 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.get( 0, 0, 0, 0, 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.get( 0, 0, 0, 0, 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.get( 0, 0, 0, 1, 0 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.get( 0, 0, 0, 1, 1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; 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 = [ 1, 1, 2, 2, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -10, -10, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -10, -10, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; submode=[clamp,clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; submode=[throw,throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw', 'throw', 'throw' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -1, -1, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; submode=[normalize,normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'normalize', 'normalize' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 0, 10, 10, 0, 0 ], - [ 0, 0, 5, 0, 0 ], - [ 0, 5, 6, 0, 0 ], - [ 0, -10, -10, 0, 0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.get.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; row-major; submode=[wrap,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'row-major'; - strides = [ 4, 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `get` method for retrieving an array element using subscripts (>4d; column-major; submode=[wrap,wrap,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'clamp', 'clamp' ] - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2, 1, 1 ]; - order = 'column-major'; - strides = [ 1, 1, 2, 4, 4 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.get( 0, 10, 10, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 5, 0, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 5, 6, 0, 0 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, -1, -1, 0, 0 ), 2.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.iget.js b/test/test.instance.iget.js deleted file mode 100644 index b61e3e4..0000000 --- a/test/test.instance.iget.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method', 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.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method (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, 'iget' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iget' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iget ), true, 'has method' ); - - t.end(); -}); diff --git a/test/test.instance.iget_0d.js b/test/test.instance.iget_0d.js deleted file mode 100644 index 3af2790..0000000 --- a/test/test.instance.iget_0d.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array 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 = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( arr.iget(), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element (0d; complex typed)', 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 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget(); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.instance.iget_1d.js b/test/test.instance.iget_1d.js deleted file mode 100644 index 0f1e164..0000000 --- a/test/test.instance.iget_1d.js +++ /dev/null @@ -1,1335 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method which throws an error if not provided an integer value (1d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - 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 ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; complex typed)', 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 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; complex typed)', 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 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; complex typed)', 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 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; complex typed)', 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 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=wrap; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( -2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=wrap; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( -2 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=wrap; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( -2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=wrap; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( -2 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=clamp; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( -1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=clamp; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( -1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=clamp; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( -1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 6 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=clamp; complex typed)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - var v; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 2 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( -1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - - values = [ - [ 5 ], - [ 6 ], - [ -10 ], - [ -20 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -10 ], - [ -20 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -10 ], - [ -20 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 5 ], - [ 6 ], - [ -10 ], - [ -20 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 5 ], - [ 6 ], - [ -1 ], - [ -2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iget_2d.js b/test/test.instance.iget_2d.js deleted file mode 100644 index 4de9463..0000000 --- a/test/test.instance.iget_2d.js +++ /dev/null @@ -1,1930 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method which throws an error if not provided an integer value (2d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - 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 ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; complex typed)', 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 ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; complex typed)', 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 = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; complex typed)', 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 ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; complex typed)', 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 ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; 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( 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iget_3d.js b/test/test.instance.iget_3d.js deleted file mode 100644 index 3fa528b..0000000 --- a/test/test.instance.iget_3d.js +++ /dev/null @@ -1,1854 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method which throws an error if not provided an integer value (3d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; complex typed)', 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; complex typed)', 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iget_4d.js b/test/test.instance.iget_4d.js deleted file mode 100644 index 561aee2..0000000 --- a/test/test.instance.iget_4d.js +++ /dev/null @@ -1,1854 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method which throws an error if not provided an integer value (4d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; complex typed)', 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; complex typed)', 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iget_nd.js b/test/test.instance.iget_nd.js deleted file mode 100644 index 2ab95be..0000000 --- a/test/test.instance.iget_nd.js +++ /dev/null @@ -1,1854 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iget` method which throws an error if not provided an integer value (>4d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget( value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; complex typed)', 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; complex typed)', 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - v = arr.iget( 0 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - - v = arr.iget( 1 ); - t.strictEqual( realf( v ), 1.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); - - v = arr.iget( 2 ); - t.strictEqual( realf( v ), 7.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 8.0, 'returns expected value' ); - - v = arr.iget( 3 ); - t.strictEqual( realf( v ), 5.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 6.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 1.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 2.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 3.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - t.strictEqual( arr.iget( 4 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( 5 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.iget( -2 ), 4.0, 'returns expected value' ); - t.strictEqual( arr.iget( -1 ), 4.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4 ], - [ 5 ], - [ -20 ], - [ -10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4 ], - [ 5 ], - [ -2 ], - [ -1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iget.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iset.js b/test/test.instance.iset.js deleted file mode 100644 index 9f1904a..0000000 --- a/test/test.instance.iset.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method', 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, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method (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, 'iset' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'iset' ), true, 'has property' ); - t.strictEqual( isFunction( arr.iset ), true, 'has method' ); - - t.end(); -}); diff --git a/test/test.instance.iset_0d.js b/test/test.instance.iset_0d.js deleted file mode 100644 index b6fb28e..0000000 --- a/test/test.instance.iset_0d.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element (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 ]; - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.iset( 5.0 ); - - t.strictEqual( arr.iget(), 5.0, 'returns expected value' ); - t.deepEqual( buffer, [ 1.0, 5.0, 3.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.iset_1d.js b/test/test.instance.iset_1d.js deleted file mode 100644 index f09476f..0000000 --- a/test/test.instance.iset_1d.js +++ /dev/null @@ -1,1119 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method which throws an error if not provided an integer value for the first argument (1d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - 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 ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset( value, 0.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 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 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 7.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 8.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 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 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 7.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 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 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 7.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 8.0, 7.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 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 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.iget( 3 ), 7.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -1, 7.0 ); - arr.iset( -2, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.iset( 0, 5.0 ); - arr.iset( 1, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'row-major'; - strides = [ -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iset_2d.js b/test/test.instance.iset_2d.js deleted file mode 100644 index b70b4de..0000000 --- a/test/test.instance.iset_2d.js +++ /dev/null @@ -1,1711 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method which throws an error if not provided an integer value for the first argument (2d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - 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 ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset( value, 0.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; 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 ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iset_3d.js b/test/test.instance.iset_3d.js deleted file mode 100644 index 3115fc0..0000000 --- a/test/test.instance.iset_3d.js +++ /dev/null @@ -1,1711 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method which throws an error if not provided an integer value for the first argument (3d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset( value, 0.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iset_4d.js b/test/test.instance.iset_4d.js deleted file mode 100644 index 79be1f9..0000000 --- a/test/test.instance.iset_4d.js +++ /dev/null @@ -1,1711 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method which throws an error if not provided an integer value for the first argument (4d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset( value, 0.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.iset_nd.js b/test/test.instance.iset_nd.js deleted file mode 100644 index b275a4e..0000000 --- a/test/test.instance.iset_nd.js +++ /dev/null @@ -1,1711 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has an `iset` method which throws an error if not provided an integer value for the first argument (>4d)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset( value, 0.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 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 constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.iset( 4, 5.0 ); - arr.iset( 5, 6.0 ); - arr.iset( -2, 7.0 ); - arr.iset( -1, 8.0 ); - - t.strictEqual( arr.iget( 0 ), 8.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 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 6.0, 2.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, -1 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, 1 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, -2, -1 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, 2 ]; - offset = 1; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, -2 ]; - offset = 2; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has an `iset` method for setting an array element using a linear index (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, -1, -2 ]; - offset = 3; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -2, 7.0 ], - [ -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.iset.apply( arr, value ); - }; - } -}); diff --git a/test/test.instance.properties.js b/test/test.instance.properties.js deleted file mode 100644 index 156f292..0000000 --- a/test/test.instance.properties.js +++ /dev/null @@ -1,1128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -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 ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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, 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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, 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which has a `data` property pointing to the underlying data buffer (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, 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which has a `dtype` property specifying the underlying data type (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, 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 constructor returns an instance which has a `flags` property providing information regarding 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 constructor returns an instance which has a `flags` property providing information regarding 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 constructor returns an instance which has a `flags` property providing information regarding 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 constructor returns an instance which has a `flags` property providing information regarding 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 constructor returns an instance which has a `flags` property providing information regarding 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which has a `length` property specifying the number of array elements (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, 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 constructor returns an instance which 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 constructor returns an instance which 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, 0, 'has expected value' ); - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which 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 constructor returns an instance which 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, 4.0, 5.0, 6.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 constructor returns an instance which 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 constructor returns an instance which has an `offset` property specifying the location of the first indexed 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, 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, '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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 = 'row-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(); -}); diff --git a/test/test.instance.set.js b/test/test.instance.set.js deleted file mode 100644 index 25d2714..0000000 --- a/test/test.instance.set.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 tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method', 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1, 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' ); - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method (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, 'set' ), false, 'does not have own property' ); - t.strictEqual( hasProp( arr, 'set' ), true, 'has property' ); - t.strictEqual( isFunction( arr.set ), true, 'has method' ); - t.end(); -}); diff --git a/test/test.instance.set_0d.js b/test/test.instance.set_0d.js deleted file mode 100644 index 3497660..0000000 --- a/test/test.instance.set_0d.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if provided index arguments (0d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0 ] ); - shape = []; - order = 'row-major'; - strides = [ 0 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 0, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set( value, 10.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element (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 ); - - 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(); -}); diff --git a/test/test.instance.set_1d.js b/test/test.instance.set_1d.js deleted file mode 100644 index 6fc14d7..0000000 --- a/test/test.instance.set_1d.js +++ /dev/null @@ -1,940 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if not provided an integer value for a dimension index (1d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set( value, 10.0 ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; 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 = [ 4 ]; - order = 'row-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 5.0 ); - arr.set( 1, 6.0 ); - arr.set( 2, 7.0 ); - arr.set( 3, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; 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 = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 5.0 ); - arr.set( 1, 6.0 ); - arr.set( 2, 7.0 ); - arr.set( 3, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( 6, 7.0 ); - arr.set( 7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( 6, 7.0 ); - arr.set( 7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( -1, 7.0 ); - arr.set( -2, 8.0 ); - - t.strictEqual( arr.get( 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( -1, 7.0 ); - arr.set( -7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.set( 0, 5.0 ); - arr.set( 1, 6.0 ); - arr.set( -2, 7.0 ); - arr.set( -1, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -10, 7.0 ], - [ -20, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.set( 0, 5.0 ); - arr.set( 1, 6.0 ); - arr.set( -2, 7.0 ); - arr.set( -1, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 5.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 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 ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( 6, 7.0 ); - arr.set( 7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( 6, 7.0 ); - arr.set( 7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( -1, 7.0 ); - arr.set( -2, 8.0 ); - - t.strictEqual( arr.get( 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( -1, 7.0 ); - arr.set( -7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'wrap', - 'submode': [ 'throw' ] - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'clamp', - 'submode': [ 'throw', 'throw' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 4, 5.0 ], - [ 5, 6.0 ], - [ -1, 7.0 ], - [ -2, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); - } - t.strictEqual( arr.get( 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; row-major; submode=[wrap,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'throw' ] - }; - - dtype = 'generic'; - buffer = [ 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, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( 6, 7.0 ); - arr.set( 7, 8.0 ); - - t.strictEqual( arr.get( 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (1d; column-major; submode=[clamp,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'throw' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 4 ]; - order = 'column-major'; - strides = [ 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 4, 5.0 ); - arr.set( 5, 6.0 ); - arr.set( -1, 7.0 ); - arr.set( -2, 8.0 ); - - t.strictEqual( arr.get( 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 2 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 3 ), 6.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 8.0, 2.0, 3.0, 6.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.set_2d.js b/test/test.instance.set_2d.js deleted file mode 100644 index fcc34a2..0000000 --- a/test/test.instance.set_2d.js +++ /dev/null @@ -1,1250 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if not provided an integer value for a dimension index (2d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - return j; - - function i() { - arr.set( value, 0, 10.0 ); - } - - function j() { - arr.set( 0, value, 10.0 ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; 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 ); - - 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.set( 1, 0, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 6.0, 5.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - 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, opts ); - - arr.set( 1, 0, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 5.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -20, 3, 6.0 ], - [ -1, -20, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( -1, -2, 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(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; mode=normalize)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'normalize' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -20, 3, 6.0 ], - [ -1, -20, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - arr.set( 0, 0, 5.0 ); - arr.set( 0, 1, 6.0 ); - arr.set( -1, -2, 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(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - 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 ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; submode=[clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp' ] - }; - - 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, opts ); - - arr.set( 1, 0, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 6.0, 5.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - 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, opts ); - - arr.set( 1, 0, 5.0 ); - arr.set( -2, 3, 6.0 ); - arr.set( -1, -2, 7.0 ); - arr.set( 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 5.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; submode=[throw,throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw', 'throw', 'throw' ], - 'mode': 'clamp' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw' ], - 'mode': 'wrap' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -2, 3, 6.0 ], - [ -1, -2, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; submode=[normalize,normalize,normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'normalize', 'normalize', 'normalize' ], - 'mode': 'clamp' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -20, 3, 6.0 ], - [ -1, -20, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; submode=[normalize])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'normalize' ], - 'mode': 'wrap' - }; - - 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, opts ); - - values = [ - [ 1, 10, 5.0 ], - [ -20, 3, 6.0 ], - [ -1, -20, 7.0 ], - [ 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - 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.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); // (0,1) - arr.set( -2, 3, 6.0 ); // (0,1) - arr.set( -1, -2, 7.0 ); // (1,0) - arr.set( 5, 5, 8.0 ); // (1,1) - - t.strictEqual( arr.get( 0, 0 ), 1.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, [ 1.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (2d; column-major; submode=[clamp,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'wrap' ] - }; - - 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, opts ); - - arr.set( 2, 2, 5.0 ); // (1,0) - arr.set( -2, 3, 6.0 ); // (0,1) - arr.set( -1, -2, 7.0 ); // (0,0) - arr.set( 5, 5, 8.0 ); // (1,1) - - t.strictEqual( arr.get( 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 5.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.set_3d.js b/test/test.instance.set_3d.js deleted file mode 100644 index 708c941..0000000 --- a/test/test.instance.set_3d.js +++ /dev/null @@ -1,834 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if not provided an integer value for a dimension index (3d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 2 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - if ( dim === 1 ) { - return j; - } - return k; - - function i() { - arr.set( value, 0, 0, 10.0 ); - } - - function j() { - arr.set( 0, value, 0, 10.0 ); - } - - function k() { - arr.set( 0, 0, value, 10.0 ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; 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 = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 5.0 ); - arr.set( 0, 0, 1, 6.0 ); - arr.set( 0, 1, 0, 7.0 ); - arr.set( 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; 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 = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 5.0 ); - arr.set( 0, 0, 1, 6.0 ); - arr.set( 0, 1, 0, 7.0 ); - arr.set( 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; submode=[clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); - arr.set( -4, -2, 11, 6.0 ); - arr.set( 0, 5, 0, 7.0 ); - arr.set( 0, 15, -1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw', 'throw' ], - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw' ], - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 5.0 ], - [ -4, -2, 11, 6.0 ], - [ 0, 5, 0, 7.0 ], - [ 0, 15, -1, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; row-major; submode=[wrap,wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); // (0,0,1) - arr.set( -4, -2, 11, 6.0 ); // (0,0,1) - arr.set( 0, 5, 0, 7.0 ); // (0,1,0) - arr.set( 0, 15, -1, 8.0 ); // (0,1,0) - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 8.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (3d; column-major; submode=[clamp,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 5.0 ); // (0,0,1) - arr.set( -4, -2, 11, 6.0 ); // (0,0,1) - arr.set( 0, 5, 0, 7.0 ); // (0,1,0) - arr.set( 0, 15, -1, 8.0 ); // (0,1,0) - - t.strictEqual( arr.get( 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 0 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 8.0, 6.0, 4.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.set_4d.js b/test/test.instance.set_4d.js deleted file mode 100644 index 9090bdd..0000000 --- a/test/test.instance.set_4d.js +++ /dev/null @@ -1,842 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if not provided an integer value for a dimension index (4d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ], 0 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 1 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 2 ), TypeError, 'throws an error when provided ' + values[ i ] ); - t.throws( badValue( values[ i ], 3 ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value, dim ) { - if ( dim === 0 ) { - return i; - } - if ( dim === 1 ) { - return j; - } - if ( dim === 2 ) { - return k; - } - return l; - - function i() { - arr.set( value, 0, 0, 0, 10.0 ); - } - - function j() { - arr.set( 0, value, 0, 0, 10.0 ); - } - - function k() { - arr.set( 0, 0, value, 0, 10.0 ); - } - - function l() { - arr.set( 0, 0, 0, value, 10.0 ); - } - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 0, 5.0 ); - arr.set( 0, 0, 0, 1, 6.0 ); - arr.set( 0, 0, 1, 0, 7.0 ); - arr.set( 0, 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; 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 = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 0, 5.0 ); - arr.set( 0, 0, 0, 1, 6.0 ); - arr.set( 0, 0, 1, 0, 7.0 ); - arr.set( 0, 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 6.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 2.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 6.0, 3.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; submode=[clamp,clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, -1, 0, 7.0 ); - arr.set( 0, 0, 5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 2.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw' ], - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; submode=[throw,throw,throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw', 'throw', 'throw', 'throw' ], - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 11, 6.0 ], - [ 0, 0, -1, 0, 7.0 ], - [ 0, 0, 5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; row-major; submode=[wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); // (0,0,0,1) - arr.set( 0, 0, 0, 11, 6.0 ); // (0,0,0,1) - arr.set( 0, 0, -1, 0, 7.0 ); // (0,0,1,0) - arr.set( 0, 0, 5, 5, 8.0 ); // (0,0,1,1) - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 6.0, 7.0, 8.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (4d; column-major; submode=[wrap,clamp,clamp,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'clamp', 'clamp', 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 5.0 ); // (0,0,1,0) - arr.set( 0, 0, 0, 11, 6.0 ); // (0,0,0,1) - arr.set( 0, 0, -1, 0, 7.0 ); // (0,0,0,0) - arr.set( 0, 0, 5, 5, 8.0 ); // (0,0,1,1) - - t.strictEqual( arr.get( 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 5.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.set_nd.js b/test/test.instance.set_nd.js deleted file mode 100644 index 12260de..0000000 --- a/test/test.instance.set_nd.js +++ /dev/null @@ -1,830 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a `set` method which throws an error if not provided an integer value for a dimension index (>4d)', function test( t ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - var i; - var j; - - dtype = 'float64'; - buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 2, 1, 1, 1, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - for ( j = 0; j < shape.length; j++ ) { - t.throws( badValue( values[ i ], j ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - } - t.end(); - - function badValue( value, dim ) { - return function badValue() { - var args = new Array( shape.length+1 ); - var i; - - for ( i = 0; i < shape.length; i++ ) { - if ( i === dim ) { - args[ i ] = value; - } else { - args[ i ] = 0; - } - } - args[ i ] = 10.0; - arr.set.apply( arr, args ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 0, 0, 5.0 ); - arr.set( 0, 0, 0, 0, 1, 6.0 ); - arr.set( 0, 0, 0, 1, 0, 7.0 ); - arr.set( 0, 0, 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; 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 = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - arr.set( 0, 0, 0, 0, 0, 5.0 ); - arr.set( 0, 0, 0, 0, 1, 6.0 ); - arr.set( 0, 0, 0, 1, 0, 7.0 ); - arr.set( 0, 0, 0, 1, 1, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; mode=wrap)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 3.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; mode=clamp)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 2.0, 8.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; mode=throw)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'mode': 'throw' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; mode=default)', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var arr; - var i; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; submode=[wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; submode=[wrap,wrap])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 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 constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; submode=[clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 3.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; submode=[clamp,clamp,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'clamp', 'clamp', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); - arr.set( 0, 0, 0, 0, 11, 6.0 ); - arr.set( 0, 0, 0, -1, -10, 7.0 ); - arr.set( 0, 0, 0, -5, 5, 8.0 ); - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 5.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 2.0, 8.0, 5.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; submode=[throw,throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw', 'throw' ], - 'mode': 'wrap' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; submode=[throw])', function test( t ) { - var strides; - var buffer; - var offset; - var values; - var dtype; - var order; - var shape; - var opts; - var arr; - var i; - - opts = { - 'submode': [ 'throw' ], - 'mode': 'clamp' - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - values = [ - [ 2, 2, 2, 2, 2, 5.0 ], - [ 0, 0, 0, 0, 11, 6.0 ], - [ 0, 0, 0, -1, -10, 7.0 ], - [ 0, 0, 0, -5, 5, 8.0 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided arguments: ' + values[ i ] ); - } - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 3.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 2.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 2.0, 3.0, 4.0 ], 'has expected values' ); - - t.end(); - - function badValue( value ) { - return function badValue() { - arr.set.apply( arr, value ); - }; - } -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; row-major; submode=[wrap,wrap,clamp,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'clamp', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'row-major'; - strides = [ 4, 4, 4, 2, 1 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); // (0,0,0,1,0) - arr.set( 0, 0, 0, 0, 11, 6.0 ); // (0,0,0,0,1) - arr.set( 0, 0, 0, -1, -10, 7.0 ); // (0,0,0,0,0) - arr.set( 0, 0, 0, -5, 5, 8.0 ); // (0,0,0,0,1) - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 8.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 5.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 4.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 7.0, 8.0, 5.0, 4.0 ], 'has expected values' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which has a `set` method for setting an array element using subscripts (>4d; column-major; submode=[wrap,wrap,wrap,wrap,clamp])', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var opts; - var arr; - - opts = { - 'submode': [ 'wrap', 'wrap', 'wrap', 'wrap', 'clamp' ] - }; - - dtype = 'generic'; - buffer = [ 1.0, 2.0, 3.0, 4.0 ]; - shape = [ 1, 1, 1, 2, 2 ]; - order = 'column-major'; - strides = [ 1, 1, 1, 1, 2 ]; - offset = 0; - - arr = ndarray( dtype, buffer, shape, strides, offset, order, opts ); - - arr.set( 2, 2, 2, 2, 2, 5.0 ); // (0,0,0,0,1) - arr.set( 0, 0, 0, 0, 11, 6.0 ); // (0,0,0,0,1) - arr.set( 0, 0, 0, -1, -10, 7.0 ); // (0,0,0,1,0) - arr.set( 0, 0, 0, -5, 5, 8.0 ); // (0,0,0,1,1) - - t.strictEqual( arr.get( 0, 0, 0, 0, 0 ), 1.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 0, 1 ), 6.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 0 ), 7.0, 'returns expected value' ); - t.strictEqual( arr.get( 0, 0, 0, 1, 1 ), 8.0, 'returns expected value' ); - - t.deepEqual( buffer, [ 1.0, 7.0, 6.0, 8.0 ], 'has expected values' ); - - t.end(); -}); diff --git a/test/test.instance.tojson.js b/test/test.instance.tojson.js deleted file mode 100644 index 10ab3a5..0000000 --- a/test/test.instance.tojson.js +++ /dev/null @@ -1,202 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 = 'column-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': 'column-major', - 'flags': { - 'READONLY': false - } - }; - actual = arr.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'an ndarray constructor returns an instance which 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(); -}); diff --git a/test/test.instance.tostring.js b/test/test.instance.tostring.js deleted file mode 100644 index 95eba28..0000000 --- a/test/test.instance.tostring.js +++ /dev/null @@ -1,309 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var hasProp = require( '@stdlib/assert-has-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var ndarray = require( './../lib' ); - - -// 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( 'an ndarray constructor returns an instance which has a custom `toString()` method (order=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 constructor returns an instance which has a custom `toString()` method (order=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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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'; - buffer = new Array( 1e4 ); - 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 constructor returns an instance which 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 constructor returns an instance which 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 constructor returns an instance which 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 = 'column-major'; - strides = [ 0 ]; - offset = 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( \'generic\', [ 2 ], [], [ 0 ], 0, \'column-major\' )'; - actual = arr.toString(); - t.strictEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5cdee94..0000000 --- a/test/test.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var ndarray = require( './../lib' ); - - -// 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 function is an ndarray constructor (complex dtype)', 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 = new ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the function is an ndarray constructor (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 = new ndarray( dtype, buffer, shape, strides, offset, order ); - - t.strictEqual( instanceOf( arr, ndarray ), true, 'returns an instance' ); - t.end(); -}); - -tape( 'the function is an ndarray constructor (0d; complex dtype)', function test( t ) { - var strides; - var buffer; - var offset; - var dtype; - var order; - var shape; - var arr; - - dtype = 'complex64'; - buffer = new Complex64Array( [ 1.0, 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( 'the function is an ndarray constructor (options)', 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 function is an ndarray constructor (0d; options)', 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( '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 constructor does not require the `new` keyword (options)', 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(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 3954beb..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,203 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unrecognized/unsupported `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 'clamped', - 'error', - 'err', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `submode` option which is not an array containing recognized/supported modes', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'wraps', - 'clamps', - 'clip', - 'clamped', - 'error', - 'err', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'throw', 'wrap', 'clamp', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'submode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'readonly': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'submode': [ 'throw', 'wrap', 'clamp' ], - 'readonly': true - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -});