From f2f9b872f116a11ed709e6a0c578a92bfabfefa2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 10:53:42 +0000 Subject: [PATCH 01/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 83351a0..19d22ac 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 54f8732a1bafcbaf4e23bf2d61984ddef167afe5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 10:58:20 +0000 Subject: [PATCH 02/48] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 125 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4911 insertions(+), 9495 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ee77ff5..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/index) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 + + ```
@@ -620,7 +617,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -685,15 +682,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b860aa6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/utils-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 12325b7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d78aaeb..59e586a 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9742fa8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d741238 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index c1303ac..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6ab0637..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'unit8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 19d22ac..53679f0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..43a47cb --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 90a5191c535c62726f3600153b55631db1452100 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:29:02 +0000 Subject: [PATCH 03/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 83351a0..19d22ac 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 0e39da9a91c96f590303aca945e6a0340e3fb7aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:13:11 +0000 Subject: [PATCH 04/48] Remove files --- index.d.ts | 718 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5565 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 59e586a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,718 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9742fa8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d741238..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 43a47cb..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 93e1718dcc4b4259c2e689f6b88960bb7fa69042 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:13:48 +0000 Subject: [PATCH 05/48] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 125 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4911 insertions(+), 9496 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = 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 1ceb9dd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:14:33.566Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ee77ff5..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/index) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 + + ```
@@ -620,7 +617,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -685,15 +682,15 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b860aa6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/utils-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 12325b7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d78aaeb..59e586a 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9742fa8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d741238 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index c1303ac..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6ab0637..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'unit8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 19d22ac..53679f0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..43a47cb --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 64d099c654e79ac47823acd5d882b43fa706dd19 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:46:20 +0000 Subject: [PATCH 06/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 83351a0..19d22ac 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 113239e41f518dba7597d18d9d7aa05552f16114 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:47:38 +0000 Subject: [PATCH 07/48] Remove files --- index.d.ts | 718 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5565 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 59e586a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,718 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9742fa8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d741238..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'unit8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 43a47cb..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2017dfed7e5bbc2d851dad2bc2ea2ee5c3b63da1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:47:59 +0000 Subject: [PATCH 08/48] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 51 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 125 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4911 insertions(+), 9496 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ee77ff5..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/index) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 + + ```
@@ -620,7 +617,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -685,15 +682,15 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b860aa6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/utils-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7a6c98b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d78aaeb..59e586a 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..03c671c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@esm/index.mjs";var v=["linear","cartesian"],y=m(v);var c=new f;function j(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var b=-1;function g(t){var h,m,f,j,w,x;if(!(this instanceof g))return arguments.length>1?new g(t,arguments[1]):new g(t);if(!d(t))throw new TypeError(i("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(m=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(u("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!y(e.kind)&&""!==e.kind)?new TypeError(u("null4S","kind",v.join('", "'),e.kind)):null:new TypeError(u("null2V",i))}(h,arguments[1]),m))throw m;if(f=l(t),"generic"===(j=p(f)))if(f.length>0)if(x=f.iget(0),a(x))w="bool";else{if(!o(x))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");w="int"}else w="int";else if("int64"===j||"int32"===j)w="int";else if("uint8"===j)w="mask";else{if("bool"!==j)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");w="bool"}if("int"!==w&&""!==h.kind)throw new TypeError(i('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',w,h.kind));return c.push({id:(b+=1).toString(),ref:this,data:f,type:w,kind:h.kind,dtype:j,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function w(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new g(e,d);if(s=arguments[1],!n(s))throw new TypeError(i("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new g(e,d)};return e(s,"free",g.free),e(s,"get",g.get),s}e(g,"name","ndindex"),e(g,"free",(function(n){var r,i;return null!==(r=j(n))&&(i=r.value,e(i.ref,"_invalidated",!0),c.remove(r),i.data=null,!0)})),e(g,"get",(function(e){var n,r,i;return null===(n=j(e))?null:(r={data:(i=n.value).data,type:i.type,kind:i.kind,dtype:i.dtype},i.persist||g.free(e),r)})),t(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(g.prototype,"isCached",(function(){return!this._invalidated})),t(g.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(g.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var x=w("cartesian"),k=w("linear");e(g,"cartesianIndex",x),e(g,"linearIndex",k);export{x as cartesianIndex,g as default,k as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..3e975c9 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;ygDAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index c1303ac..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 19d22ac..53679f0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2826ad0 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From fdf1b17cc84d8a9c365f1d8eb8fdecc652d7a471 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Jan 2025 03:24:30 +0000 Subject: [PATCH 09/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 83351a0..19d22ac 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 6b385122b27592f30c5a008ec3ac4cdda969f441 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Jan 2025 03:26:08 +0000 Subject: [PATCH 10/48] Remove files --- index.d.ts | 718 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5565 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 59e586a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,718 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 03c671c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@esm/index.mjs";var v=["linear","cartesian"],y=m(v);var c=new f;function j(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var b=-1;function g(t){var h,m,f,j,w,x;if(!(this instanceof g))return arguments.length>1?new g(t,arguments[1]):new g(t);if(!d(t))throw new TypeError(i("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(m=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(u("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!y(e.kind)&&""!==e.kind)?new TypeError(u("null4S","kind",v.join('", "'),e.kind)):null:new TypeError(u("null2V",i))}(h,arguments[1]),m))throw m;if(f=l(t),"generic"===(j=p(f)))if(f.length>0)if(x=f.iget(0),a(x))w="bool";else{if(!o(x))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");w="int"}else w="int";else if("int64"===j||"int32"===j)w="int";else if("uint8"===j)w="mask";else{if("bool"!==j)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");w="bool"}if("int"!==w&&""!==h.kind)throw new TypeError(i('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',w,h.kind));return c.push({id:(b+=1).toString(),ref:this,data:f,type:w,kind:h.kind,dtype:j,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function w(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new g(e,d);if(s=arguments[1],!n(s))throw new TypeError(i("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new g(e,d)};return e(s,"free",g.free),e(s,"get",g.get),s}e(g,"name","ndindex"),e(g,"free",(function(n){var r,i;return null!==(r=j(n))&&(i=r.value,e(i.ref,"_invalidated",!0),c.remove(r),i.data=null,!0)})),e(g,"get",(function(e){var n,r,i;return null===(n=j(e))?null:(r={data:(i=n.value).data,type:i.type,kind:i.kind,dtype:i.dtype},i.persist||g.free(e),r)})),t(g.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(g.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(g.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(g.prototype,"isCached",(function(){return!this._invalidated})),t(g.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(g.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(g.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(g.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var x=w("cartesian"),k=w("linear");e(g,"cartesianIndex",x),e(g,"linearIndex",k);export{x as cartesianIndex,g as default,k as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 3e975c9..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;ygDAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2826ad0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bb775bac1a68a608565538b2d13109a8e32b5fb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 8 Jan 2025 03:26:55 +0000 Subject: [PATCH 11/48] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 52 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4914 insertions(+), 9500 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ee77ff5..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/index) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b860aa6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/utils-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7a6c98b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/utils-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,2BAA4B,EAYlDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d78aaeb..59e586a 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..94ec9e1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2834033 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index c1303ac..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/utils-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 19d22ac..53679f0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-linked-list": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..43a47cb --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 2f0810664c3844afe06a06e8616ba384ad050b21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 4 Dec 2025 05:37:52 +0000 Subject: [PATCH 12/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 3ce8f0b..ba807c5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 029da90203831ba2ba02c6930f0273bc8d664e1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 4 Dec 2025 05:46:57 +0000 Subject: [PATCH 13/48] Remove files --- index.d.ts | 718 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5565 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 59e586a..0000000 --- a/index.d.ts +++ /dev/null @@ -1,718 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 94ec9e1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-linked-list@v0.2.2-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(r("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?i(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(r("null2o","persist",e.persist)):i(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(r("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(r("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(r('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(r("null2V",s));i(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var i,r;return null!==(i=c(n))&&(r=i.value,e(r.ref,"_invalidated",!0),y.remove(i),r.data=null,!0)})),e(b,"get",(function(e){var n,i,r;return null===(n=c(e))?null:(i={data:(r=n.value).data,type:r.type,kind:r.kind,dtype:r.dtype},r.persist||b.free(e),i)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2834033..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/utils-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;s7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 43a47cb..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6f623af57f842784488c5df4834d106a01b5920c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 4 Dec 2025 05:47:17 +0000 Subject: [PATCH 14/48] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 55 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4914 insertions(+), 9511 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4a8f960 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(i("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?r(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(i("null2o","persist",e.persist)):r(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(i("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(i("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(i('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(i("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,i;return null!==(r=c(n))&&(i=r.value,e(i.ref,"_invalidated",!0),y.remove(r),i.data=null,!0)})),e(b,"get",(function(e){var n,r,i;return null===(n=c(e))?null:(r={data:(i=n.value).data,type:i.type,kind:i.kind,dtype:i.dtype},i.persist||b.free(e),r)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..957188a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;k7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ba807c5..53679f0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/dstructs-linked-list": "github:stdlib-js/dstructs-linked-list#main", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1650c1b --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From c6ee48b6126dc3516a0292f2b35b041c5017c6f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 06:31:21 +0000 Subject: [PATCH 15/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 5684de5..e0b268a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", From 6e6b6dea91acd511734d416b67b5301cbbb7a397 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:18:47 +0000 Subject: [PATCH 16/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4a8f960..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@esm/index.mjs";var f=["linear","cartesian"],v=u(f);var y=new m;function c(e){for(var n=y.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(t){var h,u,m,c,g,w;if(!(this instanceof b))return arguments.length>1?new b(t,arguments[1]):new b(t);if(!d(t))throw new TypeError(i("null5t",t));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,t){return n(t)?r(t,"persist")&&(e.persist=t.persist,!a(e.persist))?new TypeError(i("null2o","persist",e.persist)):r(t,"kind")&&(e.kind=t.kind,!v(e.kind)&&""!==e.kind)?new TypeError(i("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(i("null2V",t))}(h,arguments[1]),u))throw u;if(m=l(t),"generic"===(c=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(i('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return y.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",y.last()),s(this,"_invalidated",!1),this}function g(t){var s=function(e){var s,d;if(d={kind:t},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(i("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,i;return null!==(r=c(n))&&(i=r.value,e(i.ref,"_invalidated",!0),y.remove(r),i.data=null,!0)})),e(b,"get",(function(e){var n,r,i;return null===(n=c(e))?null:(r={data:(i=n.value).data,type:i.type,kind:i.kind,dtype:i.dtype},i.persist||b.free(e),r)})),t(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),t(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),t(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),t(b.prototype,"isCached",(function(){return!this._invalidated})),t(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),t(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);export{w as cartesianIndex,b as default,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 957188a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;k7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1650c1b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e148ae20eda64ae04a1b6880792f57d21a2f992f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:19:09 +0000 Subject: [PATCH 17/48] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 55 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4914 insertions(+), 9611 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61607b7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.0-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..070fcb5 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;y7CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e0b268a..ba309eb 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/dstructs-linked-list": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2ndarray": "github:stdlib-js/ndarray-base-ndarraylike2ndarray#main", - "@stdlib/ndarray-to-json": "github:stdlib-js/ndarray-to-json#main", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/assert-instance-of": "^0.3.0", - "@stdlib/assert-is-method": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..728b796 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 9102eb71931de0a53e7c8410430af23adaaf7e4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:59:53 +0000 Subject: [PATCH 18/48] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7854611..9a92289 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,13 @@ Specifically, instantiated `ndindex` objects are assigned a unique identifier an ## Usage ```javascript -import ndindex from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@esm/index.mjs'; +import ndindex from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { cartesianIndex, linearIndex } from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@esm/index.mjs'; +import { cartesianIndex, linearIndex } from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@v0.1.0-esm/index.mjs'; ``` @@ -537,7 +537,7 @@ var o = idx.toJSON(); - - - - From d320e4c1c5f61fe70a35931a17b1473787b3409c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:39:06 +0000 Subject: [PATCH 22/48] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 65 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4914 insertions(+), 9614 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c9af84b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.0-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 3cc34a2..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.2", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..21cd327 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From f592651cc1144c53beadbe3edf7019172831e089 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:06:05 +0000 Subject: [PATCH 23/48] Update README.md for ESM bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44f61ba..67a75eb 100644 --- a/README.md +++ b/README.md @@ -92,13 +92,13 @@ Specifically, instantiated `ndindex` objects are assigned a unique identifier an ## Usage ```javascript -import ndindex from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@esm/index.mjs'; +import ndindex from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@v0.1.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { cartesianIndex, linearIndex } from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@esm/index.mjs'; +import { cartesianIndex, linearIndex } from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-index@v0.1.1-esm/index.mjs'; ``` @@ -537,7 +537,7 @@ var o = idx.toJSON(); - - - - From b051549157ff65ae363f2abfcfd11cb2075c99bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Mar 2026 04:41:57 +0000 Subject: [PATCH 27/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 65 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9626 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 99e1f98..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-03-23T02:17:19.837Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8587f4f..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From cc00c201b6444ae0fcc6356e53fa2c4a5bd0af1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:18:43 +0000 Subject: [PATCH 28/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 7b4e20c..8587f4f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From eb45841ac8c3af507761c141882cfdf97a2bb3ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:25:32 +0000 Subject: [PATCH 29/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c3ed1847b2c65e7398f3ee9877e68971acb9f05f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Apr 2026 03:26:07 +0000 Subject: [PATCH 30/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 65 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 74 - benchmark/benchmark.dtype.js | 74 - benchmark/benchmark.get.js | 74 - benchmark/benchmark.id.js | 74 - benchmark/benchmark.is_cached.js | 74 - benchmark/benchmark.js | 107 - benchmark/benchmark.to_json.js | 74 - benchmark/benchmark.to_string.js | 74 - benchmark/benchmark.type.js | 74 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9626 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 855ae0d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-09T03:17:18.432Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index 7e81591..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':data', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index a047b0b..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':dtype', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 993484a..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':get', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 8af5d3a..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':id', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 671435a..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':isCached', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 003fb2b..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,107 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::instantiation,new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::instantiation,no_new', function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d371ab3..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toJSON:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 2e4e780..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':toString:len=3', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index 0e6e2f4..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( pkg+':type', function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8587f4f..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 76d019abd61994bc9ee3bd5dcdeae0d9ffe16a78 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 04:27:39 +0000 Subject: [PATCH 31/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 7b4e20c..8587f4f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From ca6a31992ee1c5539045b1c9704bad1d336ecd45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 05:18:29 +0000 Subject: [PATCH 32/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e410f8e6bf88f929fbad33f64f3fcdfa7f7000e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 21 Apr 2026 05:18:57 +0000 Subject: [PATCH 33/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 65 files changed, 4914 insertions(+), 9668 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8587f4f..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From b93755a758696c307f05b45f680feb017049d19c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:23:00 +0000 Subject: [PATCH 34/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 7b4e20c..8587f4f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From 053198ce22335276343451ffd17c23b107251a77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:24:53 +0000 Subject: [PATCH 35/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 86d3a86d9f81a82dfd68cb216380758d73e86213 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 17 May 2026 03:25:11 +0000 Subject: [PATCH 36/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9674 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 09b5ca1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-17T03:21:34.662Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8587f4f..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 93c12020ed3a923f606795bb56338c2a801a0862 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 03:25:04 +0000 Subject: [PATCH 37/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 7b4e20c..8587f4f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From 32c41166d6b57e6d1eedc7f3111d00dc1ab81f0c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 03:40:47 +0000 Subject: [PATCH 38/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From be71be251ca6c1bf798c7fe0d5a6363f6b045f4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 May 2026 03:41:18 +0000 Subject: [PATCH 39/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9687 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f653963..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-20T03:22:03.545Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f97bbab..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function i(r){var e,a,t,n,d,v;if(!(this instanceof i))return arguments.length>1?new i(r,arguments[1]):new i(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(a=se(e,arguments[1]),a))throw a;if(t=ie(r),n=te(t),n==="generic")if(t.length>0)if(v=t.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:t,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(i,"name","ndindex");o(i,"free",function(e){var a,t;return a=N(e),a===null?!1:(t=a.value,o(t.ref,"_invalidated",!0),p.remove(a),t.data=null,!0)});o(i,"get",function(e){var a,t,n;return a=N(e),a===null?null:(n=a.value,t={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||i.free(e),t)});u(i.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(i.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(i.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(i.prototype,"isCached",function(){return!this._invalidated});u(i.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(i.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(i.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(i.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=i});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=a;return R(e,"free",l.free),R(e,"get",l.get),e;function a(t){var n,d;if(d={kind:r},arguments.length<2)return new l(t,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(t,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1780b84..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8587f4f..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 7bafbf6e0366a0755a859601c6808da788372a14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 03:26:26 +0000 Subject: [PATCH 40/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 3a76cdd..9ea6042 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From dd9fc11699c48501c3e09ab3c1919935459024a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 03:34:47 +0000 Subject: [PATCH 41/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ac2882773570db9e0dbc078b95deb02880f71d7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 30 Jun 2026 03:35:14 +0000 Subject: [PATCH 42/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9687 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4b19b33..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-06-30T03:24:29.854Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c893dcb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){try{return e||r((e={exports:{}}).exports,e),e.exports}catch(i){throw e=0,i}}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function t(r){var e,i,a,n,d,v;if(!(this instanceof t))return arguments.length>1?new t(r,arguments[1]):new t(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(i=se(e,arguments[1]),i))throw i;if(a=ie(r),n=te(a),n==="generic")if(a.length>0)if(v=a.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:a,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(t,"name","ndindex");o(t,"free",function(e){var i,a;return i=N(e),i===null?!1:(a=i.value,o(a.ref,"_invalidated",!0),p.remove(i),a.data=null,!0)});o(t,"get",function(e){var i,a,n;return i=N(e),i===null?null:(n=i.value,a={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||t.free(e),a)});u(t.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(t.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(t.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(t.prototype,"isCached",function(){return!this._invalidated});u(t.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(t.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(t.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(t.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=t});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=i;return R(e,"free",l.free),R(e,"get",l.get),e;function i(a){var n,d;if(d={kind:r},arguments.length<2)return new l(a,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(a,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 430125e..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9ea6042..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From cee3e93008e9513805aaad4ac6683cbc5f330a99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Aug 2026 03:18:42 +0000 Subject: [PATCH 43/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 4 ++-- lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..23bffb3 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..92b4232 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( 'null5t', x ) ); } // Resolve index options: opts = defaults(); diff --git a/lib/validate.js b/lib/validate.js index 01a5148..152c6ad 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( 'null2V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( 'null2o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 3a76cdd..9ea6042 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From 16167838e60d3f41a4b1a8f6fb705b91b5cf5bfd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Aug 2026 03:41:39 +0000 Subject: [PATCH 44/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c287bc8e94bb8fd91355d0ce7d4a37017ddfc141 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 18 Aug 2026 03:42:16 +0000 Subject: [PATCH 45/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9688 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b4a6f00..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-18T03:14:22.293Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c893dcb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){try{return e||r((e={exports:{}}).exports,e),e.exports}catch(i){throw e=0,i}}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function t(r){var e,i,a,n,d,v;if(!(this instanceof t))return arguments.length>1?new t(r,arguments[1]):new t(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(i=se(e,arguments[1]),i))throw i;if(a=ie(r),n=te(a),n==="generic")if(a.length>0)if(v=a.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:a,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(t,"name","ndindex");o(t,"free",function(e){var i,a;return i=N(e),i===null?!1:(a=i.value,o(a.ref,"_invalidated",!0),p.remove(i),a.data=null,!0)});o(t,"get",function(e){var i,a,n;return i=N(e),i===null?null:(n=i.value,a={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||t.free(e),a)});u(t.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(t.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(t.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(t.prototype,"isCached",function(){return!this._invalidated});u(t.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(t.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(t.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(t.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=t});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=i;return R(e,"free",l.free),R(e,"get",l.get),e;function i(a){var n,d;if(d={kind:r},arguments.length<2)return new l(a,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(a,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 430125e..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..58be336 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1212075 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 23bffb3..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 92b4232..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null5t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 152c6ad..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'null2o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'null4S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9ea6042..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e6ec53 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -}); From 74630253ef8adc1cfea570ec5de4f64d5cd798b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Oct 2026 02:51:19 +0000 Subject: [PATCH 46/48] Transform error messages --- lib/factory.js | 4 ++-- lib/main.js | 24 ++++++++++++------------ lib/validate.js | 8 ++++---- package.json | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index bc9bef2..c5b213d 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -23,7 +23,7 @@ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndindex = require( './main.js' ); @@ -80,7 +80,7 @@ function createFactory( kind ) { } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '2512V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; diff --git a/lib/main.js b/lib/main.js index c6f2e93..462a8cd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); var dtype = require( '@stdlib/ndarray-base-dtype' ); var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.js' ); var validate = require( './validate.js' ); var cache = require( './cache.js' ); @@ -80,7 +80,7 @@ function ndindex( x ) { return new ndindex( x ); } if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + throw new TypeError( format( '2515t', x ) ); } // Resolve index options: opts = defaults(); @@ -107,7 +107,7 @@ function ndindex( x ) { } else if ( isInteger( v ) ) { t = 'int'; } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); + throw new TypeError( format('251HG') ); } } else { // If we've been provided an empty ndarray, fallback to a default index type: @@ -120,10 +120,10 @@ function ndindex( x ) { } else if ( dt === 'bool' ) { t = 'bool'; } else { - throw new TypeError( 'invalid argument. First argument must be a valid index ndarray.' ); + throw new TypeError( format('251HG') ); } if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( 'invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.', t, opts.kind ) ); + throw new TypeError( format( '251HM', t, opts.kind ) ); } // Add the ndarray index to the index cache: cache.push({ @@ -295,7 +295,7 @@ setReadOnly( ndindex, 'get', function get( id ) { */ setReadOnlyAccessor( ndindex.prototype, 'data', function get() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return this._node.value.data; }); @@ -324,7 +324,7 @@ setReadOnlyAccessor( ndindex.prototype, 'data', function get() { */ setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return this._node.value.dtype; }); @@ -353,7 +353,7 @@ setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { */ setReadOnlyAccessor( ndindex.prototype, 'id', function get() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return this._node.value.id; }); @@ -409,7 +409,7 @@ setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { */ setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return this._node.value.kind; }); @@ -438,7 +438,7 @@ setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { */ setReadOnlyAccessor( ndindex.prototype, 'type', function get() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return this._node.value.type; }); @@ -467,7 +467,7 @@ setReadOnlyAccessor( ndindex.prototype, 'type', function get() { */ setReadOnly( ndindex.prototype, 'toString', function toString() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return 'ndindex<' + this._node.value.id + '>'; }); @@ -500,7 +500,7 @@ setReadOnly( ndindex.prototype, 'toString', function toString() { */ setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { if ( this._invalidated ) { - throw new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' ); + throw new Error( format('251HH') ); } return { 'type': 'ndindex', diff --git a/lib/validate.js b/lib/validate.js index 01a5148..a8ce124 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -24,7 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var KINDS = require( './kinds.json' ); @@ -57,18 +57,18 @@ var isKind = contains( KINDS ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '2512V', options ) ); } if ( hasOwnProp( options, 'persist' ) ) { opts.persist = options.persist; if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) ); + return new TypeError( format( '2512o', 'persist', opts.persist ) ); } } if ( hasOwnProp( options, 'kind' ) ) { opts.kind = options.kind; if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'kind', KINDS.join( '", "' ), opts.kind ) ); + return new TypeError( format( '2514S', 'kind', KINDS.join( '", "' ), opts.kind ) ); } } return null; diff --git a/package.json b/package.json index 3a76cdd..9ea6042 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype": "^0.2.3", "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/utils-define-nonenumerable-property": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", From a3006407a6782c3ce4ee55f4a7917fdb5881fec9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Oct 2026 03:01:56 +0000 Subject: [PATCH 47/48] Remove files --- index.d.ts | 720 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5567 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 9d9579b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,720 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; - -/** -* Interface describing "base" function options. -*/ -interface BaseOptions { - /** - * Boolean indicating whether to continue persisting an index object after first usage (default: `false`). - */ - persist?: boolean; -} - -/** -* Interface describing function options. -*/ -interface Options extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray is of a specialized kind. - */ - kind?: IndexArrayKinds; -} - -/** -* Interface describing function options for a Cartesian ndarray index. -*/ -interface CartesianOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains Cartesian indices. - */ - kind: 'cartesian'; -} - -/** -* Interface describing function options for a linear ndarray index. -*/ -interface LinearOptions extends BaseOptions { - /** - * Specifies whether a provided integer input ndarray contains indices representing locations in linear memory. - */ - kind: 'linear'; -} - -/** -* Interface defining common methods for constructors and functions which create `ndindex` objects. -*/ -interface BaseConstructor { - /** - * Frees the `ndindex` associated with a provided identifier. - * - * @param id - identifier - * @returns boolean indicating whether an `ndindex` was successfully freed - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var out = ndindex.free( idx.id ); - * // returns true - */ - free( id: string ): boolean; - - /** - * Returns ndarray index data associated with a provided identifier. - * - * @param id - identifier - * @returns object containing ndarray index data - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var idx = new ndindex( array( new Uint8Array( [ 1, 0, 1, 0 ] ) ), { - * 'persist': true - * }); - * // returns - * - * // ... - * - * var o = ndindex.get( idx.id ); - * // returns {...} - * - * var d = o.data; - * // returns - * - * var t = o.type; - * // returns 'mask' - * - * var dt = o.dtype; - * // returns 'uint8' - */ - get( id: string ): T | null; -} - -/** -* Interface defining an `ndindex` constructor which is both "newable" and "callable". -*/ -interface Constructor extends BaseConstructor { - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - new( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = new ndindex( x ); - * // returns - */ - new( x: IndexArray, options?: Options ): ndindex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: uint8ndarray, options?: BaseOptions ): MaskArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var BooleanArray = require( '@stdlib/array-bool' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new BooleanArray( [ true, false, true, false ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: booleanndarray, options?: BaseOptions ): BooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: int32ndarray, options: CartesianOptions ): CartesianInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: int32ndarray, options: LinearOptions ): LinearInt32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: int32ndarray, options?: Options ): Int32ArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'cartesian' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: CartesianOptions ): CartesianGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x, { - * 'kind': 'linear' - * }); - * // returns - */ - ( x: GenericIntegerIndexArray, options: LinearOptions ): LinearGenericArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: Options ): GenericIntegerArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ true, false, true, false ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: GenericBooleanIndexArray, options?: BaseOptions ): GenericBooleanArrayIndex; - - /** - * ndarray index constructor. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray - * @returns ndindex instance - * - * @example - * var Uint8Array = require( '@stdlib/array-uint8' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex( x ); - * // returns - */ - ( x: IndexArray, options?: Options ): ndindex; - - /** - * String value of the constructor name. - */ - name: 'ndindex'; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - cartesianIndex: CartesianIndexFactory; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - linearIndex: LinearIndexFactory; -} - -/** -* Interface for creating index objects for ndarrays containing Cartesian indices. -*/ -interface CartesianIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): CartesianInt32ArrayIndex; - - /** - * Returns an ndarray index containing Cartesian indices. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.cartesianIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): CartesianGenericArrayIndex; -} - -/** -* Interface for creating index objects for ndarrays containing linear indices. -*/ -interface LinearIndexFactory extends BaseConstructor { - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var Int32Array = require( '@stdlib/array-int32' ); - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: int32ndarray, options?: BaseOptions ): LinearInt32ArrayIndex; - - /** - * Returns an ndarray index containing indices representing locations in linear memory. - * - * @param x - input ndarray - * @param options - function options - * @param options.persist - boolean indicating whether to continue persisting an index object after first usage - * @returns ndindex instance - * - * @example - * var array = require( '@stdlib/ndarray-array' ); - * - * var x = array( [ 1, 2, 3, 4 ], { - * 'dtype': 'generic' - * }); - * - * var idx = ndindex.linearIndex( x ); - * // returns - */ - ( x: GenericIntegerIndexArray, options?: BaseOptions ): LinearGenericArrayIndex; -} - -/** -* ndarray index constructor. -* -* @param x - input ndarray -* @param options - function options -* @param options.persist - boolean indicating whether to continue persisting an index object after first usage -* @param options.kind - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns ndindex instance -* -* @example -* var Uint8Array = require( '@stdlib/array-uint8' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = new ndindex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.cartesianIndex( x ); -* // returns -* -* @example -* var Int32Array = require( '@stdlib/array-int32' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( new Int32Array( [ 1, 0, 1, 0 ] ) ); -* -* var idx = ndindex.linearIndex( x ); -* // returns -*/ -declare var ctor: Constructor; - - -// EXPORTS // - -export = ctor; - -// eslint-doctest-alias: ndindex diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 58be336..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as u}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var f=["linear","cartesian"],v=u(f);var c=new m;function y(e){for(var n=c.first();n;){if(n.value.id===e)return n;n=n.next}return null}var j=-1;function b(i){var h,u,m,y,g,w;if(!(this instanceof b))return arguments.length>1?new b(i,arguments[1]):new b(i);if(!d(i))throw new TypeError(t("null5t",i));if(h={persist:!1,kind:""},arguments.length>1&&(u=function(e,i){return n(i)?r(i,"persist")&&(e.persist=i.persist,!a(e.persist))?new TypeError(t("null2o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!v(e.kind)&&""!==e.kind)?new TypeError(t("null4S","kind",f.join('", "'),e.kind)):null:new TypeError(t("null2V",i))}(h,arguments[1]),u))throw u;if(m=l(i),"generic"===(y=p(m)))if(m.length>0)if(w=m.iget(0),a(w))g="bool";else{if(!o(w))throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="int"}else g="int";else if("int64"===y||"int32"===y)g="int";else if("uint8"===y)g="mask";else{if("bool"!==y)throw new TypeError("invalid argument. First argument must be a valid index ndarray.");g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(t('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',g,h.kind));return c.push({id:(j+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:y,persist:h.persist}),e(this,"_node",c.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new b(e,d);if(s=arguments[1],!n(s))throw new TypeError(t("null2V",s));r(s,"persist")&&(d.persist=s.persist);return new b(e,d)};return e(s,"free",b.free),e(s,"get",b.get),s}e(b,"name","ndindex"),e(b,"free",(function(n){var r,t;return null!==(r=y(n))&&(t=r.value,e(t.ref,"_invalidated",!0),c.remove(r),t.data=null,!0)})),e(b,"get",(function(e){var n,r,t;return null===(n=y(e))?null:(r={data:(t=n.value).data,type:t.type,kind:t.kind,dtype:t.dtype},t.persist||b.free(e),r)})),i(b.prototype,"data",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data})),i(b.prototype,"dtype",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype})),i(b.prototype,"id",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id})),i(b.prototype,"isCached",(function(){return!this._invalidated})),i(b.prototype,"kind",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind})),i(b.prototype,"type",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type})),e(b.prototype,"toString",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"})),e(b.prototype,"toJSON",(function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var w=g("cartesian"),x=g("linear");e(b,"cartesianIndex",w),e(b,"linearIndex",x);const{free:k}=b,{get:_}=b;export{w as cartesianIndex,b as default,k as free,_ as get,x as linearIndex}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 1212075..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'null2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'null2o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'null4S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null5t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,SAAUZ,IAIxC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,SAAU,UAAWX,EAAKY,UAGrDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,SAAU,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGtE,KAdC,IAAIH,UAAWC,EAAQ,SAAUG,GAe1C,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAW,mEAFrBN,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAW,mEAFrBN,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,0GAA2GP,EAAGJ,EAAKa,OAmBjJ,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,SAAUG,IAEnCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,OAAOpC,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,WAAapC,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO,oGAElB,MAAO,CACNd,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e6ec53..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d5ce76b97aeff5cdfeb591b0fba7b05d87e37b88 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Oct 2026 03:02:29 +0000 Subject: [PATCH 48/48] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 131 +- SECURITY.md | 5 - benchmark/benchmark.data.js | 75 - benchmark/benchmark.dtype.js | 75 - benchmark/benchmark.get.js | 75 - benchmark/benchmark.id.js | 75 - benchmark/benchmark.is_cached.js | 75 - benchmark/benchmark.js | 108 - benchmark/benchmark.to_json.js | 75 - benchmark/benchmark.to_string.js | 75 - benchmark/benchmark.type.js | 75 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 301 -- docs/types/test.ts | 303 -- examples/index.js | 66 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cache.js | 40 - lib/cache_gc.js | 59 - lib/cartesian.js | 57 - lib/defaults.js | 43 - lib/factory.js | 95 - lib/find.js | 49 - lib/id.js | 46 - lib/index.js | 56 - lib/kinds.json | 4 - lib/linear.js | 57 - lib/main.js | 515 -- lib/validate.js | 80 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.cartesian.js | 589 --- test/test.js | 44 - test/test.linear.js | 589 --- test/test.main.js | 2053 -------- test/test.validate.js | 157 - 66 files changed, 4914 insertions(+), 9688 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.data.js delete mode 100644 benchmark/benchmark.dtype.js delete mode 100644 benchmark/benchmark.get.js delete mode 100644 benchmark/benchmark.id.js delete mode 100644 benchmark/benchmark.is_cached.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.to_json.js delete mode 100644 benchmark/benchmark.to_string.js delete mode 100644 benchmark/benchmark.type.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cache.js delete mode 100644 lib/cache_gc.js delete mode 100644 lib/cartesian.js delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/find.js delete mode 100644 lib/id.js delete mode 100644 lib/index.js delete mode 100644 lib/kinds.json delete mode 100644 lib/linear.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.cartesian.js delete mode 100644 test/test.js delete mode 100644 test/test.linear.js delete mode 100644 test/test.main.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +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 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0564137..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-10-03T02:44:55.165Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 335e57b..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/index) 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 ff3b463..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/index) 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 ee06ed3..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: '28 4 * * 5' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -630,7 +627,7 @@ console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); ## 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]. @@ -695,23 +692,23 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [json]: http://www.json.org/ -[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor +[@stdlib/proxy/ctor]: https://github.com/stdlib-js/proxy-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-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 -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy +[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray-to-fancy/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy +[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray-fancy/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/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.data.js b/benchmark/benchmark.data.js deleted file mode 100644 index a5dc500..0000000 --- a/benchmark/benchmark.data.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:data', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].data; - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.dtype.js b/benchmark/benchmark.dtype.js deleted file mode 100644 index 5e59d86..0000000 --- a/benchmark/benchmark.dtype.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:dtype', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].dtype; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.get.js b/benchmark/benchmark.get.js deleted file mode 100644 index 920eaa1..0000000 --- a/benchmark/benchmark.get.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:get', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - ( new ndindex( v1, opts ) ).id, - ( new ndindex( v2, opts ) ).id, - ( new ndindex( v3, opts ) ).id - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex.get( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.id.js b/benchmark/benchmark.id.js deleted file mode 100644 index 903d015..0000000 --- a/benchmark/benchmark.id.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:id', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].id; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.is_cached.js b/benchmark/benchmark.is_cached.js deleted file mode 100644 index 38f7ea7..0000000 --- a/benchmark/benchmark.is_cached.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:isCached', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].isCached; - if ( typeof v !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( v ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index dcbe093..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::instantiation,new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = new ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::instantiation,no_new', pkg ), function benchmark( b ) { - var values; - var v1; - var v2; - var v3; - var v; - var i; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - v1, - v2, - v3 - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = ndindex( values[ i%values.length ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !instanceOf( v, ndindex ) ) { - b.fail( 'should return an instance' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_json.js b/benchmark/benchmark.to_json.js deleted file mode 100644 index d540031..0000000 --- a/benchmark/benchmark.to_json.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toJSON:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toJSON(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isPlainObject( v ) ) { - b.fail( 'should return an object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.to_string.js b/benchmark/benchmark.to_string.js deleted file mode 100644 index 0bfa95a..0000000 --- a/benchmark/benchmark.to_string.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:toString:len=3', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].toString(); - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.type.js b/benchmark/benchmark.type.js deleted file mode 100644 index d587185..0000000 --- a/benchmark/benchmark.type.js +++ /dev/null @@ -1,75 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var empty = require( '@stdlib/ndarray-empty' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var ndindex = require( './../lib' ); - - -// MAIN // - -bench( format( '%s:type', pkg ), function benchmark( b ) { - var values; - var opts; - var v1; - var v2; - var v3; - var v; - var i; - - opts = { - 'persist': true - }; - - v1 = zeros( [ 2 ], { - 'dtype': 'int32' - }); - v2 = zeros( [ 2, 2 ], { - 'dtype': 'int32' - }); - v3 = empty( [ 10 ], { - 'dtype': 'bool' - }); - values = [ - new ndindex( v1, opts ), - new ndindex( v2, opts ), - new ndindex( v3, opts ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = values[ i%values.length ].type; - if ( typeof v !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( v ) ) { - b.fail( 'should return a string' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b5dcd89..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/index" -%% click B href "https://github.com/stdlib-js/ndarray-index/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-index/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-index/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-index/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-index/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/index -[production-url]: https://github.com/stdlib-js/ndarray-index/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-index/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-index/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-index/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-index/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-index/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-index/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0b44231..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import ctor from '../docs/types/index'; -export = ctor; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c893dcb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var s=function(r,e){return function(){try{return e||r((e={exports:{}}).exports,e),e.exports}catch(i){throw e=0,i}}};var m=s(function(qe,w){"use strict";function A(){return{persist:!1,kind:""}}w.exports=A});var q=s(function(be,D){D.exports=["linear","cartesian"]});var _=s(function(xe,k){"use strict";var U=require("@stdlib/assert-is-plain-object"),b=require("@stdlib/assert-has-own-property"),z=require("@stdlib/assert-is-boolean").isPrimitive,G=require("@stdlib/array-base-assert-contains").factory,f=require("@stdlib/string-format"),x=q(),H=G(x);function M(r,e){return U(e)?b(e,"persist")&&(r.persist=e.persist,!z(r.persist))?new TypeError(f("invalid option. `%s` option must be a boolean. Option: `%s`.","persist",r.persist)):b(e,"kind")&&(r.kind=e.kind,!H(r.kind)&&r.kind!=="")?new TypeError(f('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"kind",x.join('", "'),r.kind)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",e))}k.exports=M});var c=s(function(ke,E){"use strict";var Q=require("@stdlib/dstructs-linked-list"),W=new Q;E.exports=W});var O=s(function(_e,T){"use strict";var X=c();function Y(r){for(var e=X.first();e;){if(e.value.id===r)return e;e=e.next}return null}T.exports=Y});var F=s(function(Ee,j){"use strict";var I=-1;function Z(){return I+=1,I.toString()}j.exports=Z});var h=s(function(Te,P){"use strict";var u=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),o=require("@stdlib/utils-define-nonenumerable-read-only-property"),$=require("@stdlib/utils-define-nonenumerable-property"),ee=require("@stdlib/assert-is-ndarray-like"),re=require("@stdlib/assert-is-boolean").isPrimitive,ne=require("@stdlib/assert-is-integer").isPrimitive,ie=require("@stdlib/ndarray-base-ndarraylike2ndarray"),te=require("@stdlib/ndarray-base-dtype"),ae=require("@stdlib/ndarray-to-json"),S=require("@stdlib/string-format"),de=m(),se=_(),p=c(),N=O(),oe=F();function t(r){var e,i,a,n,d,v;if(!(this instanceof t))return arguments.length>1?new t(r,arguments[1]):new t(r);if(!ee(r))throw new TypeError(S("invalid argument. First argument must be an ndarray-like object. Value: `%s`.",r));if(e=de(),arguments.length>1&&(i=se(e,arguments[1]),i))throw i;if(a=ie(r),n=te(a),n==="generic")if(a.length>0)if(v=a.iget(0),re(v))d="bool";else if(ne(v))d="int";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");else d="int";else if(n==="int64"||n==="int32")d="int";else if(n==="uint8")d="mask";else if(n==="bool")d="bool";else throw new TypeError("invalid argument. First argument must be a valid index ndarray.");if(d!=="int"&&e.kind!=="")throw new TypeError(S('invalid argument. First argument is not compatible with the specified index "kind". Type: %s. Kind: %s.',d,e.kind));return p.push({id:oe(),ref:this,data:a,type:d,kind:e.kind,dtype:n,persist:e.persist}),o(this,"_node",p.last()),$(this,"_invalidated",!1),this}o(t,"name","ndindex");o(t,"free",function(e){var i,a;return i=N(e),i===null?!1:(a=i.value,o(a.ref,"_invalidated",!0),p.remove(i),a.data=null,!0)});o(t,"get",function(e){var i,a,n;return i=N(e),i===null?null:(n=i.value,a={data:n.data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||t.free(e),a)});u(t.prototype,"data",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.data});u(t.prototype,"dtype",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.dtype});u(t.prototype,"id",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.id});u(t.prototype,"isCached",function(){return!this._invalidated});u(t.prototype,"kind",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.kind});u(t.prototype,"type",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return this._node.value.type});o(t.prototype,"toString",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return"ndindex<"+this._node.value.id+">"});o(t.prototype,"toJSON",function(){if(this._invalidated)throw new Error("invalid operation. This ndarray index instance has already been freed and can no longer be used.");return{type:"ndindex",kind:this._node.value.kind,data:ae(this._node.value.data)}});P.exports=t});var y=s(function(Oe,K){"use strict";var R=require("@stdlib/utils-define-nonenumerable-read-only-property"),ue=require("@stdlib/assert-is-plain-object"),le=require("@stdlib/assert-has-own-property"),ve=require("@stdlib/string-format"),l=h();function fe(r){var e=i;return R(e,"free",l.free),R(e,"get",l.get),e;function i(a){var n,d;if(d={kind:r},arguments.length<2)return new l(a,d);if(n=arguments[1],!ue(n))throw new TypeError(ve("invalid argument. Options argument must be an object. Value: `%s`.",n));return le(n,"persist")&&(d.persist=n.persist),new l(a,d)}}K.exports=fe});var V=s(function(Ie,L){"use strict";var ce=y(),pe=ce("cartesian");L.exports=pe});var C=s(function(je,B){"use strict";var he=y(),ye=he("linear");B.exports=ye});var J=require("@stdlib/utils-define-nonenumerable-read-only-property"),ge=V(),we=C(),g=h();J(g,"cartesianIndex",ge);J(g,"linearIndex",we);module.exports=g; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 430125e..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.js", "../lib/kinds.json", "../lib/validate.js", "../lib/cache.js", "../lib/find.js", "../lib/id.js", "../lib/main.js", "../lib/factory.js", "../lib/cartesian.js", "../lib/linear.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = defaults;\n", "[\n \"linear\",\n \"cartesian\"\n]\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar format = require( '@stdlib/string-format' );\nvar KINDS = require( './kinds.json' );\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList = require( '@stdlib/dstructs-linked-list' );\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nmodule.exports = cache;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache = require( './cache.js' );\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = find;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nmodule.exports = id;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' );\nvar dtype = require( '@stdlib/ndarray-base-dtype' );\nvar ndarray2json = require( '@stdlib/ndarray-to-json' );\nvar format = require( '@stdlib/string-format' );\nvar defaults = require( './defaults.js' );\nvar validate = require( './validate.js' );\nvar cache = require( './cache.js' );\nvar findndindex = require( './find.js' );\nvar generateId = require( './id.js' );\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a valid index ndarray.' );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( 'invalid argument. First argument is not compatible with the specified index \"kind\". Type: %s. Kind: %s.', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( 'invalid operation. This ndarray index instance has already been freed and can no longer be used.' );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nmodule.exports = ndindex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\nvar ndindex = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\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\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = createFactory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nmodule.exports = cartesianIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nmodule.exports = linearIndex;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* var empty = require( '@stdlib/ndarray-empty' );\n* var ndindex = require( '@stdlib/ndarray-index' );\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar cartesianIndex = require( './cartesian.js' );\nvar linearIndex = require( './linear.js' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,QAAW,GACX,KAAQ,EACT,CACD,CAKAD,EAAO,QAAUC,IC1CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,SACA,WACF,ICHA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IAKRC,EAASH,EAAUE,CAAM,EAyB7B,SAASE,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,QAClB,CAACP,EAAWM,EAAK,OAAQ,GACtB,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAK,OAAQ,CAAE,EAGrHP,EAAYQ,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACH,EAAQE,EAAK,IAAK,GAAKA,EAAK,OAAS,IACnC,IAAI,UAAWJ,EAAQ,gFAAiF,OAAQC,EAAM,KAAM,MAAO,EAAGG,EAAK,IAAK,CAAE,EAGpJ,KAdC,IAAI,UAAWJ,EAAQ,qEAAsEK,CAAQ,CAAE,CAehH,CAKAV,EAAO,QAAUQ,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,8BAA+B,EAYrDC,EAAQ,IAAID,EAKhBD,EAAO,QAAUE,ICvCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAQ,IAYZ,SAASC,EAAMC,EAAK,CAEnB,QADIC,EAAOH,EAAM,MAAM,EACfG,GAAO,CACd,GAAKA,EAAK,MAAM,KAAOD,EACtB,OAAOC,EAERA,EAAOA,EAAK,IACb,CACA,OAAO,IACR,CAKAJ,EAAO,QAAUE,IChDjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,GAed,SAASC,GAAK,CACb,OAAAD,GAAW,EACJA,EAAQ,SAAS,CACzB,CAKAD,EAAO,QAAUE,IC7CjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAwBA,IAAIC,EAAsB,QAAS,uDAAwD,EACvFC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,6CAA8C,EAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAsB,QAAS,0CAA2C,EAC1EC,GAAQ,QAAS,4BAA6B,EAC9CC,GAAe,QAAS,yBAA0B,EAClDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IACRC,EAAc,IACdC,GAAa,IA8BjB,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACA,EACJ,GAAK,EAAE,gBAAgBN,GACtB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAASC,EAAG,UAAW,CAAE,CAAE,EAEhC,IAAID,EAASC,CAAE,EAEvB,GAAK,CAACb,GAAea,CAAE,EACtB,MAAM,IAAI,UAAWP,EAAQ,gFAAiFO,CAAE,CAAE,EAInH,GADAC,EAAOP,GAAS,EACX,UAAU,OAAS,IACvBQ,EAAMP,GAAUM,EAAM,UAAW,CAAE,CAAE,EAChCC,GACJ,MAAMA,EAUR,GANAC,EAAMb,GAAqBU,CAAE,EAG7BI,EAAKb,GAAOY,CAAI,EAGXC,IAAO,UACX,GAAKD,EAAI,OAAS,EAIjB,GAHA,EAAIA,EAAI,KAAM,CAAE,EAGXf,GAAW,CAAE,EACjBiB,EAAI,eACOhB,GAAW,CAAE,EACxBgB,EAAI,UAEJ,OAAM,IAAI,UAAW,iEAAkE,OAIxFA,EAAI,cAEMD,IAAO,SAAWA,IAAO,QACpCC,EAAI,cACOD,IAAO,QAClBC,EAAI,eACOD,IAAO,OAClBC,EAAI,WAEJ,OAAM,IAAI,UAAW,iEAAkE,EAExF,GAAKA,IAAM,OAASJ,EAAK,OAAS,GACjC,MAAM,IAAI,UAAWR,EAAQ,0GAA2GY,EAAGJ,EAAK,IAAK,CAAE,EAGxJ,OAAAL,EAAM,KAAK,CACV,GAAME,GAAW,EACjB,IAAO,KACP,KAAQK,EACR,KAAQE,EACR,KAAQJ,EAAK,KACb,MAASG,EACT,QAAWH,EAAK,OACjB,CAAC,EAGDhB,EAAa,KAAM,QAASW,EAAM,KAAK,CAAE,EAGzCV,EAAkB,KAAM,eAAgB,EAAM,EAEvC,IACR,CAeAD,EAAac,EAAS,OAAQ,SAAU,EA4BxCd,EAAac,EAAS,OAAQ,SAAeO,EAAK,CACjD,IAAIC,EACAC,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,IAERC,EAAID,EAAK,MAGTtB,EAAauB,EAAE,IAAK,eAAgB,EAAK,EAGzCZ,EAAM,OAAQW,CAAK,EAGnBC,EAAE,KAAO,KAEF,GACR,CAAC,EAqCDvB,EAAac,EAAS,MAAO,SAAcO,EAAK,CAC/C,IAAIC,EACAE,EACAD,EAIJ,OADAD,EAAOV,EAAaS,CAAG,EAClBC,IAAS,KACN,MAERC,EAAID,EAAK,MAGTE,EAAM,CACL,KAAQD,EAAE,KACV,KAAQA,EAAE,KACV,KAAQA,EAAE,KACV,MAASA,EAAE,KACZ,EAGMA,EAAE,SACPT,EAAQ,KAAMO,CAAG,EAEXG,EACR,CAAC,EAwBDzB,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,QAAS,UAAe,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,KACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,KAAM,UAAe,CAC5D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,EACzB,CAAC,EAuBDf,EAAqBe,EAAQ,UAAW,WAAY,UAAe,CAClE,MAAO,CAAC,KAAK,YACd,CAAC,EA0BDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDf,EAAqBe,EAAQ,UAAW,OAAQ,UAAe,CAC9D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,OAAO,KAAK,MAAM,MAAM,IACzB,CAAC,EAwBDd,EAAac,EAAQ,UAAW,WAAY,UAAoB,CAC/D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,WAAa,KAAK,MAAM,MAAM,GAAK,GAC3C,CAAC,EA4BDd,EAAac,EAAQ,UAAW,SAAU,UAAkB,CAC3D,GAAK,KAAK,aACT,MAAM,IAAI,MAAO,kGAAmG,EAErH,MAAO,CACN,KAAQ,UACR,KAAQ,KAAK,MAAM,MAAM,KACzB,KAAQP,GAAc,KAAK,MAAM,MAAM,IAAK,CAC7C,CACD,CAAC,EAKDT,EAAO,QAAUgB,IClgBjB,IAAAW,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAW,QAAS,gCAAiC,EACrDC,GAAa,QAAS,iCAAkC,EACxDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAU,IAyBd,SAASC,GAAeC,EAAO,CAC9B,IAAIC,EAAIC,EACR,OAAAR,EAAaO,EAAG,OAAQH,EAAQ,IAAK,EACrCJ,EAAaO,EAAG,MAAOH,EAAQ,GAAI,EAC5BG,EAeP,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAKJ,GAHAA,EAAO,CACN,KAAQL,CACT,EACK,UAAU,OAAS,EACvB,OAAO,IAAIF,EAASK,EAAGE,CAAK,EAG7B,GADAD,EAAU,UAAW,CAAE,EAClB,CAACT,GAAUS,CAAQ,EACvB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,OAAKR,GAAYQ,EAAS,SAAU,IACnCC,EAAK,QAAUD,EAAQ,SAEjB,IAAIN,EAASK,EAAGE,CAAK,CAC7B,CACD,CAKAZ,EAAO,QAAUM,KC9FjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAiBD,GAAe,WAAY,EAKhDD,EAAO,QAAUE,KCxDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAgB,IA6BhBC,GAAcD,GAAe,QAAS,EAK1CD,EAAO,QAAUE,KCjBjB,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,GAAiB,IACjBC,GAAc,IACdC,EAAO,IAKXH,EAAaG,EAAM,iBAAkBF,EAAe,EACpDD,EAAaG,EAAM,cAAeD,EAAY,EAK9C,OAAO,QAAUC", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_kinds", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "contains", "format", "KINDS", "isKind", "validate", "opts", "options", "require_cache", "__commonJSMin", "exports", "module", "LinkedList", "cache", "require_find", "__commonJSMin", "exports", "module", "cache", "find", "id", "node", "require_id", "__commonJSMin", "exports", "module", "COUNTER", "id", "require_main", "__commonJSMin", "exports", "module", "setReadOnlyAccessor", "setReadOnly", "setNonEnumerable", "isndarrayLike", "isBoolean", "isInteger", "ndarraylike2ndarray", "dtype", "ndarray2json", "format", "defaults", "validate", "cache", "findndindex", "generateId", "ndindex", "x", "opts", "err", "arr", "dt", "t", "id", "node", "v", "out", "require_factory", "__commonJSMin", "exports", "module", "setReadOnly", "isObject", "hasOwnProp", "format", "ndindex", "createFactory", "kind", "f", "factory", "x", "options", "opts", "require_cartesian", "__commonJSMin", "exports", "module", "createFactory", "cartesianIndex", "require_linear", "__commonJSMin", "exports", "module", "createFactory", "linearIndex", "setReadOnly", "cartesianIndex", "linearIndex", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 782d9d4..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,301 +0,0 @@ - -{{alias}}( x[, options] ) - Wraps a provided array as an ndarray index object. - - ndarray index instances have no explicit functionality; however, they are - used by "fancy" ndarrays for element retrieval and assignment. - - By default, an instance is invalidated and removed from an internal cache - immediately after a consumer resolves the underlying data associated with an - instance using the `get` static method. Immediate invalidation and cache - removal ensures that references to the underlying ndarray are not the source - of memory leaks. - - Because instances leverage an internal cache implementing the Singleton - pattern, one must be sure to use the same constructor as consumers. If one - uses a different constructor, the consumer will *not* be able to resolve the - original wrapped ndarray, as the consumer will attempt to resolve an - instance in the wrong internal cache. - - Because non-persisted instances are freed after first use, in order to avoid - holding onto memory and to allow garbage collection, one should avoid - scenarios in which an instance is never used. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - options.kind: string (optional) - Specifies whether a provided ndarray is a specialized input ndarray - "kind". This option is only applicable for integer input ndarrays. Must - be one of the following: - - - cartesian: a provided input ndarray contains Cartesian indices. - - linear: a provided input ndarray contains indices representing - locations in linear memory. - - Default: ''. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - - -{{alias}}.free( id ) - Frees the instance associated with a provided identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: boolean - Boolean indicating whether an instance was successfully freed. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.free( idx.id ) - - - -{{alias}}.get( id ) - Returns the ndarray associated with the instance having a provided - identifier. - - Parameters - ---------- - id: string - Instance identifier. - - Returns - ------- - out: Object - Object containing ndarray data. - - out.data: ndarray - The underlying ndarray associated with the provided identifier. - - out.type: string - The type of ndarray index. - - out.dtype: string - The data type of the underlying ndarray. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > {{alias}}.get( idx.id ) - {...} - - -{{alias}}.cartesianIndex( x[, options] ) - Returns an ndarray index containing Cartesian indices. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'cartesian'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.cartesianIndex( x ); - - -{{alias}}.linearIndex( x[, options] ) - Returns an ndarray index for indices representing locations in linear - memory. - - This is a convenience method for calling `{{alias}}` with `kind` set to - 'linear'. - - Parameters - ---------- - x: ndarray - Input ndarray. - - options: Object (optional) - Function options. - - options.persist: boolean (optional) - Boolean indicating whether to continue persisting an index object after - first usage. Default: false. - - Returns - ------- - out: ndindex - Index instance. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 5 ], { 'dtype': 'int32' } ); - > var idx = {{alias}}.linearIndex( x ); - - -{{alias}}.prototype.data - Read-only property returning an ndarray view of the underlying index - ndarray. - - Returns - ------- - out: ndarray - Array data. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.data - - - -{{alias}}.prototype.dtype - Read-only property returning the underlying data type of the index ndarray. - - Returns - ------- - out: string - Array data type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.dtype - 'int32' - - -{{alias}}.prototype.id - Read-only property returning the unique identifier associated with an - instance. - - Returns - ------- - out: string - String identifier. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.id - - - -{{alias}}.prototype.isCached - Read-only property returning a boolean indicating whether an ndarray index - is actively cached. - - Returns - ------- - out: boolean - Boolean indicating whether an ndarray index is actively cached. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.isCached - true - - -{{alias}}.prototype.kind - Read-only property returning the ndarray index kind. - - Returns - ------- - out: string - Index kind. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x, { 'kind': 'cartesian' } ); - > idx.kind - 'cartesian' - - -{{alias}}.prototype.type - Read-only property returning the ndarray index type. - - Returns - ------- - out: string - Index type. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.type - - - -{{alias}}.prototype.toString() - Serializes an instance as a string. - - Returns - ------- - str: string - Serialized string. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toString() - - - -{{alias}}.prototype.toJSON() - Serializes an instance as a JSON object. - - Returns - ------- - obj: Object - JSON object. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/empty}}( [ 2, 2 ], { 'dtype': 'int32' } ); - > var idx = new {{alias}}( x ); - > idx.toJSON() - { 'type': 'ndindex', ... } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index fe25284..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,303 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import empty = require( '@stdlib/ndarray-empty' ); -import ndindex = require( './index' ); - - -// TESTS // - -// The function returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const y = empty( [ 2 ], { 'dtype': 'generic' } ); - const z = empty( [ 2 ], { 'dtype': 'uint8' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - const v = empty( [ 2 ], { 'dtype': 'bool' } ); - - new ndindex( x ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y ); // $ExpectType GenericIntegerArrayIndex - new ndindex( z ); // $ExpectType MaskArrayIndex - new ndindex( w ); // $ExpectType Int32ArrayIndex - new ndindex( v ); // $ExpectType BooleanArrayIndex - - new ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - new ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - new ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - new ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - new ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - new ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex - - ndindex( x ); // $ExpectType GenericIntegerArrayIndex - ndindex( y ); // $ExpectType GenericIntegerArrayIndex - ndindex( z ); // $ExpectType MaskArrayIndex - ndindex( w ); // $ExpectType Int32ArrayIndex - ndindex( v ); // $ExpectType BooleanArrayIndex - - ndindex( x, { 'persist': true } ); // $ExpectType GenericIntegerArrayIndex - ndindex( y, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianGenericArrayIndex - ndindex( y, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearGenericArrayIndex - ndindex( z, { 'persist': true } ); // $ExpectType MaskArrayIndex - ndindex( w, { 'persist': true } ); // $ExpectType Int32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'cartesian' } ); // $ExpectType CartesianInt32ArrayIndex - ndindex( w, { 'persist': true, 'kind': 'linear' } ); // $ExpectType LinearInt32ArrayIndex - ndindex( v, { 'persist': true } ); // $ExpectType BooleanArrayIndex -} - -// The compiler throws an error if the function is provided first argument which is not a valid ndarray... -{ - ndindex( 'abc' ); // $ExpectError - ndindex( 1 ); // $ExpectError - ndindex( null ); // $ExpectError - ndindex( void 0 ); // $ExpectError - ndindex( true ); // $ExpectError - ndindex( false ); // $ExpectError - ndindex( [] ); // $ExpectError - ndindex( {} ); // $ExpectError - ndindex( [ {} ] ); // $ExpectError - ndindex( ( x: number ): number => x ); // $ExpectError - - ndindex( 'abc', {} ); // $ExpectError - ndindex( 1, {} ); // $ExpectError - ndindex( null, {} ); // $ExpectError - ndindex( void 0, {} ); // $ExpectError - ndindex( true, {} ); // $ExpectError - ndindex( false, {} ); // $ExpectError - ndindex( [], {} ); // $ExpectError - ndindex( {}, {} ); // $ExpectError - ndindex( [ {} ], {} ); // $ExpectError - ndindex( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided second argument which is not an object... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, 'abc' ); // $ExpectError - ndindex( x, 1 ); // $ExpectError - ndindex( x, null ); // $ExpectError - ndindex( x, true ); // $ExpectError - ndindex( x, false ); // $ExpectError - ndindex( x, [ {} ] ); // $ExpectError - ndindex( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex( x, { 'persist': 1 } ); // $ExpectError - ndindex( x, { 'persist': null } ); // $ExpectError - ndindex( x, { 'persist': {} } ); // $ExpectError - ndindex( x, { 'persist': [] } ); // $ExpectError - ndindex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid `kind` option... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex( x, { 'kind': 'abc' } ); // $ExpectError - ndindex( x, { 'kind': 1 } ); // $ExpectError - ndindex( x, { 'kind': null } ); // $ExpectError - ndindex( x, { 'kind': {} } ); // $ExpectError - ndindex( x, { 'kind': [] } ); // $ExpectError - ndindex( x, { 'kind': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex(); // $ExpectError - ndindex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` function which returns a boolean... -{ - ndindex.free( '0' ); // $ExpectType boolean -} - -// The compiler throws an error if the `free` method is provided first argument which is not a string... -{ - ndindex.free( 1 ); // $ExpectError - ndindex.free( null ); // $ExpectError - ndindex.free( void 0 ); // $ExpectError - ndindex.free( true ); // $ExpectError - ndindex.free( false ); // $ExpectError - ndindex.free( {} ); // $ExpectError - ndindex.free( [] ); // $ExpectError - ndindex.free( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `free` method is provided an unsupported number of arguments... -{ - ndindex.free(); // $ExpectError - ndindex.free( '0', {} ); // $ExpectError -} - -// Attached to the main export is a `get` function which returns array object data... -{ - ndindex.get( '0' ); // $ExpectType ndindexObject | null -} - -// The compiler throws an error if the `get` method is provided first argument which is not a string... -{ - ndindex.get( 1 ); // $ExpectError - ndindex.get( null ); // $ExpectError - ndindex.get( void 0 ); // $ExpectError - ndindex.get( true ); // $ExpectError - ndindex.get( false ); // $ExpectError - ndindex.get( {} ); // $ExpectError - ndindex.get( [] ); // $ExpectError - ndindex.get( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `get` method is provided an unsupported number of arguments... -{ - ndindex.get(); // $ExpectError - ndindex.get( '0', {} ); // $ExpectError -} - -// An array index has a `dtype` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.dtype; // $ExpectType "generic" -} - -// An array index has an `id` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.id; // $ExpectType string -} - -// An array index has a `type` property which returns a string... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.type; // $ExpectType "int" -} - -// An array index has a `data` property which returns a ndarray... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'uint8' } ) ); - - x.data; // $ExpectType uint8ndarray -} - -// An array index has an `isCached` property which returns a boolean... -{ - const x = new ndindex( empty( [ 2 ], { 'dtype': 'generic' } ) ); - - x.isCached; // $ExpectType boolean -} - -// Attached to the main export is a `cartesianIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.cartesianIndex( x ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w ); // $ExpectType CartesianInt32ArrayIndex - - ndindex.cartesianIndex( x, { 'persist': true } ); // $ExpectType CartesianGenericArrayIndex - ndindex.cartesianIndex( w, { 'persist': true } ); // $ExpectType CartesianInt32ArrayIndex -} - -// The compiler throws an error if the `cartesianIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.cartesianIndex( 1 ); // $ExpectError - ndindex.cartesianIndex( null ); // $ExpectError - ndindex.cartesianIndex( void 0 ); // $ExpectError - ndindex.cartesianIndex( true ); // $ExpectError - ndindex.cartesianIndex( false ); // $ExpectError - ndindex.cartesianIndex( {} ); // $ExpectError - ndindex.cartesianIndex( [] ); // $ExpectError - ndindex.cartesianIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': null } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.cartesianIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `cartesianIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.cartesianIndex(); // $ExpectError - ndindex.cartesianIndex( x, {}, {} ); // $ExpectError -} - -// Attached to the main export is a `linearIndex` function which returns an array index... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - const w = empty( [ 2 ], { 'dtype': 'int32' } ); - - ndindex.linearIndex( x ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w ); // $ExpectType LinearInt32ArrayIndex - - ndindex.linearIndex( x, { 'persist': true } ); // $ExpectType LinearGenericArrayIndex - ndindex.linearIndex( w, { 'persist': true } ); // $ExpectType LinearInt32ArrayIndex -} - -// The compiler throws an error if the `linearIndex` method is provided first argument which is not a valid ndarray... -{ - ndindex.linearIndex( 1 ); // $ExpectError - ndindex.linearIndex( null ); // $ExpectError - ndindex.linearIndex( void 0 ); // $ExpectError - ndindex.linearIndex( true ); // $ExpectError - ndindex.linearIndex( false ); // $ExpectError - ndindex.linearIndex( {} ); // $ExpectError - ndindex.linearIndex( [] ); // $ExpectError - ndindex.linearIndex( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided `persist` option which is not a boolean... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex( x, { 'persist': 'abc' } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': 1 } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': null } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': {} } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': [] } ); // $ExpectError - ndindex.linearIndex( x, { 'persist': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `linearIndex` method is provided an unsupported number of arguments... -{ - const x = empty( [ 2 ], { 'dtype': 'generic' } ); - - ndindex.linearIndex(); // $ExpectError - ndindex.linearIndex( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a49375f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var empty = require( '@stdlib/ndarray-empty' ); -var ndindex = require( './../lib' ); - -var x = empty( [ 5 ], { - 'dtype': 'uint8' -}); -var i = new ndindex( x ); -// returns - -var o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'generic' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'bool' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); - -x = empty( [ 5 ], { - 'dtype': 'int32' -}); -i = new ndindex( x ); -// returns - -o = ndindex.get( i.id ); -// returns {...} - -console.log( 'Type: %s. Data type: %s.', o.type, o.dtype ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 3dff510..9d9579b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { GenericBooleanIndexArray, GenericIntegerIndexArray, IndexArray, MaskArrayIndex, BooleanArrayIndex, Int32ArrayIndex, GenericBooleanArrayIndex, GenericIntegerArrayIndex, CartesianInt32ArrayIndex, CartesianGenericArrayIndex, LinearInt32ArrayIndex, LinearGenericArrayIndex, ndindex, BaseIndexArrayObject, ndindexObject, IndexArrayKinds, uint8ndarray, int32ndarray, booleanndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..57a098f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.3-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2ndarray@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-json@v0.1.1-esm/index.mjs";import{factory as f}from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-contains@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/dstructs-linked-list@v0.1.1-esm/index.mjs";var v=["linear","cartesian"],u=f(v);var j=new m;function c(e){for(var t=j.first();t;){if(t.value.id===e)return t;t=t.next}return null}var y=-1;function w(i){var h,f,m,c,g,b;if(!(this instanceof w))return arguments.length>1?new w(i,arguments[1]):new w(i);if(!d(i))throw new TypeError(n("2515t",i));if(h={persist:!1,kind:""},arguments.length>1&&(f=function(e,i){return t(i)?r(i,"persist")&&(e.persist=i.persist,!o(e.persist))?new TypeError(n("2512o","persist",e.persist)):r(i,"kind")&&(e.kind=i.kind,!u(e.kind)&&""!==e.kind)?new TypeError(n("2514S","kind",v.join('", "'),e.kind)):null:new TypeError(n("2512V",i))}(h,arguments[1]),f))throw f;if(m=l(i),"generic"===(c=p(m)))if(m.length>0)if(b=m.iget(0),o(b))g="bool";else{if(!a(b))throw new TypeError(n("251HG"));g="int"}else g="int";else if("int64"===c||"int32"===c)g="int";else if("uint8"===c)g="mask";else{if("bool"!==c)throw new TypeError(n("251HG"));g="bool"}if("int"!==g&&""!==h.kind)throw new TypeError(n("251HM",g,h.kind));return j.push({id:(y+=1).toString(),ref:this,data:m,type:g,kind:h.kind,dtype:c,persist:h.persist}),e(this,"_node",j.last()),s(this,"_invalidated",!1),this}function g(i){var s=function(e){var s,d;if(d={kind:i},arguments.length<2)return new w(e,d);if(s=arguments[1],!t(s))throw new TypeError(n("2512V",s));r(s,"persist")&&(d.persist=s.persist);return new w(e,d)};return e(s,"free",w.free),e(s,"get",w.get),s}e(w,"name","ndindex"),e(w,"free",(function(t){var r,n;return null!==(r=c(t))&&(n=r.value,e(n.ref,"_invalidated",!0),j.remove(r),n.data=null,!0)})),e(w,"get",(function(e){var t,r,n;return null===(t=c(e))?null:(r={data:(n=t.value).data,type:n.type,kind:n.kind,dtype:n.dtype},n.persist||w.free(e),r)})),i(w.prototype,"data",(function(){if(this._invalidated)throw new Error(n("251HH"));return this._node.value.data})),i(w.prototype,"dtype",(function(){if(this._invalidated)throw new Error(n("251HH"));return this._node.value.dtype})),i(w.prototype,"id",(function(){if(this._invalidated)throw new Error(n("251HH"));return this._node.value.id})),i(w.prototype,"isCached",(function(){return!this._invalidated})),i(w.prototype,"kind",(function(){if(this._invalidated)throw new Error(n("251HH"));return this._node.value.kind})),i(w.prototype,"type",(function(){if(this._invalidated)throw new Error(n("251HH"));return this._node.value.type})),e(w.prototype,"toString",(function(){if(this._invalidated)throw new Error(n("251HH"));return"ndindex<"+this._node.value.id+">"})),e(w.prototype,"toJSON",(function(){if(this._invalidated)throw new Error(n("251HH"));return{type:"ndindex",kind:this._node.value.kind,data:h(this._node.value.data)}}));var b=g("cartesian"),k=g("linear");e(w,"cartesianIndex",b),e(w,"linearIndex",k);const{free:x}=w,{get:_}=w;export{b as cartesianIndex,w as default,x as free,_ as get,k as linearIndex}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bb2f2cf --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/validate.js","../lib/cache.js","../lib/find.js","../lib/id.js","../lib/main.js","../lib/defaults.js","../lib/factory.js","../lib/cartesian.js","../lib/linear.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { factory as contains } from '@stdlib/array-base-assert-contains';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport KINDS from './kinds.json';\n\n\n// VARIABLES //\n\nvar isKind = contains( KINDS );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'persist': false\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '2512V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\topts.persist = options.persist;\n\t\tif ( !isBoolean( opts.persist ) ) {\n\t\t\treturn new TypeError( format( '2512o', 'persist', opts.persist ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'kind' ) ) {\n\t\topts.kind = options.kind;\n\t\tif ( !isKind( opts.kind ) && opts.kind !== '' ) {\n\t\t\treturn new TypeError( format( '2514S', 'kind', KINDS.join( '\", \"' ), opts.kind ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 LinkedList from '@stdlib/dstructs-linked-list';\n\n\n// MAIN //\n\n/**\n* Cache for storing index objects.\n*\n* @private\n* @name cache\n* @type {LinkedList}\n*/\nvar cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects\n\n\n// EXPORTS //\n\nexport default cache;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 cache from './cache.js';\n\n\n// MAIN //\n\n/**\n* Returns an index object associated with a specified identifier.\n*\n* @private\n* @param {*} id - identifier\n* @returns {(Node|null)} index object\n*/\nfunction find( id ) { // eslint-disable-line stdlib/no-redeclare\n\tvar node = cache.first();\n\twhile ( node ) {\n\t\tif ( node.value.id === id ) {\n\t\t\treturn node;\n\t\t}\n\t\tnode = node.next;\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default find;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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// VARIABLES //\n\nvar COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc).\n\n\n// MAIN //\n\n/**\n* Generates a new identifier.\n*\n* @private\n* @returns {string} identifier\n*\n* @example\n* var v = id();\n* // returns \n*/\nfunction id() {\n\tCOUNTER += 1;\n\treturn COUNTER.toString();\n}\n\n\n// EXPORTS //\n\nexport default id;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* eslint-disable no-restricted-syntax, no-invalid-this */\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnlyAccessor from '@stdlib/utils-define-nonenumerable-read-only-accessor';\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport ndarraylike2ndarray from '@stdlib/ndarray-base-ndarraylike2ndarray';\nimport dtype from '@stdlib/ndarray-base-dtype';\nimport ndarray2json from '@stdlib/ndarray-to-json';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport defaults from './defaults.js';\nimport validate from './validate.js';\nimport cache from './cache.js';\nimport findndindex from './find.js';\nimport generateId from './id.js';\n\n\n// MAIN //\n\n/**\n* ndarray index constructor.\n*\n* @constructor\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} first argument must be compatible with a specified index \"kind\"\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\nfunction ndindex( x ) {\n\tvar opts;\n\tvar err;\n\tvar arr;\n\tvar dt;\n\tvar t;\n\tvar v;\n\tif ( !(this instanceof ndindex) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ndindex( x, arguments[ 1 ] );\n\t\t}\n\t\treturn new ndindex( x );\n\t}\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '2515t', x ) );\n\t}\n\t// Resolve index options:\n\topts = defaults();\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, arguments[ 1 ] );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Normalize the input ndarray-like object by converting to a \"base\" ndarray:\n\tarr = ndarraylike2ndarray( x );\n\n\t// Resolve the input ndarray data type:\n\tdt = dtype( arr ); // note: as we've normalized to a \"base\" ndarray, there should always be a resolved data type\n\n\t// When provided a \"generic\" ndarray, attempt to infer the type of index ndarray...\n\tif ( dt === 'generic' ) {\n\t\tif ( arr.length > 0 ) {\n\t\t\tv = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget`\n\n\t\t\t// Infer the \"type\" of index array from the first element...\n\t\t\tif ( isBoolean( v ) ) {\n\t\t\t\tt = 'bool';\n\t\t\t} else if ( isInteger( v ) ) {\n\t\t\t\tt = 'int';\n\t\t\t} else {\n\t\t\t\tthrow new TypeError( format('251HG') );\n\t\t\t}\n\t\t} else {\n\t\t\t// If we've been provided an empty ndarray, fallback to a default index type:\n\t\t\tt = 'int';\n\t\t}\n\t} else if ( dt === 'int64' || dt === 'int32' ) {\n\t\tt = 'int';\n\t} else if ( dt === 'uint8' ) {\n\t\tt = 'mask';\n\t} else if ( dt === 'bool' ) {\n\t\tt = 'bool';\n\t} else {\n\t\tthrow new TypeError( format('251HG') );\n\t}\n\tif ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized \"kinds\"\n\t\tthrow new TypeError( format( '251HM', t, opts.kind ) );\n\t}\n\t// Add the ndarray index to the index cache:\n\tcache.push({\n\t\t'id': generateId(),\n\t\t'ref': this,\n\t\t'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer\n\t\t'type': t,\n\t\t'kind': opts.kind,\n\t\t'dtype': dt,\n\t\t'persist': opts.persist\n\t});\n\n\t// Store a reference to the cache node:\n\tsetReadOnly( this, '_node', cache.last() );\n\n\t// Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed):\n\tsetNonEnumerable( this, '_invalidated', false );\n\n\treturn this;\n}\n\n/**\n* Constructor name.\n*\n* @name name\n* @memberof ndindex\n* @readonly\n* @type {string}\n* @default 'ndindex'\n*\n* @example\n* var str = ndindex.name;\n* // returns 'ndindex'\n*/\nsetReadOnly( ndindex, 'name', 'ndindex' );\n\n/**\n* Frees an ndarray index object associated with a provided identifier.\n*\n* @name free\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {boolean} boolean indicating whether an index object was successfully freed\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var out = ndindex.free( idx.id );\n* // returns true\n*/\nsetReadOnly( ndindex, 'free', function free( id ) {\n\tvar node;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn false;\n\t}\n\tv = node.value;\n\n\t// Invalidate the index instance object:\n\tsetReadOnly( v.ref, '_invalidated', true );\n\n\t// Remove the index instance from the cache:\n\tcache.remove( node );\n\n\t// Remove the reference to the cached ndarray:\n\tv.data = null;\n\n\treturn true;\n});\n\n/**\n* Returns the ndarray associated with a provided identifier.\n*\n* @name get\n* @memberof ndindex\n* @type {Function}\n* @param {string} id - identifier\n* @returns {(Object|null)} object containing index data\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x, {\n* 'persist': true\n* });\n* // returns \n*\n* // ...\n*\n* var o = ndindex.get( idx.id );\n* // returns {...}\n*\n* var d = o.data;\n* // returns \n*\n* var t = o.type;\n* // returns 'mask'\n*\n* var dt = o.dtype;\n* // returns 'uint8'\n*/\nsetReadOnly( ndindex, 'get', function get( id ) {\n\tvar node;\n\tvar out;\n\tvar v;\n\n\t// Retrieve the index object with the specified identifier:\n\tnode = findndindex( id );\n\tif ( node === null ) {\n\t\treturn null;\n\t}\n\tv = node.value;\n\n\t// Assemble the output object:\n\tout = {\n\t\t'data': v.data,\n\t\t'type': v.type,\n\t\t'kind': v.kind,\n\t\t'dtype': v.dtype\n\t};\n\n\t// If the index object should not be persisted, go ahead and remove the object from the cache...\n\tif ( !v.persist ) {\n\t\tndindex.free( id ); // note: this should come last, after having retrieved all desired index node data\n\t}\n\treturn out;\n});\n\n/**\n* Returns the underlying data of an ndarray index object.\n*\n* @name data\n* @memberof ndindex.prototype\n* @readonly\n* @type {ndarray}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var v = idx.data;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'data', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn this._node.value.data;\n});\n\n/**\n* Returns the underlying data type of an ndarray index object.\n*\n* @name dtype\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.dtype;\n* // returns 'uint8'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'dtype', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn this._node.value.dtype;\n});\n\n/**\n* Returns the identifier associated with an ndarray index object.\n*\n* @name id\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var id = idx.id;\n* // returns \n*/\nsetReadOnlyAccessor( ndindex.prototype, 'id', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn this._node.value.id;\n});\n\n/**\n* Returns a boolean indicating if an ndarray index object is actively cached.\n*\n* @name isCached\n* @memberof ndindex.prototype\n* @readonly\n* @type {boolean}\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var out = idx.isCached;\n* // returns true\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'isCached', function get() {\n\treturn !this._invalidated;\n});\n\n/**\n* Returns the ndarray index object \"kind\".\n*\n* @name kind\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = new ndindex( x, {\n* 'kind': 'linear'\n* });\n* // returns \n*\n* var v = idx.kind;\n* // returns 'linear'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'kind', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn this._node.value.kind;\n});\n\n/**\n* Returns the type of an ndarray index object.\n*\n* @name type\n* @memberof ndindex.prototype\n* @readonly\n* @type {string}\n* @throws {Error} index object is no longer valid\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var t = idx.type;\n* // returns 'mask'\n*/\nsetReadOnlyAccessor( ndindex.prototype, 'type', function get() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn this._node.value.type;\n});\n\n/**\n* Serializes an ndarray index object to a string.\n*\n* @name toString\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {string} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var str = idx.toString();\n* // e.g., 'ndindex<0>'\n*/\nsetReadOnly( ndindex.prototype, 'toString', function toString() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn 'ndindex<' + this._node.value.id + '>';\n});\n\n/**\n* Serializes an ndarray index object as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance.\n*\n* @name toJSON\n* @memberof ndindex.prototype\n* @type {Function}\n* @throws {Error} index object is no longer valid\n* @returns {Object} serialized index object\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*\n* var o = idx.toJSON();\n* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} }\n*/\nsetReadOnly( ndindex.prototype, 'toJSON', function toJSON() {\n\tif ( this._invalidated ) {\n\t\tthrow new Error( format('251HH') );\n\t}\n\treturn {\n\t\t'type': 'ndindex',\n\t\t'kind': this._node.value.kind,\n\t\t'data': ndarray2json( this._node.value.data )\n\t};\n});\n\n\n// EXPORTS //\n\nexport default ndindex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} defaults\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'persist': false,\n\t\t'kind': ''\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndindex from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating ndarray index objects having a specified \"kind\".\n*\n* @private\n* @param {string} kind - specialized index kind\n* @returns {Function} factory function\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var cartesianIndex = createFactory( 'cartesian' );\n* // returns \n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nfunction createFactory( kind ) {\n\tvar f = factory;\n\tsetReadOnly( f, 'free', ndindex.free ); // `free` is a static method\n\tsetReadOnly( f, 'get', ndindex.get ); // `get` is a static method\n\treturn f;\n\n\t/**\n\t* Returns an ndarray index having a specialized \"kind\".\n\t*\n\t* @private\n\t* @param {ndarray} x - input ndarray\n\t* @param {Options} [options] - function options\n\t* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n\t* @throws {TypeError} first argument must be an ndarray-like object\n\t* @throws {TypeError} first argument must be a valid index ndarray\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ndindex} ndindex instance\n\t*/\n\tfunction factory( x ) {\n\t\tvar options;\n\t\tvar opts;\n\n\t\topts = {\n\t\t\t'kind': kind\n\t\t};\n\t\tif ( arguments.length < 2 ) {\n\t\t\treturn new ndindex( x, opts );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '2512V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'persist' ) ) {\n\t\t\topts.persist = options.persist;\n\t\t}\n\t\treturn new ndindex( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default createFactory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index containing Cartesian indices.\n*\n* @name cartesianIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 3, 2 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = cartesianIndex( x );\n* // returns \n*/\nvar cartesianIndex = createFactory( 'cartesian' );\n\n\n// EXPORTS //\n\nexport default cartesianIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 createFactory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an ndarray index for indices representing locations in linear memory.\n*\n* @name linearIndex\n* @type {Function}\n* @param {ndarray} x - input ndarray\n* @param {Options} [options] - function options\n* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage\n* @throws {TypeError} first argument must be an ndarray-like object\n* @throws {TypeError} first argument must be a valid index ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ndindex} ndindex instance\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'int32'\n* });\n*\n* var idx = linearIndex( x );\n* // returns \n*/\nvar linearIndex = createFactory( 'linear' );\n\n\n// EXPORTS //\n\nexport default linearIndex;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* ndarray index constructor.\n*\n* @module @stdlib/ndarray-index\n*\n* @example\n* import empty from '@stdlib/ndarray-empty';\n* import ndindex from '@stdlib/ndarray-index';\n*\n* var x = empty( [ 10 ], {\n* 'dtype': 'uint8'\n* });\n*\n* var idx = new ndindex( x );\n* // returns \n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport cartesianIndex from './cartesian.js';\nimport linearIndex from './linear.js';\nimport main from './main.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'cartesianIndex', cartesianIndex );\nsetReadOnly( main, 'linearIndex', linearIndex );\n\n\n// EXPORTS //\n\nexport default main;\n\n// exports: { \"cartesianIndex\": \"main.cartesianIndex\", \"linearIndex\": \"main.linearIndex\", \"free\": \"main.free\", \"get\": \"main.get\" }\n"],"names":["isKind","contains","KINDS","cache","LinkedList","find","id","node","first","value","next","COUNTER","ndindex","x","opts","err","arr","dt","t","v","this","arguments","length","isndarrayLike","TypeError","format","persist","kind","options","isObject","hasOwnProp","isBoolean","join","validate","ndarraylike2ndarray","dtype","iget","isInteger","push","toString","ref","data","type","setReadOnly","last","setNonEnumerable","createFactory","f","free","get","findndindex","remove","out","setReadOnlyAccessor","prototype","_invalidated","Error","_node","ndarray2json","cartesianIndex","linearIndex","main"],"mappings":";;u8CAgCIA,EAASC,EAAUC,GCEvB,IAAIC,EAAQ,IAAIC,ECAhB,SAASC,EAAMC,GAEd,IADA,IAAIC,EAAOJ,EAAMK,QACTD,GAAO,CACd,GAAKA,EAAKE,MAAMH,KAAOA,EACtB,OAAOC,EAERA,EAAOA,EAAKG,IACZ,CACD,OAAO,IACR,CCrBA,IAAIC,GAAW,EC8Cf,SAASC,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,KAAOC,gBAAgBR,GACtB,OAAKS,UAAUC,OAAS,EAChB,IAAIV,EAASC,EAAGQ,UAAW,IAE5B,IAAIT,EAASC,GAErB,IAAMU,EAAeV,GACpB,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAIvC,GADAC,ECpDO,CACNY,SAAW,EACXC,KAAQ,IDmDJN,UAAUC,OAAS,IACvBP,EJ9BF,SAAmBD,EAAMc,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SACjBK,EAAWjB,EAAKY,UACd,IAAIF,UAAWC,EAAQ,QAAS,UAAWX,EAAKY,UAGpDI,EAAYF,EAAS,UACzBd,EAAKa,KAAOC,EAAQD,MACd3B,EAAQc,EAAKa,OAAwB,KAAdb,EAAKa,MAC1B,IAAIH,UAAWC,EAAQ,QAAS,OAAQvB,EAAM8B,KAAM,QAAUlB,EAAKa,OAGrE,KAdC,IAAIH,UAAWC,EAAQ,QAASG,GAezC,CIaQK,CAAUnB,EAAMO,UAAW,IAC5BN,GACJ,MAAMA,EAUR,GANAC,EAAMkB,EAAqBrB,GAMf,aAHZI,EAAKkB,EAAOnB,IAIX,GAAKA,EAAIM,OAAS,EAIjB,GAHAH,EAAIH,EAAIoB,KAAM,GAGTL,EAAWZ,GACfD,EAAI,WACE,KAAKmB,EAAWlB,GAGtB,MAAM,IAAIK,UAAWC,EAAO,UAF5BP,EAAI,KAGJ,MAGDA,EAAI,WAEC,GAAY,UAAPD,GAAyB,UAAPA,EAC7BC,EAAI,WACE,GAAY,UAAPD,EACXC,EAAI,WACE,IAAY,SAAPD,EAGX,MAAM,IAAIO,UAAWC,EAAO,UAF5BP,EAAI,MAGJ,CACD,GAAW,QAANA,GAA6B,KAAdJ,EAAKa,KACxB,MAAM,IAAIH,UAAWC,EAAQ,QAASP,EAAGJ,EAAKa,OAmB/C,OAhBAxB,EAAMmC,KAAK,CACVhC,ID3FDK,GAAW,GACI4B,WC2FdC,IAAOpB,KACPqB,KAAQzB,EACR0B,KAAQxB,EACRS,KAAQb,EAAKa,KACbQ,MAASlB,EACTS,QAAWZ,EAAKY,UAIjBiB,EAAavB,KAAM,QAASjB,EAAMyC,QAGlCC,EAAkBzB,KAAM,gBAAgB,GAEjCA,IACR,CE9FA,SAAS0B,EAAenB,GACvB,IAAIoB,EAkBJ,SAAkBlC,GACjB,IAAIe,EACAd,EAKJ,GAHAA,EAAO,CACNa,KAAQA,GAEJN,UAAUC,OAAS,EACvB,OAAO,IAAIV,EAASC,EAAGC,GAGxB,GADAc,EAAUP,UAAW,IACfQ,EAAUD,GACf,MAAM,IAAIJ,UAAWC,EAAQ,QAASG,IAElCE,EAAYF,EAAS,aACzBd,EAAKY,QAAUE,EAAQF,SAExB,OAAO,IAAId,EAASC,EAAGC,EACvB,EAjCD,OAFA6B,EAAaI,EAAG,OAAQnC,EAAQoC,MAChCL,EAAaI,EAAG,MAAOnC,EAAQqC,KACxBF,CAkCR,CFuEAJ,EAAa/B,EAAS,OAAQ,WA4B9B+B,EAAa/B,EAAS,QAAQ,SAAeN,GAC5C,IAAIC,EACAY,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,MAIpBa,EAAIZ,EAAKE,MAGTkC,EAAaxB,EAAEqB,IAAK,gBAAgB,GAGpCrC,EAAMgD,OAAQ5C,GAGdY,EAAEsB,KAAO,MAEF,EACR,IAqCAE,EAAa/B,EAAS,OAAO,SAAcN,GAC1C,IAAIC,EACA6C,EACAjC,EAIJ,OAAc,QADdZ,EAAO2C,EAAa5C,IAEZ,MAKR8C,EAAM,CACLX,MAJDtB,EAAIZ,EAAKE,OAIEgC,KACVC,KAAQvB,EAAEuB,KACVf,KAAQR,EAAEQ,KACVQ,MAAShB,EAAEgB,OAINhB,EAAEO,SACPd,EAAQoC,KAAM1C,GAER8C,EACR,IAwBAC,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,OAAOL,KAAKqC,MAAMhD,MAAMgC,IACzB,IAwBAY,EAAqBzC,EAAQ0C,UAAW,SAAS,WAChD,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,OAAOL,KAAKqC,MAAMhD,MAAM0B,KACzB,IAwBAkB,EAAqBzC,EAAQ0C,UAAW,MAAM,WAC7C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,OAAOL,KAAKqC,MAAMhD,MAAMH,EACzB,IAuBA+C,EAAqBzC,EAAQ0C,UAAW,YAAY,WACnD,OAAQlC,KAAKmC,YACd,IA0BAF,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,OAAOL,KAAKqC,MAAMhD,MAAMkB,IACzB,IAwBA0B,EAAqBzC,EAAQ0C,UAAW,QAAQ,WAC/C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,OAAOL,KAAKqC,MAAMhD,MAAMiC,IACzB,IAwBAC,EAAa/B,EAAQ0C,UAAW,YAAY,WAC3C,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,MAAO,WAAaL,KAAKqC,MAAMhD,MAAMH,GAAK,GAC3C,IA4BAqC,EAAa/B,EAAQ0C,UAAW,UAAU,WACzC,GAAKlC,KAAKmC,aACT,MAAM,IAAIC,MAAO/B,EAAO,UAEzB,MAAO,CACNiB,KAAQ,UACRf,KAAQP,KAAKqC,MAAMhD,MAAMkB,KACzBc,KAAQiB,EAActC,KAAKqC,MAAMhD,MAAMgC,MAEzC,IG1cG,IAACkB,EAAiBb,EAAe,aCAhCc,EAAcd,EAAe,UCJjCH,EAAAkB,EAAA,iBAAAF,GACAhB,EAAAkB,EAAA,cAAAD"} \ No newline at end of file diff --git a/lib/cache.js b/lib/cache.js deleted file mode 100644 index 468e198..0000000 --- a/lib/cache.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var LinkedList = require( '@stdlib/dstructs-linked-list' ); - - -// MAIN // - -/** -* Cache for storing index objects. -* -* @private -* @name cache -* @type {LinkedList} -*/ -var cache = new LinkedList(); // note: created as a linked list to allow for more efficient removal of expired index objects - - -// EXPORTS // - -module.exports = cache; diff --git a/lib/cache_gc.js b/lib/cache_gc.js deleted file mode 100644 index b316011..0000000 --- a/lib/cache_gc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Performs garbage collection on the index cache. -* -* @private -* @returns {Object} garbage collection results -*/ -function gc() { - var node; - var N; - var M; - var v; - - node = cache.first(); - N = cache.length; - while ( node ) { - v = node.value; - if ( !v.persist ) { - cache.remove( node ); - } - node = node.next; - } - M = cache.length; - return { - 'size': M, - 'removed': N - M - }; -} - - -// EXPORTS // - -module.exports = gc; diff --git a/lib/cartesian.js b/lib/cartesian.js deleted file mode 100644 index ae0be9d..0000000 --- a/lib/cartesian.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index containing Cartesian indices. -* -* @name cartesianIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -var cartesianIndex = createFactory( 'cartesian' ); - - -// EXPORTS // - -module.exports = cartesianIndex; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 1bbc78a..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} defaults -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'persist': false, - 'kind': '' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index c5b213d..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,95 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndindex = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating ndarray index objects having a specified "kind". -* -* @private -* @param {string} kind - specialized index kind -* @returns {Function} factory function -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var cartesianIndex = createFactory( 'cartesian' ); -* // returns -* -* var x = empty( [ 3, 2 ], { -* 'dtype': 'int32' -* }); -* -* var idx = cartesianIndex( x ); -* // returns -*/ -function createFactory( kind ) { - var f = factory; - setReadOnly( f, 'free', ndindex.free ); // `free` is a static method - setReadOnly( f, 'get', ndindex.get ); // `get` is a static method - return f; - - /** - * Returns an ndarray index having a specialized "kind". - * - * @private - * @param {ndarray} x - input ndarray - * @param {Options} [options] - function options - * @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage - * @throws {TypeError} first argument must be an ndarray-like object - * @throws {TypeError} first argument must be a valid index ndarray - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ndindex} ndindex instance - */ - function factory( x ) { - var options; - var opts; - - opts = { - 'kind': kind - }; - if ( arguments.length < 2 ) { - return new ndindex( x, opts ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '2512V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - } - return new ndindex( x, opts ); - } -} - - -// EXPORTS // - -module.exports = createFactory; diff --git a/lib/find.js b/lib/find.js deleted file mode 100644 index cde8a99..0000000 --- a/lib/find.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var cache = require( './cache.js' ); - - -// MAIN // - -/** -* Returns an index object associated with a specified identifier. -* -* @private -* @param {*} id - identifier -* @returns {(Node|null)} index object -*/ -function find( id ) { // eslint-disable-line stdlib/no-redeclare - var node = cache.first(); - while ( node ) { - if ( node.value.id === id ) { - return node; - } - node = node.next; - } - return null; -} - - -// EXPORTS // - -module.exports = find; diff --git a/lib/id.js b/lib/id.js deleted file mode 100644 index 64b99b4..0000000 --- a/lib/id.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var COUNTER = -1; // TODO: consider another approach for unique identifier generation. For most cases, this should suffice; however, it is possible that two different libraries, both relying on separate copies of this package, may trigger id collisions in the event that instantiated instances were to interact (e.g., a consumer attempting to free an instance instantiated by another copy of the package, etc). - - -// MAIN // - -/** -* Generates a new identifier. -* -* @private -* @returns {string} identifier -* -* @example -* var v = id(); -* // returns -*/ -function id() { - COUNTER += 1; - return COUNTER.toString(); -} - - -// EXPORTS // - -module.exports = id; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8e36619..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* ndarray index constructor. -* -* @module @stdlib/ndarray-index -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* var ndindex = require( '@stdlib/ndarray-index' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var cartesianIndex = require( './cartesian.js' ); -var linearIndex = require( './linear.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'cartesianIndex', cartesianIndex ); -setReadOnly( main, 'linearIndex', linearIndex ); - - -// EXPORTS // - -module.exports = main; - -// exports: { "cartesianIndex": "main.cartesianIndex", "linearIndex": "main.linearIndex", "free": "main.free", "get": "main.get" } diff --git a/lib/kinds.json b/lib/kinds.json deleted file mode 100644 index eb1a2a1..0000000 --- a/lib/kinds.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "linear", - "cartesian" -] diff --git a/lib/linear.js b/lib/linear.js deleted file mode 100644 index 218752a..0000000 --- a/lib/linear.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var createFactory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an ndarray index for indices representing locations in linear memory. -* -* @name linearIndex -* @type {Function} -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = linearIndex( x ); -* // returns -*/ -var linearIndex = createFactory( 'linear' ); - - -// EXPORTS // - -module.exports = linearIndex; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 462a8cd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,515 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-restricted-syntax, no-invalid-this */ - -'use strict'; - -// MODULES // - -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var ndarraylike2ndarray = require( '@stdlib/ndarray-base-ndarraylike2ndarray' ); -var dtype = require( '@stdlib/ndarray-base-dtype' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var cache = require( './cache.js' ); -var findndindex = require( './find.js' ); -var generateId = require( './id.js' ); - - -// MAIN // - -/** -* ndarray index constructor. -* -* @constructor -* @param {ndarray} x - input ndarray -* @param {Options} [options] - function options -* @param {boolean} [options.persist=false] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind=''] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} first argument must be a valid index ndarray -* @throws {TypeError} first argument must be compatible with a specified index "kind" -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ndindex} ndindex instance -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -*/ -function ndindex( x ) { - var opts; - var err; - var arr; - var dt; - var t; - var v; - if ( !(this instanceof ndindex) ) { - if ( arguments.length > 1 ) { - return new ndindex( x, arguments[ 1 ] ); - } - return new ndindex( x ); - } - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '2515t', x ) ); - } - // Resolve index options: - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, arguments[ 1 ] ); - if ( err ) { - throw err; - } - } - // Normalize the input ndarray-like object by converting to a "base" ndarray: - arr = ndarraylike2ndarray( x ); - - // Resolve the input ndarray data type: - dt = dtype( arr ); // note: as we've normalized to a "base" ndarray, there should always be a resolved data type - - // When provided a "generic" ndarray, attempt to infer the type of index ndarray... - if ( dt === 'generic' ) { - if ( arr.length > 0 ) { - v = arr.iget( 0 ); // note: we assume that, even for zero-dimensional ndarrays, we can pass `0` as an argument to `#.iget` - - // Infer the "type" of index array from the first element... - if ( isBoolean( v ) ) { - t = 'bool'; - } else if ( isInteger( v ) ) { - t = 'int'; - } else { - throw new TypeError( format('251HG') ); - } - } else { - // If we've been provided an empty ndarray, fallback to a default index type: - t = 'int'; - } - } else if ( dt === 'int64' || dt === 'int32' ) { - t = 'int'; - } else if ( dt === 'uint8' ) { - t = 'mask'; - } else if ( dt === 'bool' ) { - t = 'bool'; - } else { - throw new TypeError( format('251HG') ); - } - if ( t !== 'int' && opts.kind !== '' ) { // note: here we assume that only integer ndarrays can have specialized "kinds" - throw new TypeError( format( '251HM', t, opts.kind ) ); - } - // Add the ndarray index to the index cache: - cache.push({ - 'id': generateId(), - 'ref': this, - 'data': arr, // note: while we cache a reference to the normalized ndarray object, and not the original input ndarray-like object, we still hold onto memory, as the normalized object references the same underlying data buffer - 'type': t, - 'kind': opts.kind, - 'dtype': dt, - 'persist': opts.persist - }); - - // Store a reference to the cache node: - setReadOnly( this, '_node', cache.last() ); - - // Initialize a boolean flag indicating whether an index object has been invalidated (i.e., freed): - setNonEnumerable( this, '_invalidated', false ); - - return this; -} - -/** -* Constructor name. -* -* @name name -* @memberof ndindex -* @readonly -* @type {string} -* @default 'ndindex' -* -* @example -* var str = ndindex.name; -* // returns 'ndindex' -*/ -setReadOnly( ndindex, 'name', 'ndindex' ); - -/** -* Frees an ndarray index object associated with a provided identifier. -* -* @name free -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {boolean} boolean indicating whether an index object was successfully freed -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var out = ndindex.free( idx.id ); -* // returns true -*/ -setReadOnly( ndindex, 'free', function free( id ) { - var node; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return false; - } - v = node.value; - - // Invalidate the index instance object: - setReadOnly( v.ref, '_invalidated', true ); - - // Remove the index instance from the cache: - cache.remove( node ); - - // Remove the reference to the cached ndarray: - v.data = null; - - return true; -}); - -/** -* Returns the ndarray associated with a provided identifier. -* -* @name get -* @memberof ndindex -* @type {Function} -* @param {string} id - identifier -* @returns {(Object|null)} object containing index data -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x, { -* 'persist': true -* }); -* // returns -* -* // ... -* -* var o = ndindex.get( idx.id ); -* // returns {...} -* -* var d = o.data; -* // returns -* -* var t = o.type; -* // returns 'mask' -* -* var dt = o.dtype; -* // returns 'uint8' -*/ -setReadOnly( ndindex, 'get', function get( id ) { - var node; - var out; - var v; - - // Retrieve the index object with the specified identifier: - node = findndindex( id ); - if ( node === null ) { - return null; - } - v = node.value; - - // Assemble the output object: - out = { - 'data': v.data, - 'type': v.type, - 'kind': v.kind, - 'dtype': v.dtype - }; - - // If the index object should not be persisted, go ahead and remove the object from the cache... - if ( !v.persist ) { - ndindex.free( id ); // note: this should come last, after having retrieved all desired index node data - } - return out; -}); - -/** -* Returns the underlying data of an ndarray index object. -* -* @name data -* @memberof ndindex.prototype -* @readonly -* @type {ndarray} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var v = idx.data; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'data', function get() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return this._node.value.data; -}); - -/** -* Returns the underlying data type of an ndarray index object. -* -* @name dtype -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.dtype; -* // returns 'uint8' -*/ -setReadOnlyAccessor( ndindex.prototype, 'dtype', function get() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return this._node.value.dtype; -}); - -/** -* Returns the identifier associated with an ndarray index object. -* -* @name id -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var id = idx.id; -* // returns -*/ -setReadOnlyAccessor( ndindex.prototype, 'id', function get() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return this._node.value.id; -}); - -/** -* Returns a boolean indicating if an ndarray index object is actively cached. -* -* @name isCached -* @memberof ndindex.prototype -* @readonly -* @type {boolean} -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var out = idx.isCached; -* // returns true -*/ -setReadOnlyAccessor( ndindex.prototype, 'isCached', function get() { - return !this._invalidated; -}); - -/** -* Returns the ndarray index object "kind". -* -* @name kind -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'int32' -* }); -* -* var idx = new ndindex( x, { -* 'kind': 'linear' -* }); -* // returns -* -* var v = idx.kind; -* // returns 'linear' -*/ -setReadOnlyAccessor( ndindex.prototype, 'kind', function get() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return this._node.value.kind; -}); - -/** -* Returns the type of an ndarray index object. -* -* @name type -* @memberof ndindex.prototype -* @readonly -* @type {string} -* @throws {Error} index object is no longer valid -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var t = idx.type; -* // returns 'mask' -*/ -setReadOnlyAccessor( ndindex.prototype, 'type', function get() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return this._node.value.type; -}); - -/** -* Serializes an ndarray index object to a string. -* -* @name toString -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {string} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var str = idx.toString(); -* // e.g., 'ndindex<0>' -*/ -setReadOnly( ndindex.prototype, 'toString', function toString() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return 'ndindex<' + this._node.value.id + '>'; -}); - -/** -* Serializes an ndarray index object as a JSON object. -* -* ## Notes -* -* - `JSON.stringify()` implicitly calls this method when stringifying an `ndindex` instance. -* -* @name toJSON -* @memberof ndindex.prototype -* @type {Function} -* @throws {Error} index object is no longer valid -* @returns {Object} serialized index object -* -* @example -* var empty = require( '@stdlib/ndarray-empty' ); -* -* var x = empty( [ 10 ], { -* 'dtype': 'uint8' -* }); -* -* var idx = new ndindex( x ); -* // returns -* -* var o = idx.toJSON(); -* // returns { 'type': 'ndindex', 'kind': '', 'data': {...} } -*/ -setReadOnly( ndindex.prototype, 'toJSON', function toJSON() { - if ( this._invalidated ) { - throw new Error( format('251HH') ); - } - return { - 'type': 'ndindex', - 'kind': this._node.value.kind, - 'data': ndarray2json( this._node.value.data ) - }; -}); - - -// EXPORTS // - -module.exports = ndindex; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index a8ce124..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var contains = require( '@stdlib/array-base-assert-contains' ).factory; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var KINDS = require( './kinds.json' ); - - -// VARIABLES // - -var isKind = contains( KINDS ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.persist] - boolean indicating whether to continue persisting an index object after first usage -* @param {string} [options.kind] - specifies whether a provided ndarray is a specialized kind of integer input ndarray -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'persist': false -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '2512V', options ) ); - } - if ( hasOwnProp( options, 'persist' ) ) { - opts.persist = options.persist; - if ( !isBoolean( opts.persist ) ) { - return new TypeError( format( '2512o', 'persist', opts.persist ) ); - } - } - if ( hasOwnProp( options, 'kind' ) ) { - opts.kind = options.kind; - if ( !isKind( opts.kind ) && opts.kind !== '' ) { - return new TypeError( format( '2514S', 'kind', KINDS.join( '", "' ), opts.kind ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9ea6042..fc7fd4c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.1", "description": "ndarray index constructor.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "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,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-contains": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/dstructs-linked-list": "^0.1.1", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-ndarraylike2ndarray": "^0.1.1", - "@stdlib/ndarray-to-json": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.4", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-to-accessor-array": "^0.2.3", - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-method": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-zeros": "^0.3.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..10694e4 --- /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.cartesian.js b/test/test.cartesian.js deleted file mode 100644 index af7a189..0000000 --- a/test/test.cartesian.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var cartesianIndex = require( './../lib/cartesian.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cartesianIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = cartesianIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = cartesianIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = cartesianIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = cartesianIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = cartesianIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = cartesianIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = cartesianIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - cartesianIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - cartesianIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = cartesianIndex( x, { - 'persist': true - }); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = cartesianIndex( x ); - - id = idx.id; - cartesianIndex.free( id ); - actual = cartesianIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = cartesianIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0fa9ffa..0000000 --- a/test/test.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isMethod = require( '@stdlib/assert-is-method' ); -var ndindex = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `cartesianIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'cartesianIndex' ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the main export is a `linearIndex` method', function test( t ) { - t.strictEqual( isMethod( ndindex, 'linearIndex' ), true, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.linear.js b/test/test.linear.js deleted file mode 100644 index 5331fa1..0000000 --- a/test/test.linear.js +++ /dev/null @@ -1,589 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndindex = require( './../lib/main.js' ); -var linearIndex = require( './../lib/linear.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof linearIndex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - - ]; - 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 v = linearIndex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ), - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = linearIndex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = linearIndex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an ndindex instance', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - t.strictEqual( instanceOf( idx, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = linearIndex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = linearIndex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = linearIndex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = linearIndex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - linearIndex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - linearIndex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the function is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = linearIndex( x, { - 'persist': true - }); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = linearIndex( x ); - - id = idx.id; - linearIndex.free( id ); - actual = linearIndex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = linearIndex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index ac21698..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,2053 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Float64Array = require( '@stdlib/array-float64' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2json = require( '@stdlib/ndarray-to-json' ); -var ndindex = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndindex, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function is a constructor', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function is a constructor (options)', function test( t ) { - var opts; - var x; - - opts = { - 'dtype': 'generic' - }; - x = new ndindex( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = new ndindex( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ) ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function does not require the `new` keyword (options)', function test( t ) { - var opts; - var idx; - var x; - - idx = ndindex; - - opts = { - 'dtype': 'generic' - }; - x = idx( array( [ 1, 2, 3 ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( [ true, false, true ], opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( toAccessorArray( [ 1, 2, 3 ] ), opts ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Uint8Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new BooleanArray( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - x = idx( array( new Int32Array( [ 1, 0, 1 ] ) ), {} ); - t.strictEqual( instanceOf( x, ndindex ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', 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() { - var v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (options)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( [ 'a', 'b', 'c' ], opts ), - array( new Float64Array( [ 1.0, 2.0, 3.0 ] ) ), - array( [ 1.5, 2.5, 3.5 ], opts ), - array( [ null ], opts ) - ]; - 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 v = new ndindex( value, {} ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=cartesian)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'cartesian' - }); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not a valid index ndarray (kind=linear)', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - array( new BooleanArray( 5 ) ), - array( [ true, false, true, false ], opts ), - array( new Uint8Array( 5 ) ) - ]; - 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 v = new ndindex( value, { // eslint-disable-line no-unused-vars - 'kind': 'linear' - }); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), value ); // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var opts; - var i; - - opts = { - 'dtype': 'generic' - }; - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var v = new ndindex( array( [ 1, 2, 3 ], opts ), { // eslint-disable-line no-unused-vars - 'persist': value - }); - }; - } -}); - -tape( 'the function returns an instance having a `data` property which returns an ndarray view of underlying index ndarray', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isndarrayLike( idx.data ), true, 'returns expected value' ); - t.strictEqual( idx.data.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `data` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.data; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `dtype` property which returns the underlying index ndarray data type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'uint8', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'generic', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.dtype, 'int32', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `dtype` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.dtype; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `id` property which returns the ndarray index identifier', function test( t ) { - var opts; - var obj; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( isString( idx.id ), true, 'returns expected value' ); - - // Should assign unique identifiers... - obj = {}; - for ( i = 0; i < 100; i++ ) { - idx = new ndindex( array( [ 1, 2, 3 ], opts ) ); - if ( obj[ idx.id ] === void 0 ) { - obj[ idx.id ] = true; - } else { - t.fail( 'should not return a duplicate id: ' + idx.id ); - } - } - t.end(); -}); - -tape( 'the function returns an instance having an `id` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.id; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having an `isCached` property which returns a boolean indicating whether an ndarray index is actively cached', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.kind, '', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.kind, 'cartesian', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which returns the ndarray index kind (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.kind, 'linear', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `kind` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.kind; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'mask', 'returns expected value' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'bool', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=cartesian)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which returns the ndarray index type (kind=linear)', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( [], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - t.strictEqual( idx.type, 'int', 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a `type` property which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Uint8Array( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new BooleanArray( [ 0, 1, 0, 1 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - var v = idx.type; // eslint-disable-line no-unused-vars - }; - } -}); - -tape( 'the function returns an instance having a custom `toString` method', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( /ndindex<[^>]+>/.test( idx.toString() ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns an instance having a custom `toString` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toString(); - }; - } -}); - -tape( 'the function returns an instance having a custom `toJSON` method', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x ); - - expected = { - 'type': 'ndindex', - 'kind': '', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'cartesian', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3, 4 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'type': 'ndindex', - 'kind': 'linear', - 'data': ndarray2json( x ) - }; - actual = idx.toJSON(); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an instance having a custom `toJSON` method which throws an error if an instance has been invalidated', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - ndindex.get( idx.id ); - t.throws( invalidated( idx ), Error, 'throws an error' ); - - t.end(); - - function invalidated( idx ) { - return function invalidated() { - idx.toJSON(); - }; - } -}); - -tape( 'attached to the constructor is a `name` property', function test( t ) { - t.strictEqual( ndindex.name, 'ndindex', 'returns expected value' ); - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (non-persisted)', function test( t ) { - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method to free an actively cached index ndarray (persisted)', function test( t ) { - var actual; - var ndopts; - var opts; - var idx; - var x; - - ndopts = { - 'dtype': 'generic' - }; - opts = { - 'persist': true - }; - - x = array( [ 1, 2, 3 ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ true, false, true, false ], ndopts ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, opts ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - actual = ndindex.free( idx.id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `free` method which returns `false` if an index ndarray has already been freed', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - - // Generic: - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Generic (persisted): - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Accessor: - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Boolean: - x = array( new BooleanArray( [ true, false, true, false ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Mask: - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - // Integer: - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - id = idx.id; - actual = ndindex.free( id ); - t.strictEqual( actual, true, 'returns expected value' ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - actual = ndindex.free( id ); - t.strictEqual( actual, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'bool', - 'kind': '', - 'dtype': 'bool' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'mask', - 'kind': '', - 'dtype': 'uint8' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - expected = { - 'data': x, - 'type': 'int', - 'kind': '', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=cartesian)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'cartesian' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'cartesian', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method to return index ndarray data (kind=linear)', function test( t ) { - var expected; - var actual; - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true, - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'generic' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x, { - 'kind': 'linear' - }); - - expected = { - 'data': x, - 'type': 'int', - 'kind': 'linear', - 'dtype': 'int32' - }; - actual = ndindex.get( idx.id ); - t.strictEqual( actual.type, expected.type, 'returns expected value' ); - t.strictEqual( actual.kind, expected.kind, 'returns expected value' ); - t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' ); - t.strictEqual( actual.data.data, expected.data.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which frees non-persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': false - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which does not free persisted index ndarrays', function test( t ) { - var opts; - var idx; - var x; - var i; - - opts = { - 'dtype': 'generic' - }; - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - t.strictEqual( idx.isCached, true, 'returns expected value' ); - - for ( i = 0; i < 100; i++ ) { - ndindex.get( idx.id ); - t.strictEqual( idx.isCached, true, 'returns expected value' ); - } - ndindex.free( idx.id ); - t.strictEqual( idx.isCached, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the constructor is a `get` method which returns `null` if unable to resolve an index ndarray', function test( t ) { - var actual; - var opts; - var idx; - var id; - var x; - - opts = { - 'dtype': 'generic' - }; - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ 1, 2, 3 ], opts ); - idx = new ndindex( x, { - 'persist': true - }); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( toAccessorArray( [ 1, 2, 3 ] ), opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( [ true, false, true, false ], opts ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new BooleanArray( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Uint8Array( [ 1, 0, 1, 0 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - x = array( new Int32Array( [ 1, 2, 3 ] ) ); - idx = new ndindex( x ); - - id = idx.id; - ndindex.free( id ); - actual = ndindex.get( id ); - t.strictEqual( actual, null, 'returns expected value' ); - - actual = ndindex.get( '??beep_boop_foo_bar!!' ); - t.strictEqual( actual, null, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 878e880..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an options object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `persist` option which is not a boolean', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'persist': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an invalid `kind` option', function test( t ) { - var values; - var err; - var i; - - values = [ - 'foo', - 'bar', - '5', - 5, - true, - false, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'kind': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns an error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var expected; - var options; - var opts; - var err; - - options = { - 'persist': true, - 'kind': 'linear' - }; - opts = {}; - - expected = { - 'persist': true, - 'kind': 'linear' - }; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function ignores unrecognized options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': 'boop', - 'foo': 5, - 'bar': {} - }; - - opts = {}; - - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'returns expected value' ); - - t.end(); -});