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 c828539..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:10:05.099Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..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/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/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 c9faa1b..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/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 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 b7f0018..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: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # 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 + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +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.array.""" - -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 = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - 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 10cb019..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/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/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 fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 313751c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArrayLikeObject;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar settings = require( '@stdlib/ndarray-defaults' );\n\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'casting': settings.get( 'casting' ),\n\t\t'copy': false,\n\t\t'dtype': settings.get( 'dtypes.default' ),\n\t\t'flatten': true,\n\t\t'mode': settings.get( 'index_mode' ),\n\t\t'ndmin': 0,\n\t\t'order': settings.get( 'order' ),\n\t\t'readonly': false\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\n\n\n// MAIN //\n\n/**\n* Casts buffer elements by copying those elements to a buffer of another data type.\n*\n* @private\n* @param {(Array|TypedArray|Buffer)} buffer - input buffer\n* @param {NonNegativeInteger} len - number of elements to cast\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output buffer\n*\n* @example\n* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' );\n* // returns [ 1.0, 2.0, 3.0 ]\n*/\nfunction castBuffer( buffer, len, dtype ) {\n\tvar ctor;\n\tvar out;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tif ( dtype === 'generic' ) {\n\t\tout = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.push( buffer[ i ] );\n\t\t}\n\t} else if ( dtype === 'binary' ) {\n\t\tout = allocUnsafe( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ];\n\t\t}\n\t} else {\n\t\tout = new ctor( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = castBuffer;\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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar castReturn = require( '@stdlib/complex-base-cast-return' );\nvar complexCtors = require( '@stdlib/complex-ctors' );\nvar bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );\nvar allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getStrides = require( '@stdlib/ndarray-strides' );\nvar getOffset = require( '@stdlib/ndarray-offset' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getData = require( '@stdlib/ndarray-data-buffer' );\n\n\n// FUNCTIONS //\n\n/**\n* Copies a \"generic\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction generic( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"binary\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction binary( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = allocUnsafe( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a \"binary\" ndarray or a double-precision floating-point ndarray to binary, etc)\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"typed\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {Array} output data buffer\n*/\nfunction typed( arr, dtype ) {\n\tvar ctor;\n\tvar len;\n\tvar out;\n\tvar set;\n\tvar fcn;\n\tvar o;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tlen = arr.length;\n\tout = new ctor( len );\n\n\t// If the output data buffer is a complex number array, we need to use accessors...\n\to = arraylike2object( out );\n\tif ( o.accessorProtocol ) {\n\t\tset = o.accessors[ 1 ];\n\t\tfcn = castReturn( wrapper, 1, complexCtors( dtype ) );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tset( out, i, fcn( i ) ); // we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc)\n\t\t}\n\t} else {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc)\n\t\t}\n\t}\n\treturn out;\n\n\t/**\n\t* Returns the ndarray element specified by a provided linear index.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} i - linear index\n\t* @returns {*} value\n\t*/\n\tfunction wrapper( i ) {\n\t\treturn arr.iget( i );\n\t}\n}\n\n\n// MAIN //\n\n/**\n* Copies an ndarray view to a data buffer.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output data buffer\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n*\n* var buffer = [ 1.0, 2.0, 3.0 ];\n* var shape = [ 3 ];\n* var strides = [ -1 ];\n* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' );\n*\n* var b = copyView( vec, 'float64' );\n* // returns [ 3.0, 2.0, 1.0 ]\n*/\nfunction copyView( arr, dtype ) {\n\tvar x;\n\n\t// Create a new \"base\" view, thus ensuring we have an `.iget` method and associated meta data...\n\tx = new ndarray( getDType( arr ), getData( arr ), getShape( arr ), getStrides( arr ), getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n\n\tif ( dtype === 'generic' ) {\n\t\treturn generic( x );\n\t}\n\tif ( dtype === 'binary' ) {\n\t\treturn binary( x );\n\t}\n\treturn typed( x, dtype );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyView;\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* Prepends singleton dimensions in order to satisfy a minimum number of dimensions.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - array dimensions\n* @param {NonNegativeInteger} ndmin - minimum number of dimensions\n* @returns {Array} output shape array\n*/\nfunction expandShape( ndims, shape, ndmin ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < ndmin-ndims; i++ ) {\n\t\tout.push( 1 );\n\t}\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tout.push( shape[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandShape;\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 isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' );\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions).\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - expanded array shape\n* @param {Array} strides - strides array\n* @param {string} order - memory layout order\n* @returns {Array} output strides array\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' );\n* // returns [ 1, 1, 1, 2 ]\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' );\n* // returns [ 4, 4, 2, 1 ]\n*/\nfunction expandStrides( ndims, shape, strides, order ) {\n\tvar out;\n\tvar N;\n\tvar s;\n\tvar i;\n\tvar j;\n\n\tN = strides.length;\n\tj = ndims - N;\n\tout = [];\n\tif ( isRowMajor( order ) ) {\n\t\ts = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( s );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t} else { // column-major\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( 1 );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = expandStrides;\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 hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar shape2strides = require( '@stdlib/ndarray-base-shape2strides' );\nvar strides2offset = require( '@stdlib/ndarray-base-strides2offset' );\nvar strides2order = require( '@stdlib/ndarray-base-strides2order' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndarray = require( '@stdlib/ndarray-ctor' );\nvar isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' );\nvar isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' );\nvar isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' );\nvar createBuffer = require( '@stdlib/ndarray-base-buffer' );\nvar getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar getDType = require( '@stdlib/ndarray-dtype' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar getStrides = require( '@stdlib/ndarray-strides' );\nvar getOffset = require( '@stdlib/ndarray-offset' );\nvar getOrder = require( '@stdlib/ndarray-order' );\nvar getData = require( '@stdlib/ndarray-data-buffer' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flatten = require( '@stdlib/array-base-flatten' );\nvar format = require( '@stdlib/string-format' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar getDefaults = require( './defaults.js' );\nvar castBuffer = require( './cast_buffer.js' );\nvar copyView = require( './copy_view.js' );\nvar expandShape = require( './expand_shape.js' );\nvar expandStrides = require( './expand_strides.js' );\n\n\n// VARIABLES //\n\nvar defaults = getDefaults();\n\n\n// MAIN //\n\n/**\n* Returns a multidimensional array.\n*\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source\n* @param {Options} [options] - function options\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source\n* @param {string} [options.dtype=\"float64\"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)\n* @param {string} [options.order=\"row-major\"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style)\n* @param {NonNegativeIntegerArray} [options.shape] - array shape\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.copy=false] - boolean indicating whether to copy source data to a new data buffer\n* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources\n* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions\n* @param {string} [options.casting=\"safe\"] - casting rule used to determine what constitutes an acceptable cast\n* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide either an array shape, data source, or both\n* @throws {Error} invalid cast\n* @throws {RangeError} data source must be compatible with specified meta data\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\nfunction array() {\n\tvar options;\n\tvar strides;\n\tvar buffer;\n\tvar offset;\n\tvar order;\n\tvar dtype;\n\tvar btype;\n\tvar shape;\n\tvar ndims;\n\tvar nopts;\n\tvar opts;\n\tvar osh;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\n\tif ( arguments.length === 1 ) {\n\t\tif ( isArrayLikeObject( arguments[ 0 ] ) ) {\n\t\t\tbuffer = arguments[ 0 ];\n\t\t\toptions = {};\n\t\t} else {\n\t\t\toptions = arguments[ 0 ];\n\t\t\tif ( !isObject( options ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( options, 'buffer' ) ) {\n\t\t\t\tbuffer = options.buffer;\n\t\t\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tbuffer = arguments[ 0 ];\n\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\t// Note: we ignore whether `options` has a `buffer` property\n\t}\n\tif ( buffer ) {\n\t\tif ( isndarrayLike( buffer ) ) {\n\t\t\tbtype = getDType( buffer );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getBufferDType( buffer ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\n\t\t\tFLG = false;\n\t\t}\n\t}\n\tnopts = {};\n\topts = {};\n\n\t// Validate some options before others...\n\tif ( hasOwnProp( options, 'casting' ) ) {\n\t\topts.casting = options.casting;\n\t\tif ( !isCastingMode( opts.casting ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) );\n\t\t}\n\t} else {\n\t\topts.casting = defaults.casting;\n\t}\n\tif ( hasOwnProp( options, 'flatten' ) ) {\n\t\topts.flatten = options.flatten;\n\t\tif ( !isBoolean( opts.flatten ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) );\n\t\t}\n\t} else {\n\t\topts.flatten = defaults.flatten;\n\t}\n\tif ( hasOwnProp( options, 'ndmin' ) ) {\n\t\topts.ndmin = options.ndmin;\n\t\tif ( !isNonNegativeInteger( opts.ndmin ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) );\n\t\t}\n\t\t// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)\n\t} else {\n\t\topts.ndmin = defaults.ndmin;\n\t}\n\n\t// Validate the remaining options...\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\tdtype = options.dtype;\n\t\tif ( !isDataType( dtype ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\n\t\t// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.\n\n\t\t// Only cast generic array data sources when not provided an ndarray...\n\t\tif ( !FLG && btype === 'generic' ) {\n\t\t\tdtype = defaults.dtype;\n\t\t} else {\n\t\t\tdtype = btype;\n\t\t}\n\t} else {\n\t\tdtype = defaults.dtype;\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\torder = options.order;\n\t\tif ( order === 'any' || order === 'same' ) {\n\t\t\tif ( FLG ) {\n\t\t\t\t// If the user indicated that \"any\" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally \"row-major\" or \"column-major\" or configured as such....\n\t\t\t\tif ( order === 'any' ) {\n\t\t\t\t\t// Compute the layout order in order to ascertain whether an ndarray can be considered both \"row-major\" and \"column-major\":\n\t\t\t\t\tord = strides2order( getStrides( buffer ) );\n\n\t\t\t\t\t// If the ndarray can be considered both \"row-major\" and \"column-major\", then use the default order; otherwise, use the ndarray's stated layout order...\n\t\t\t\t\tif ( ord === 3 ) {\n\t\t\t\t\t\torder = defaults.order;\n\t\t\t\t\t} else {\n\t\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise, use the same order as the provided ndarray...\n\t\t\t\telse if ( order === 'same' ) {\n\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\torder = defaults.order;\n\t\t\t}\n\t\t} else if ( !isOrder( order ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) );\n\t\t}\n\t} else {\n\t\torder = defaults.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\tnopts.mode = options.mode;\n\t} else {\n\t\tnopts.mode = defaults.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\tnopts.submode = options.submode;\n\t} else {\n\t\tnopts.submode = [ nopts.mode ];\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\tnopts.readonly = options.readonly;\n\t} else {\n\t\tnopts.readonly = defaults.readonly;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\n\t\tif ( !isBoolean( opts.copy ) ) {\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) );\n\t\t}\n\t} else {\n\t\topts.copy = defaults.copy;\n\t}\n\t// If not provided a shape, infer from a provided data source...\n\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\tshape = options.shape;\n\t\tif ( !isArrayLikeObject( shape ) ) { // weak test\n\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) );\n\t\t}\n\t\tndims = shape.length;\n\t\tlen = numel( shape );\n\t} else if ( buffer ) {\n\t\tif ( FLG ) {\n\t\t\tshape = getShape( buffer );\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\n\t\t\tosh = shape; // cache a reference to the inferred shape\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else {\n\t\t\tndims = 1;\n\t\t\tlen = buffer.length;\n\t\t\tshape = [ len ]; // assume a 1-dimensional array (vector)\n\t\t}\n\t} else {\n\t\tthrow new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' );\n\t}\n\t// Adjust the array shape to satisfy the minimum number of dimensions...\n\tif ( ndims < opts.ndmin ) {\n\t\tshape = expandShape( ndims, shape, opts.ndmin );\n\t\tndims = opts.ndmin;\n\t}\n\t// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...\n\tif ( FLG ) {\n\t\tif ( numel( buffer.shape ) !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = getStrides( buffer );\n\t\t\toffset = getOffset( buffer );\n\t\t\tbuffer = getData( buffer );\n\t\t\tif ( strides.length < ndims ) {\n\t\t\t\t// Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset):\n\t\t\t\tstrides = expandStrides( ndims, shape, strides, order );\n\t\t\t}\n\t\t}\n\t} else if ( buffer ) {\n\t\tif ( btype === 'generic' && opts.flatten && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = castBuffer( buffer, len, dtype );\n\t\t}\n\t} else {\n\t\tbuffer = createBuffer( dtype, len );\n\t}\n\t// If we have yet to determine array strides, we assume that we can compute the strides, along with the index offset, for a **contiguous** data source based solely on the array shape and specified memory layout order...\n\tif ( strides === void 0 ) {\n\t\tstrides = shape2strides( shape, order );\n\t\toffset = strides2offset( shape, strides );\n\t}\n\treturn new ndarray( dtype, buffer, shape, strides, offset, order, nopts );\n}\n\n\n// EXPORTS //\n\nmodule.exports = array;\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.\n*\n* @module @stdlib/ndarray-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\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,cAsBA,IAAIC,EAAO,QAAS,gCAAiC,EACjDC,EAAY,QAAS,qCAAsC,EAoB/D,SAASC,EAAmBC,EAAQ,CACnC,OACC,OAAOA,GAAU,UACjBA,IAAU,MACV,OAAOA,EAAM,QAAW,UACxBF,EAAWE,EAAM,MAAO,GACxBA,EAAM,QAAU,GAChBA,EAAM,OAASH,CAEjB,CAKAD,EAAO,QAAUG,ICzDjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,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C,EAAON,CAAQ,GAElC,IAAI1B,GAAS8B,EAAOH,EAAQK,EAAON,EAASE,EAAQC,EAAOK,CAAM,CACzE,CAKA7C,EAAO,QAAUmC,KCzRjB,IAAIgB,GAAO,IAKX,OAAO,QAAUA", - "names": ["require_is_array_like_object", "__commonJSMin", "exports", "module", "PINF", "isInteger", "isArrayLikeObject", "value", "require_defaults", "__commonJSMin", "exports", "module", "settings", "defaults", "require_cast_buffer", "__commonJSMin", "exports", "module", "bufferCtors", "allocUnsafe", "castBuffer", "buffer", "len", "dtype", "ctor", "out", "i", "require_copy_view", "__commonJSMin", "exports", "module", "arraylike2object", "castReturn", "complexCtors", "bufferCtors", "allocUnsafe", "ndarray", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "generic", "arr", "len", "out", "i", "binary", "typed", "dtype", "ctor", "set", "fcn", "o", "wrapper", "copyView", "x", "require_expand_shape", "__commonJSMin", "exports", "module", "expandShape", "ndims", "shape", "ndmin", "out", "require_expand_strides", "__commonJSMin", "exports", "module", "isRowMajor", "abs", "expandStrides", "ndims", "shape", "strides", "order", "out", "N", "s", "i", "j", "require_main", "__commonJSMin", "exports", "module", "hasOwnProp", "isObject", "isBoolean", "isArray", "isNonNegativeInteger", "isndarrayLike", "shape2strides", "strides2offset", "strides2order", "numel", "ndarray", "isColumnMajor", "isDataType", "isOrder", "isCastingMode", "isAllowedCast", "createBuffer", "getBufferDType", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "arrayShape", "flatten", "format", "isArrayLikeObject", "getDefaults", "castBuffer", "copyView", "expandShape", "expandStrides", "defaults", "array", "options", "strides", "buffer", "offset", "order", "dtype", "btype", "shape", "ndims", "nopts", "opts", "osh", "len", "ord", "FLG", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - '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. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - '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 - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // 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 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +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 array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( 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 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( 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 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// 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() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..50585b7 --- /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/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function F(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&R(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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 arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\n\n\n// FUNCTIONS //\n\n/**\n* Copies a \"generic\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction generic( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = [];\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"binary\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @returns {Array} output data buffer\n*/\nfunction binary( arr ) {\n\tvar len;\n\tvar out;\n\tvar i;\n\n\tlen = arr.length;\n\tout = allocUnsafe( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a \"binary\" ndarray or a double-precision floating-point ndarray to binary, etc)\n\t}\n\treturn out;\n}\n\n/**\n* Copies a \"typed\" ndarray view.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {Array} output data buffer\n*/\nfunction typed( arr, dtype ) {\n\tvar ctor;\n\tvar len;\n\tvar out;\n\tvar set;\n\tvar fcn;\n\tvar o;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tlen = arr.length;\n\tout = new ctor( len );\n\n\t// If the output data buffer is a complex number array, we need to use accessors...\n\to = arraylike2object( out );\n\tif ( o.accessorProtocol ) {\n\t\tset = o.accessors[ 1 ];\n\t\tfcn = castReturn( wrapper, 1, complexCtors( dtype ) );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tset( out, i, fcn( i ) ); // we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc)\n\t\t}\n\t} else {\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc)\n\t\t}\n\t}\n\treturn out;\n\n\t/**\n\t* Returns the ndarray element specified by a provided linear index.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} i - linear index\n\t* @returns {*} value\n\t*/\n\tfunction wrapper( i ) {\n\t\treturn arr.iget( i );\n\t}\n}\n\n\n// MAIN //\n\n/**\n* Copies an ndarray view to a data buffer.\n*\n* @private\n* @param {ndarray} arr - input ndarray\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output data buffer\n*\n* @example\n* import ndarray from '@stdlib/ndarray-ctor';\n*\n* var buffer = [ 1.0, 2.0, 3.0 ];\n* var shape = [ 3 ];\n* var strides = [ -1 ];\n* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' );\n*\n* var b = copyView( vec, 'float64' );\n* // returns [ 3.0, 2.0, 1.0 ]\n*/\nfunction copyView( arr, dtype ) {\n\tvar x;\n\n\t// Create a new \"base\" view, thus ensuring we have an `.iget` method and associated meta data...\n\tx = new ndarray( getDType( arr ), getData( arr ), getShape( arr ), getStrides( arr ), getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n\n\tif ( dtype === 'generic' ) {\n\t\treturn generic( x );\n\t}\n\tif ( dtype === 'binary' ) {\n\t\treturn binary( x );\n\t}\n\treturn typed( x, dtype );\n}\n\n\n// EXPORTS //\n\nexport default copyView;\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 hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './expand_strides.js';\n\n\n// VARIABLES //\n\nvar defaults = getDefaults();\n\n\n// MAIN //\n\n/**\n* Returns a multidimensional array.\n*\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source\n* @param {Options} [options] - function options\n* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source\n* @param {string} [options.dtype=\"float64\"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data)\n* @param {string} [options.order=\"row-major\"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style)\n* @param {NonNegativeIntegerArray} [options.shape] - array shape\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.copy=false] - boolean indicating whether to copy source data to a new data buffer\n* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources\n* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions\n* @param {string} [options.casting=\"safe\"] - casting rule used to determine what constitutes an acceptable cast\n* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide either an array shape, data source, or both\n* @throws {Error} invalid cast\n* @throws {RangeError} data source must be compatible with specified meta data\n* @returns {ndarray} ndarray instance\n*\n* @example\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1\n*\n* @example\n* var opts = {\n* 'dtype': 'generic',\n* 'flatten': false\n* };\n*\n* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );\n* // returns \n*\n* var v = arr.get( 0 );\n* // returns [ 1, 2 ]\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n*\n* var opts = {\n* 'shape': [ 2, 2 ]\n* };\n*\n* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );\n* // returns \n*\n* var v = arr.get( 0, 0 );\n* // returns 1.0\n*/\nfunction array() {\n\tvar options;\n\tvar strides;\n\tvar buffer;\n\tvar offset;\n\tvar order;\n\tvar dtype;\n\tvar btype;\n\tvar shape;\n\tvar ndims;\n\tvar nopts;\n\tvar opts;\n\tvar osh;\n\tvar len;\n\tvar ord;\n\tvar FLG;\n\n\tif ( arguments.length === 1 ) {\n\t\tif ( isArrayLikeObject( arguments[ 0 ] ) ) {\n\t\t\tbuffer = arguments[ 0 ];\n\t\t\toptions = {};\n\t\t} else {\n\t\t\toptions = arguments[ 0 ];\n\t\t\tif ( !isObject( options ) ) {\n\t\t\t\tthrow new TypeError( format( '0hT56', options ) );\n\t\t\t}\n\t\t\tif ( hasOwnProp( options, 'buffer' ) ) {\n\t\t\t\tbuffer = options.buffer;\n\t\t\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\t\t\tthrow new TypeError( format( '0hT57', 'buffer', buffer ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tbuffer = arguments[ 0 ];\n\t\tif ( !isArrayLikeObject( buffer ) ) { // weak test\n\t\t\tthrow new TypeError( format( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', options ) );\n\t\t}\n\t\t// Note: we ignore whether `options` has a `buffer` property\n\t}\n\tif ( buffer ) {\n\t\tif ( isndarrayLike( buffer ) ) {\n\t\t\tbtype = getDType( buffer );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getBufferDType( buffer ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\n\t\t\tFLG = false;\n\t\t}\n\t}\n\tnopts = {};\n\topts = {};\n\n\t// Validate some options before others...\n\tif ( hasOwnProp( options, 'casting' ) ) {\n\t\topts.casting = options.casting;\n\t\tif ( !isCastingMode( opts.casting ) ) {\n\t\t\tthrow new TypeError( format( '0hT59', 'casting', opts.casting ) );\n\t\t}\n\t} else {\n\t\topts.casting = defaults.casting;\n\t}\n\tif ( hasOwnProp( options, 'flatten' ) ) {\n\t\topts.flatten = options.flatten;\n\t\tif ( !isBoolean( opts.flatten ) ) {\n\t\t\tthrow new TypeError( format( '0hT2o', 'flatten', opts.flatten ) );\n\t\t}\n\t} else {\n\t\topts.flatten = defaults.flatten;\n\t}\n\tif ( hasOwnProp( options, 'ndmin' ) ) {\n\t\topts.ndmin = options.ndmin;\n\t\tif ( !isNonNegativeInteger( opts.ndmin ) ) {\n\t\t\tthrow new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) );\n\t\t}\n\t\t// TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57)\n\t} else {\n\t\topts.ndmin = defaults.ndmin;\n\t}\n\n\t// Validate the remaining options...\n\tif ( hasOwnProp( options, 'dtype' ) ) {\n\t\tdtype = options.dtype;\n\t\tif ( !isDataType( dtype ) ) {\n\t\t\tthrow new TypeError( format( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\n\t\t// TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option.\n\n\t\t// Only cast generic array data sources when not provided an ndarray...\n\t\tif ( !FLG && btype === 'generic' ) {\n\t\t\tdtype = defaults.dtype;\n\t\t} else {\n\t\t\tdtype = btype;\n\t\t}\n\t} else {\n\t\tdtype = defaults.dtype;\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\torder = options.order;\n\t\tif ( order === 'any' || order === 'same' ) {\n\t\t\tif ( FLG ) {\n\t\t\t\t// If the user indicated that \"any\" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally \"row-major\" or \"column-major\" or configured as such....\n\t\t\t\tif ( order === 'any' ) {\n\t\t\t\t\t// Compute the layout order in order to ascertain whether an ndarray can be considered both \"row-major\" and \"column-major\":\n\t\t\t\t\tord = strides2order( getStrides( buffer ) );\n\n\t\t\t\t\t// If the ndarray can be considered both \"row-major\" and \"column-major\", then use the default order; otherwise, use the ndarray's stated layout order...\n\t\t\t\t\tif ( ord === 3 ) {\n\t\t\t\t\t\torder = defaults.order;\n\t\t\t\t\t} else {\n\t\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Otherwise, use the same order as the provided ndarray...\n\t\t\t\telse if ( order === 'same' ) {\n\t\t\t\t\torder = getOrder( buffer );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\torder = defaults.order;\n\t\t\t}\n\t\t} else if ( !isOrder( order ) ) {\n\t\t\tthrow new TypeError( format( '0hT5C', 'order', order ) );\n\t\t}\n\t} else {\n\t\torder = defaults.order;\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\tnopts.mode = options.mode;\n\t} else {\n\t\tnopts.mode = defaults.mode;\n\t}\n\tif ( hasOwnProp( options, 'submode' ) ) {\n\t\tnopts.submode = options.submode;\n\t} else {\n\t\tnopts.submode = [ nopts.mode ];\n\t}\n\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\tnopts.readonly = options.readonly;\n\t} else {\n\t\tnopts.readonly = defaults.readonly;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\n\t\tif ( !isBoolean( opts.copy ) ) {\n\t\t\tthrow new TypeError( format( '0hT2o', 'copy', opts.copy ) );\n\t\t}\n\t} else {\n\t\topts.copy = defaults.copy;\n\t}\n\t// If not provided a shape, infer from a provided data source...\n\tif ( hasOwnProp( options, 'shape' ) ) {\n\t\tshape = options.shape;\n\t\tif ( !isArrayLikeObject( shape ) ) { // weak test\n\t\t\tthrow new TypeError( format( '0hT5D', 'shape', shape ) );\n\t\t}\n\t\tndims = shape.length;\n\t\tlen = numel( shape );\n\t} else if ( buffer ) {\n\t\tif ( FLG ) {\n\t\t\tshape = getShape( buffer );\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\n\t\t\tosh = shape; // cache a reference to the inferred shape\n\t\t\tndims = shape.length;\n\t\t\tlen = numel( shape );\n\t\t} else {\n\t\t\tndims = 1;\n\t\t\tlen = buffer.length;\n\t\t\tshape = [ len ]; // assume a 1-dimensional array (vector)\n\t\t}\n\t} else {\n\t\tthrow new Error( format('0hT0X') );\n\t}\n\t// Adjust the array shape to satisfy the minimum number of dimensions...\n\tif ( ndims < opts.ndmin ) {\n\t\tshape = expandShape( ndims, shape, opts.ndmin );\n\t\tndims = opts.ndmin;\n\t}\n\t// If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy...\n\tif ( FLG ) {\n\t\tif ( numel( buffer.shape ) !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = getStrides( buffer );\n\t\t\toffset = getOffset( buffer );\n\t\t\tbuffer = getData( buffer );\n\t\t\tif ( strides.length < ndims ) {\n\t\t\t\t// Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset):\n\t\t\t\tstrides = expandStrides( ndims, shape, strides, order );\n\t\t\t}\n\t\t}\n\t} else if ( buffer ) {\n\t\tif ( btype === 'generic' && opts.flatten && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\n\t\t}\n\t\tif ( btype !== dtype || opts.copy ) {\n\t\t\tbuffer = castBuffer( buffer, len, dtype );\n\t\t}\n\t} else {\n\t\tbuffer = createBuffer( dtype, len );\n\t}\n\t// If we have yet to determine array strides, we assume that we can compute the strides, along with the index offset, for a **contiguous** data source based solely on the array shape and specified memory layout order...\n\tif ( strides === void 0 ) {\n\t\tstrides = shape2strides( shape, order );\n\t\toffset = strides2offset( shape, strides );\n\t}\n\treturn new ndarray( dtype, buffer, shape, strides, offset, order, nopts );\n}\n\n\n// EXPORTS //\n\nexport default array;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport settings from '@stdlib/ndarray-defaults';\n\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'casting': settings.get( 'casting' ),\n\t\t'copy': false,\n\t\t'dtype': settings.get( 'dtypes.default' ),\n\t\t'flatten': true,\n\t\t'mode': settings.get( 'index_mode' ),\n\t\t'ndmin': 0,\n\t\t'order': settings.get( 'order' ),\n\t\t'readonly': false\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Prepends singleton dimensions in order to satisfy a minimum number of dimensions.\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - array dimensions\n* @param {NonNegativeInteger} ndmin - minimum number of dimensions\n* @returns {Array} output shape array\n*/\nfunction expandShape( ndims, shape, ndmin ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < ndmin-ndims; i++ ) {\n\t\tout.push( 1 );\n\t}\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tout.push( shape[ i ] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default expandShape;\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 isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport abs from '@stdlib/math-base-special-abs';\n\n\n// MAIN //\n\n/**\n* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions).\n*\n* @private\n* @param {NonNegativeInteger} ndims - number of dimensions\n* @param {Array} shape - expanded array shape\n* @param {Array} strides - strides array\n* @param {string} order - memory layout order\n* @returns {Array} output strides array\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' );\n* // returns [ 1, 1, 1, 2 ]\n*\n* @example\n* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' );\n* // returns [ 4, 4, 2, 1 ]\n*/\nfunction expandStrides( ndims, shape, strides, order ) {\n\tvar out;\n\tvar N;\n\tvar s;\n\tvar i;\n\tvar j;\n\n\tN = strides.length;\n\tj = ndims - N;\n\tout = [];\n\tif ( isRowMajor( order ) ) {\n\t\ts = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( s );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t} else { // column-major\n\t\tfor ( i = 0; i < j; i++ ) {\n\t\t\tout.push( 1 );\n\t\t}\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( strides[ i ] );\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default expandStrides;\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 bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\n\n\n// MAIN //\n\n/**\n* Casts buffer elements by copying those elements to a buffer of another data type.\n*\n* @private\n* @param {(Array|TypedArray|Buffer)} buffer - input buffer\n* @param {NonNegativeInteger} len - number of elements to cast\n* @param {string} dtype - data type\n* @returns {(Array|TypedArray|Buffer)} output buffer\n*\n* @example\n* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' );\n* // returns [ 1.0, 2.0, 3.0 ]\n*/\nfunction castBuffer( buffer, len, dtype ) {\n\tvar ctor;\n\tvar out;\n\tvar i;\n\n\tctor = bufferCtors( dtype );\n\tif ( dtype === 'generic' ) {\n\t\tout = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout.push( buffer[ i ] );\n\t\t}\n\t} else if ( dtype === 'binary' ) {\n\t\tout = allocUnsafe( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ];\n\t\t}\n\t} else {\n\t\tout = new ctor( len );\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tout[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","isRowMajor","abs","expandStrides","isColumnMajor","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":";;qoHA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,CCgGA,SAASC,EAAUC,EAAKC,GACvB,IAAIC,EAKJ,OAFAA,EAAI,IAAIC,EAASC,EAAUJ,GAAOK,EAASL,GAAOM,EAAUN,GAAOO,EAAYP,GAAOQ,EAAWR,GAAOS,EAAUT,IAEnG,YAAVC,EA7GN,SAAkBD,GACjB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAMb,EAAIc,KAAMF,IAErB,OAAOD,CACR,CAmGSI,CAASb,GAEF,WAAVD,EA5FN,SAAiBD,GAChB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAMK,EAAaN,GACbE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAMZ,EAAIc,KAAMF,GAEtB,OAAOD,CACR,CAkFSM,CAAQf,GAxEjB,SAAgBF,EAAKC,GACpB,IACIS,EACAC,EACAO,EACAC,EACAC,EACAR,EAQJ,GAJAD,EAAM,IAFCU,EAAapB,GAEd,CADNS,EAAMV,EAAIJ,SAIVwB,EAAIE,EAAkBX,IACfY,iBAGN,IAFAL,EAAME,EAAEI,UAAW,GACnBL,EAAMM,GAkBP,SAAkBb,GACjB,OAAOZ,EAAIc,KAAMF,EACjB,GApB2B,EAAGc,EAAczB,IACtCW,EAAI,EAAGA,EAAIF,EAAKE,IACrBM,EAAKP,EAAKC,EAAGO,EAAKP,SAGnB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AAOS,GAO/B,YAJiB,IAAZ8B,IACJA,EAAUyC,EAAerC,EAAOR,GAChCM,EAASwC,EAAgBtC,EAAOJ,IAE1B,IAAIrC,EAASF,EAAOwC,EAAQG,EAAOJ,EAASE,EAAQN,EAAOU,EACnE"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var castReturn = require( '@stdlib/complex-base-cast-return' ); -var complexCtors = require( '@stdlib/complex-ctors' ); -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - var set; - var fcn; - var o; - var i; - - ctor = bufferCtors( dtype ); - len = arr.length; - out = new ctor( len ); - - // If the output data buffer is a complex number array, we need to use accessors... - o = arraylike2object( out ); - if ( o.accessorProtocol ) { - set = o.accessors[ 1 ]; - fcn = castReturn( wrapper, 1, complexCtors( dtype ) ); - for ( i = 0; i < len; i++ ) { - set( out, i, fcn( i ) ); // we're assuming that we're doing something sensible here (e.g., not trying to cast arbitrary objects to complex numbers, etc) - } - } else { - for ( i = 0; i < len; i++ ) { - out[ i ] = arr.iget( i ); // we're assuming that we're doing something sensible here (e.g., not trying to cast an ndarray containing generic objects to a double-precision floating-point array or a complex-valued ndarray to a real-valued ndarray, etc) - } - } - return out; - - /** - * Returns the ndarray element specified by a provided linear index. - * - * @private - * @param {NonNegativeInteger} i - linear index - * @returns {*} value - */ - function wrapper( i ) { - return arr.iget( i ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - var x; - - // Create a new "base" view, thus ensuring we have an `.iget` method and associated meta data... - x = new ndarray( getDType( arr ), getData( arr ), getShape( arr ), getStrides( arr ), getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len - - if ( dtype === 'generic' ) { - return generic( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +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 settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index 5b7cd5e..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( isRowMajor( order ) ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8d596c5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,347 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var getStrides = require( '@stdlib/ndarray-strides' ); -var getOffset = require( '@stdlib/ndarray-offset' ); -var getOrder = require( '@stdlib/ndarray-order' ); -var getData = require( '@stdlib/ndarray-data-buffer' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @param {string} [options.dtype="float64"] - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @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.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object, typed-array-like, a Buffer, or an ndarray. Option: `%s`.', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // TODO: validate that minimum number of dimensions does not exceed the maximum number of possible dimensions (in theory, infinite; in practice, determined by max array length; see https://github.com/stdlib-js/stdlib/blob/ac350059877c036640775d6b30d0e98e840d07cf/lib/node_modules/%40stdlib/ndarray/ctor/lib/main.js#L57) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // TODO: reconcile difference in behavior when provided a generic array and no `dtype` option. Currently, we cast here, but do not allow casting a generic array (by default) when explicitly providing a `dtype` option. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // If the user indicated that "any" order suffices (meaning the user does not care about ndarray order), then we use the default order, unless the input ndarray is either unequivocally "row-major" or "column-major" or configured as such.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // If the ndarray can be considered both "row-major" and "column-major", then use the default order; otherwise, use the ndarray's stated layout order... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // If not provided a data buffer, create it; otherwise, see if we need to cast a provided data buffer to another data type or perform a copy... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // If we have yet to determine array strides, we assume that we can compute the strides, along with the index offset, for a **contiguous** data source based solely on the array shape and specified memory layout order... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 44992cf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,70 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-row-major-string": "github:stdlib-js/ndarray-base-assert-is-row-major-string#main", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "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", @@ -116,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5392f02 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 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 = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests