From 936279e0611987a647f9cdccb7e91edc274b2604 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Apr 2026 15:38:17 +0500 Subject: [PATCH 1/8] feat: add blas/ext/to-sorted --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/to-sorted/README.md | 209 ++ .../to-sorted/benchmark/benchmark.assign.js | 111 + .../blas/ext/to-sorted/benchmark/benchmark.js | 104 + .../@stdlib/blas/ext/to-sorted/docs/repl.txt | 115 + .../blas/ext/to-sorted/docs/types/index.d.ts | 273 +++ .../blas/ext/to-sorted/docs/types/test.ts | 363 +++ .../blas/ext/to-sorted/examples/index.js | 37 + .../@stdlib/blas/ext/to-sorted/lib/assign.js | 98 + .../@stdlib/blas/ext/to-sorted/lib/index.js | 70 + .../@stdlib/blas/ext/to-sorted/lib/main.js | 132 ++ .../@stdlib/blas/ext/to-sorted/package.json | 64 + .../blas/ext/to-sorted/test/test.assign.js | 2019 +++++++++++++++++ .../@stdlib/blas/ext/to-sorted/test/test.js | 39 + .../blas/ext/to-sorted/test/test.main.js | 1905 ++++++++++++++++ 14 files changed, 5539 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md new file mode 100644 index 000000000000..7ef60699488f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md @@ -0,0 +1,209 @@ + + +# toSorted + +> Return a new [ndarray][@stdlib/ndarray/ctor] containing the elements of an input [ndarray][@stdlib/ndarray/ctor] sorted along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var toSorted = require( '@stdlib/blas/ext/to-sorted' ); +``` + +#### toSorted( x\[, sortOrder]\[, options] ) + +Returns a new [ndarray][@stdlib/ndarray/ctor] containing the elements of an input [ndarray][@stdlib/ndarray/ctor] sorted along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); + +var y = toSorted( x ); +// returns [ -3.0, -1.0, 2.0 ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **sortOrder**: sort order (_optional_). May be either a scalar value, string, or an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] sort order must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] sort order must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the sort order is `1` (i.e., increasing order). +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. + +By default, the function sorts elements in increasing order. To sort in a different order, provide a `sortOrder` argument. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); + +var y = toSorted( x, -1.0 ); +// returns [ 2.0, -1.0, -3.0 ] +``` + +In addition to numeric values, one can specify the sort order via one of the following string literals: `'ascending'`, `'asc'`, `'descending'`, or `'desc'`. The first two literals indicate to sort in ascending (i.e., increasing) order. The last two literals indicate to sort in descending (i.e., decreasing) order. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); + +// Sort in ascending order: +var y = toSorted( x, 'asc' ); +// returns [ -3.0, -1.0, 2.0 ] + +// Sort in descending order: +y = toSorted( x, 'descending' ); +// returns [ 2.0, -1.0, -3.0 ] +``` + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var y = toSorted( x, { + 'dims': [ 0 ] +}); +// returns [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ] +``` + +To specify the output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes], provide a `dtype` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); + +var y = toSorted( x, { + 'dtype': 'float32' +}); +// returns [ -3.0, -1.0, 2.0 ] +``` + +#### toSorted.assign( x, out\[, sortOrder]\[, options] ) + +Sorts the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns the results to an output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var y = zeros( [ 3 ] ); + +var out = toSorted.assign( x, y ); +// returns [ -3.0, -1.0, 2.0 ] + +var bool = ( y === out ); +// returns true +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **sortOrder**: sort order (_optional_). May be either a scalar value, string, or an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] sort order must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] sort order must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the sort order is `1` (i.e., increasing order). +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **increasing** order. If `sortOrder == 0.0`, the input [ndarray][@stdlib/ndarray/ctor] is left unchanged. +- The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. +- The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. +- The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before sorting. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toSorted = require( '@stdlib/blas/ext/to-sorted' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = toSorted( x, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( out ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..46b96082d327 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assign = require( './../lib/assign.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var y; + + x = uniform( [ len ], -50.0, 50.0, options ); + y = zeros( [ len ], { + 'dtype': options.dtype + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = assign( x, y, ( i%2 ) ? 1 : -1 ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( y.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js new file mode 100644 index 000000000000..634df1bdf68f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var toSorted = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( [ len ], -50.0, 50.0, options ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = toSorted( x, ( i%2 ) ? 1 : -1 ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt new file mode 100644 index 000000000000..0c0d5f2a5272 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt @@ -0,0 +1,115 @@ + +{{alias}}( x[, sortOrder][, options] ) + Returns a new ndarray containing the elements of an input ndarray sorted + along one or more ndarray dimensions. + + The algorithm distinguishes between `-0` and `+0`. When sorted in increasing + order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is + sorted after `+0`. + + The algorithm sorts `NaN` values to the end. When sorted in increasing + order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` + values are sorted first. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + sortOrder: ndarray|number|string (optional) + Sort order. May be either a scalar value, string, or an ndarray having a + real-valued or "generic" data type. If provided an ndarray, the value + must have a shape which is broadcast compatible with the complement of + the shape defined by `options.dims`. For example, given the input shape + `[2, 3, 4]` and `options.dims=[0]`, an ndarray sort order must have a + shape which is broadcast compatible with the shape `[3, 4]`. Similarly, + when performing the operation over all elements in a provided input + ndarray, an ndarray sort order must be a zero-dimensional ndarray. + + If specified as a string, must be one of the following values: + + - ascending: sort in increasing order. + - asc: sort in increasing order. + - descending: sort in decreasing order. + - desc: sort in decreasing order. + + By default, the sort order is `1` (i.e., increasing order). + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + options.dtype: string|DataType (optional) + Output array data type. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var out = {{alias}}( x ) + [ -4.0, -3.0, -1.0, 2.0 ] + + +{{alias}}.assign( x, out[, sortOrder][, options] ) + Sorts elements of an input ndarray along one or more ndarray dimensions and + assigns the results to an output ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + out: ndarray + Output array. Must have a real-valued or "generic" data type. + + sortOrder: ndarray|number|string (optional) + Sort order. May be either a scalar value, string, or an ndarray having a + real-valued or "generic" data type. If provided an ndarray, the value + must have a shape which is broadcast compatible with the complement of + the shape defined by `options.dims`. For example, given the input shape + `[2, 3, 4]` and `options.dims=[0]`, an ndarray sort order must have a + shape which is broadcast compatible with the shape `[3, 4]`. Similarly, + when performing the operation over all elements in a provided input + ndarray, an ndarray sort order must be a zero-dimensional ndarray. + + If specified as a string, must be one of the following values: + + - ascending: sort in increasing order. + - asc: sort in increasing order. + - descending: sort in decreasing order. + - desc: sort in decreasing order. + + By default, the sort order is `1` (i.e., increasing order). + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var y = {{alias:@stdlib/ndarray/zeros}}( [ 4 ] ); + > var out = {{alias}}.assign( x, y ) + [ -4.0, -3.0, -1.0, 2.0 ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts new file mode 100644 index 000000000000..578f44d0931c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts @@ -0,0 +1,273 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; +import { RealAndGenericDataType as DataType, typedndarray, realndarray, genericndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = realndarray | genericndarray; + +/** +* Output array. +*/ +type OutputArray = realndarray | genericndarray; + +/** +* Sort order. +*/ +type SortOrder = typedndarray | genericndarray | number | 'descending' | 'desc' | 'ascending' | 'asc'; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output ndarray data type. + */ + dtype: DataType; +} + +/** +* Interface for performing an operation on an ndarray. +*/ +interface ToSorted { + /** + * Returns a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var out = toSorted( x ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + */ + ( x: T, options?: BaseOptions ): T; + + /** + * Returns a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var out = toSorted( x ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + */ + ( x: T, options?: Options ): U; // NOTE: we lose type specificity here. We can likely address this with type maps + + /** + * Returns a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param sortOrder - sort order + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var out = toSorted( x, 1.0 ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + */ + ( x: T, sortOrder: SortOrder, options?: BaseOptions ): T; + + /** + * Returns a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param sortOrder - sort order + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var out = toSorted( x, 1.0 ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + */ + ( x: T, sortOrder: SortOrder, options?: Options ): U; // NOTE: we lose type specificity here. We can likely address this with type maps + + /** + * Sorts the elements in an input ndarray along along one or more ndarray dimensions and assigns the results to an output ndarray. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var y = zeros( [ 3, 1, 2 ] ); + * // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] + * + * var out = toSorted.assign( x, y ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + * + * var bool = ( out === y ); + * // returns true + */ + assign( x: T, out: U, options?: BaseOptions ): U; + + /** + * Sorts the elements in an input ndarray along along one or more ndarray dimensions and assigns the results to an output ndarray. + * + * ## Notes + * + * - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. + * - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. + * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. + * + * @param x - input ndarray + * @param out - output ndarray + * @param sortOrder - sort order + * @param options - function options + * @returns output ndarray + * + * @example + * var zeros = require( '@stdlib/ndarray/zeros' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); + * // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] + * + * var y = zeros( [ 3, 1, 2 ] ); + * // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] + * + * var out = toSorted.assign( x, y, 1 ); + * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] + * + * var bool = ( out === y ); + * // returns true + */ + assign( x: T, out: U, sortOrder: SortOrder, options?: BaseOptions ): U; +} + +/** +* Returns a new ndarray with the elements of an input ndarray sorted along one or more ndarray dimensions. +* +* ## Notes +* +* - If `sortOrder < 0.0` or is either `'desc'` or `'descending'`, the input ndarray is sorted in **decreasing** order. If `sortOrder > 0.0` or is either `'asc'` or `'ascending'`, the input ndarray is sorted in **increasing** order. If `sortOrder == 0.0`, the input ndarray is left unchanged. +* - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. +* - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. +* +* @param x - input ndarray +* @param sortOrder - sort order +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var out = toSorted( x, 1.0 ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var y = zeros( [ 3, 1, 2 ] ); +* // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] +* +* var out = toSorted.assign( x, y ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const toSorted: ToSorted; + + +// EXPORTS // + +export = toSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts new file mode 100644 index 000000000000..2150dc358383 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts @@ -0,0 +1,363 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import toSorted = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted( x ); // $ExpectType float64ndarray + toSorted( x, 1.0 ); // $ExpectType float64ndarray + toSorted( x, {} ); // $ExpectType float64ndarray + toSorted( x, 1.0, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + toSorted( '5' ); // $ExpectError + toSorted( 5 ); // $ExpectError + toSorted( true ); // $ExpectError + toSorted( false ); // $ExpectError + toSorted( null ); // $ExpectError + toSorted( void 0 ); // $ExpectError + toSorted( {} ); // $ExpectError + toSorted( ( x: number ): number => x ); // $ExpectError + + toSorted( '5', 1.0 ); // $ExpectError + toSorted( 5, 1.0 ); // $ExpectError + toSorted( true, 1.0 ); // $ExpectError + toSorted( false, 1.0 ); // $ExpectError + toSorted( null, 1.0 ); // $ExpectError + toSorted( void 0, 1.0 ); // $ExpectError + toSorted( {}, 1.0 ); // $ExpectError + toSorted( ( x: number ): number => x, 1.0 ); // $ExpectError + + toSorted( '5', {} ); // $ExpectError + toSorted( 5, {} ); // $ExpectError + toSorted( true, {} ); // $ExpectError + toSorted( false, {} ); // $ExpectError + toSorted( null, {} ); // $ExpectError + toSorted( void 0, {} ); // $ExpectError + toSorted( {}, {} ); // $ExpectError + toSorted( ( x: number ): number => x, {} ); // $ExpectError + + toSorted( '5', 1.0, {} ); // $ExpectError + toSorted( 5, 1.0, {} ); // $ExpectError + toSorted( true, 1.0, {} ); // $ExpectError + toSorted( false, 1.0, {} ); // $ExpectError + toSorted( null, 1.0, {} ); // $ExpectError + toSorted( void 0, 1.0, {} ); // $ExpectError + toSorted( {}, 1.0, {} ); // $ExpectError + toSorted( ( x: number ): number => x, 1.0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sort order argument which is not an ndarray, supported string literal, or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted( x, true ); // $ExpectError + toSorted( x, false ); // $ExpectError + toSorted( x, [] ); // $ExpectError + toSorted( x, ( x: number ): number => x ); // $ExpectError + + toSorted( x, 'foo', {} ); // $ExpectError + toSorted( x, true, {} ); // $ExpectError + toSorted( x, false, {} ); // $ExpectError + toSorted( x, null, {} ); // $ExpectError + toSorted( x, void 0, {} ); // $ExpectError + toSorted( x, [], {} ); // $ExpectError + toSorted( x, {}, {} ); // $ExpectError + toSorted( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted( x, true ); // $ExpectError + toSorted( x, false ); // $ExpectError + toSorted( x, [] ); // $ExpectError + toSorted( x, ( x: number ): number => x ); // $ExpectError + + toSorted( x, 1.0, '5' ); // $ExpectError + toSorted( x, 1.0, true ); // $ExpectError + toSorted( x, 1.0, false ); // $ExpectError + toSorted( x, 1.0, null ); // $ExpectError + toSorted( x, 1.0, [] ); // $ExpectError + toSorted( x, 1.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted( x, { 'dtype': '5' } ); // $ExpectError + toSorted( x, { 'dtype': 5 } ); // $ExpectError + toSorted( x, { 'dtype': true } ); // $ExpectError + toSorted( x, { 'dtype': false } ); // $ExpectError + toSorted( x, { 'dtype': null } ); // $ExpectError + toSorted( x, { 'dtype': [] } ); // $ExpectError + toSorted( x, { 'dtype': {} } ); // $ExpectError + toSorted( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError + + toSorted( x, 1.0, { 'dtype': '5' } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': 5 } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': true } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': false } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': null } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': [] } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': {} } ); // $ExpectError + toSorted( x, 1.0, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted( x, { 'dims': '5' } ); // $ExpectError + toSorted( x, { 'dims': 5 } ); // $ExpectError + toSorted( x, { 'dims': true } ); // $ExpectError + toSorted( x, { 'dims': false } ); // $ExpectError + toSorted( x, { 'dims': null } ); // $ExpectError + toSorted( x, { 'dims': {} } ); // $ExpectError + toSorted( x, { 'dims': ( x: number ): number => x } ); // $ExpectError + + toSorted( x, 1.0, { 'dims': '5' } ); // $ExpectError + toSorted( x, 1.0, { 'dims': 5 } ); // $ExpectError + toSorted( x, 1.0, { 'dims': true } ); // $ExpectError + toSorted( x, 1.0, { 'dims': false } ); // $ExpectError + toSorted( x, 1.0, { 'dims': null } ); // $ExpectError + toSorted( x, 1.0, { 'dims': {} } ); // $ExpectError + toSorted( x, 1.0, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted(); // $ExpectError + toSorted( x, 10.0, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, y ); // $ExpectType float64ndarray + toSorted.assign( x, y, 1.0 ); // $ExpectType float64ndarray + toSorted.assign( x, y, {} ); // $ExpectType float64ndarray + toSorted.assign( x, y, 1.0, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( '5', y ); // $ExpectError + toSorted.assign( 5, y ); // $ExpectError + toSorted.assign( true, y ); // $ExpectError + toSorted.assign( false, y ); // $ExpectError + toSorted.assign( null, y ); // $ExpectError + toSorted.assign( void 0, y ); // $ExpectError + toSorted.assign( {}, y ); // $ExpectError + toSorted.assign( ( x: number ): number => x, y ); // $ExpectError + + toSorted.assign( '5', y, 1.0 ); // $ExpectError + toSorted.assign( 5, y, 1.0 ); // $ExpectError + toSorted.assign( true, y, 1.0 ); // $ExpectError + toSorted.assign( false, y, 1.0 ); // $ExpectError + toSorted.assign( null, y, 1.0 ); // $ExpectError + toSorted.assign( void 0, y, 1.0 ); // $ExpectError + toSorted.assign( {}, y, 1.0 ); // $ExpectError + toSorted.assign( ( x: number ): number => x, y, 1.0 ); // $ExpectError + + toSorted.assign( '5', y, {} ); // $ExpectError + toSorted.assign( 5, y, {} ); // $ExpectError + toSorted.assign( true, y, {} ); // $ExpectError + toSorted.assign( false, y, {} ); // $ExpectError + toSorted.assign( null, y, {} ); // $ExpectError + toSorted.assign( void 0, y, {} ); // $ExpectError + toSorted.assign( {}, y, {} ); // $ExpectError + toSorted.assign( ( x: number ): number => x, y, {} ); // $ExpectError + + toSorted.assign( '5', y, 1.0, {} ); // $ExpectError + toSorted.assign( 5, y, 1.0, {} ); // $ExpectError + toSorted.assign( true, y, 1.0, {} ); // $ExpectError + toSorted.assign( false, y, 1.0, {} ); // $ExpectError + toSorted.assign( null, y, 1.0, {} ); // $ExpectError + toSorted.assign( void 0, y, 1.0, {} ); // $ExpectError + toSorted.assign( {}, y, 1.0, {} ); // $ExpectError + toSorted.assign( ( x: number ): number => x, y, 1.0, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, '5' ); // $ExpectError + toSorted.assign( x, 5 ); // $ExpectError + toSorted.assign( x, true ); // $ExpectError + toSorted.assign( x, false ); // $ExpectError + toSorted.assign( x, null ); // $ExpectError + toSorted.assign( x, void 0 ); // $ExpectError + toSorted.assign( x, {} ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x ); // $ExpectError + + toSorted.assign( x, '5', 1.0 ); // $ExpectError + toSorted.assign( x, 5, 1.0 ); // $ExpectError + toSorted.assign( x, true, 1.0 ); // $ExpectError + toSorted.assign( x, false, 1.0 ); // $ExpectError + toSorted.assign( x, null, 1.0 ); // $ExpectError + toSorted.assign( x, void 0, 1.0 ); // $ExpectError + toSorted.assign( x, {}, 1.0 ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x, 1.0 ); // $ExpectError + + toSorted.assign( x, '5', {} ); // $ExpectError + toSorted.assign( x, 5, {} ); // $ExpectError + toSorted.assign( x, true, {} ); // $ExpectError + toSorted.assign( x, false, {} ); // $ExpectError + toSorted.assign( x, null, {} ); // $ExpectError + toSorted.assign( x, void 0, {} ); // $ExpectError + toSorted.assign( x, {}, {} ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x, {} ); // $ExpectError + + toSorted.assign( x, '5', 1.0, {} ); // $ExpectError + toSorted.assign( x, 5, 1.0, {} ); // $ExpectError + toSorted.assign( x, true, 1.0, {} ); // $ExpectError + toSorted.assign( x, false, 1.0, {} ); // $ExpectError + toSorted.assign( x, null, 1.0, {} ); // $ExpectError + toSorted.assign( x, void 0, 1.0, {} ); // $ExpectError + toSorted.assign( x, {}, 1.0, {} ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x, 1.0, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sort order argument which is not an ndarray, supported string literal, or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, y, true ); // $ExpectError + toSorted.assign( x, y, false ); // $ExpectError + toSorted.assign( x, y, [] ); // $ExpectError + toSorted.assign( x, y, ( x: number ): number => x ); // $ExpectError + + toSorted.assign( x, y, 'foo', {} ); // $ExpectError + toSorted.assign( x, y, true, {} ); // $ExpectError + toSorted.assign( x, y, false, {} ); // $ExpectError + toSorted.assign( x, y, null, {} ); // $ExpectError + toSorted.assign( x, y, void 0, {} ); // $ExpectError + toSorted.assign( x, y, [], {} ); // $ExpectError + toSorted.assign( x, y, {}, {} ); // $ExpectError + toSorted.assign( x, y, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a options argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, y, true ); // $ExpectError + toSorted.assign( x, y, false ); // $ExpectError + toSorted.assign( x, y, [] ); // $ExpectError + toSorted.assign( x, y, ( x: number ): number => x ); // $ExpectError + + toSorted.assign( x, y, 1.0, '5' ); // $ExpectError + toSorted.assign( x, y, 1.0, true ); // $ExpectError + toSorted.assign( x, y, 1.0, false ); // $ExpectError + toSorted.assign( x, y, 1.0, null ); // $ExpectError + toSorted.assign( x, y, 1.0, [] ); // $ExpectError + toSorted.assign( x, y, 1.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, y, { 'dims': '5' } ); // $ExpectError + toSorted.assign( x, y, { 'dims': 5 } ); // $ExpectError + toSorted.assign( x, y, { 'dims': true } ); // $ExpectError + toSorted.assign( x, y, { 'dims': false } ); // $ExpectError + toSorted.assign( x, y, { 'dims': null } ); // $ExpectError + toSorted.assign( x, y, { 'dims': {} } ); // $ExpectError + toSorted.assign( x, y, { 'dims': ( x: number ): number => x } ); // $ExpectError + + toSorted.assign( x, y, 1.0, { 'dims': '5' } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': 5 } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': true } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': false } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': null } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': {} } ); // $ExpectError + toSorted.assign( x, y, 1.0, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign(); // $ExpectError + toSorted.assign( x ); // $ExpectError + toSorted.assign( x, y, 10.0, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/examples/index.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/examples/index.js new file mode 100644 index 000000000000..23641b1ea7a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toSorted = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var out = toSorted( x, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( out ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js new file mode 100644 index 000000000000..9c3d88ea1cf2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var copy = require( '@stdlib/ndarray/base/assign' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var sort = require( '@stdlib/blas/ext/sort' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Sorts the elements of an input ndarray along one or more ndarray dimensions and assigns the results to an output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @param {ndarrayLike} y - output ndarray +* @param {(ndarrayLike|number|string)} [sortOrder=1.0] - sort order +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} sort order argument must be either an ndarray-like object, a numeric value, or a supported string +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {TypeError} first argument cannot be safely cast to the data type of the second argument +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var y = zeros( [ 3, 1, 2 ] ); +* // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] +* +* var out = assign( x, y ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, y ) { + var nargs; + var xdt; + var ydt; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( !isndarrayLike( y ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', y ) ); + } + xdt = getDType( x ); + ydt = getDType( y ); + if ( !isMostlySafeCast( xdt, ydt ) ) { + throw new TypeError( format( 'invalid argument. First argument cannot be safely cast to the output data type. Data types: [%s, %s].', resolveStr( xdt ), resolveStr( ydt ) ) ); + } + nargs = arguments.length; + copy( [ x, y ] ); + if ( nargs <= 2 ) { + return sort( y ); + } + if ( nargs === 3 ) { + return sort( y, arguments[ 2 ] ); + } + // nargs > 3 + return sort( y, arguments[ 2 ], arguments[ 3 ] ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/index.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/index.js new file mode 100644 index 000000000000..db099b286909 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/index.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. +* +* @module @stdlib/blas/ext/to-sorted +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var toSorted = require( '@stdlib/blas/ext/to-sorted' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var out = toSorted( x ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var array = require( '@stdlib/ndarray/array' ); +* var toSorted = require( '@stdlib/blas/ext/to-sorted' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var y = zeros( [ 3, 1, 2 ] ); +* // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] +* +* var out = toSorted.assign( x, y ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +* +* var bool = ( y === out ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/main.js new file mode 100644 index 000000000000..df4584ad182f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/main.js @@ -0,0 +1,132 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var empty = require( '@stdlib/ndarray/empty' ); +var assign = require( '@stdlib/ndarray/base/assign' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var sort = require( '@stdlib/blas/ext/sort' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number|string)} [sortOrder=1.0] - sort order +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} sort order argument must be either an ndarray-like object, a numeric value, or a supported string +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] ); +* // returns [ [ [ 1.0, 2.0 ] ], [ [ -3.0, 4.0 ] ], [ [ -5.0, 6.0 ] ] ] +* +* var out = toSorted( x ); +* // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] +*/ +function toSorted( x ) { + var sortOrder; + var options; + var nargs; + var xdt; + var ydt; + var y; + var o; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + nargs = arguments.length; + o = arguments[ 1 ]; + + // Case: toSorted( x ) + if ( nargs < 2 ) { + sortOrder = 1; + } + // Case: toSorted( x, ??? ) + else if ( nargs === 2 ) { + // Case: toSorted( x, sortOrder_string || sortOrder_scalar || sortOrder_ndarray ) ) + if ( isString( o ) || isNumber( o ) || isndarrayLike( o ) ) { + sortOrder = o; + } + // Case: toSorted( x, options ) + else { + sortOrder = 1; + options = o; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + } + } + // Case: toSorted( x, sortOrder, options ) + else if ( nargs >= 3 ) { + sortOrder = o; + options = arguments[ 2 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + } + xdt = getDType( x ); + if ( options && hasOwnProp( options, 'dtype' ) ) { + ydt = options.dtype; + if ( !isMostlySafeCast( xdt, ydt ) ) { + throw new TypeError( format( 'invalid argument. First argument cannot be safely cast to the output data type. Data types: [%s, %s].', resolveStr( xdt ), resolveStr( ydt ) ) ); + } + } else { + ydt = xdt; + } + // Create an output ndarray: + y = empty( getShape( x ), { + 'dtype': ydt, + 'order': getOrder( x ) + }); + + // Copy elements from the input ndarray to the output ndarray: + assign( [ x, y ] ); + + return sort( y, sortOrder, options || {} ); +} + + +// EXPORTS // + +module.exports = toSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/package.json b/lib/node_modules/@stdlib/blas/ext/to-sorted/package.json new file mode 100644 index 000000000000..82927b48c551 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/blas/ext/to-sorted", + "version": "0.0.0", + "description": "Return a new ndarray containing the elements of an input ndarray sorted along one or more ndarray dimensions.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "arrange", + "sort", + "sorted", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js new file mode 100644 index 000000000000..0e330b7fd6fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js @@ -0,0 +1,2019 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var assign = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=scalar)', 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() { + assign( value, zeros( [ 2, 2 ] ), 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=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() { + assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=scalar, 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() { + assign( value, zeros( [ 2, 2 ] ), 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=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() { + assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type (sortOrder=scalar)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type (sortOrder=ndarray)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type (sortOrder=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which does not have a supported data type (sortOrder=ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=scalar)', 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() { + assign( zeros( [ 2, 2 ] ), value, 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=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() { + assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=scalar, 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() { + assign( zeros( [ 2, 2 ] ), value, 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=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() { + assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=scalar)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=ndarray)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument having dimensions greater than or less than the dimensions of input ndarray', function test( t ) { + var values; + var i; + + values = [ + zeros( [ 2 ] ), + zeros( [ 2, 1 ] ), + zeros( [ 3, 3 ] ), + zeros( [ 2, 2, 2 ] ), + zeros( [ 2, 2, 2, 2 ] ), + zeros( [ 2, 2, 2, 2, 2 ] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( zeros( [ 2, 2 ] ), value ); + }; + } +}); + +tape( 'the function throws an error if the input ndarray cannot be safely cast to the output ndarray data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + zeros( [ 2, 2 ], { + 'dtype': 'int8' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int16' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int32' + }), + zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }), + zeros( [ 2, 2 ], { + 'dtype': 'uint8c' + }), + zeros( [ 2, 2 ], { + 'dtype': 'uint16' + }), + zeros( [ 2, 2 ], { + 'dtype': 'uint32' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided an output ndarray having dtype ' + values[ i ].dtype ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a support string', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + 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() { + assign( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a support string (options)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + 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() { + assign( x, y, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + assign( x, y, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (sortOrder=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + '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() { + assign( x, y, 1.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + 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() { + assign( x, y, scalar2ndarray( 1.0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + assign( x, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (sortOrder=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + assign( x, y, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + assign( x, y, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var y; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var y; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + y = zeros( [ 2, 2 ], opts ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + assign( x, y, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y ); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y, { + 'dims': [ 0, 1 ] + }); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, { + 'dims': [ 0, 1 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y, { + 'dims': [] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts the input ndarray and assigns results to an output ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, { + 'dims': [] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = assign( x, y, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = assign( x, y, { + 'dims': [ 1 ] + }); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, 1.0 ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, -1.0 ); + expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, 1.0, {} ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, -1.0, {} ); + expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, 0.0, {} ); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + var y; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, scalar2ndarray( 1.0, opts ) ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( -1.0, opts ) ); + expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( 0.0, opts ) ); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + var y; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, scalar2ndarray( 1.0, opts ), {} ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( -1.0, opts ), {} ); + expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( 0.0, opts ), {} ); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, 1.0, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, -1.0, { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, 0.0, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + var y; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + actual = assign( x, y, scalar2ndarray( 1.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( -1.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + actual = assign( x, y, scalar2ndarray( 0.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (string literals)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y, 'asc' ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = assign( x, y, 'ascending' ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = assign( x, y, 'desc' ); + expected = [ [ 4.0, 2.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = assign( x, y, 'descending' ); + expected = [ [ 4.0, 2.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (string literals, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var y; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + actual = assign( x, y, 'asc', {} ); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = assign( x, y, 'descending', { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 4.0 ], [ -3.0, 2.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (ndarray)', function test( t ) { + var sortOrder; + var expected; + var actual; + var xbuf; + var obuf; + var opts; + var x; + var y; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + obuf = [ 1.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = assign( x, y, sortOrder, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 4.0 ], [ -1.0, 2.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'column-major' + }); + + obuf = [ 1.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = assign( x, y, sortOrder, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 4.0 ], [ 2.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, -2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + y = zeros( [ 2, 2 ], { + 'dtype': 'generic', + 'order': 'row-major' + }); + + obuf = [ 0.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = assign( x, y, sortOrder, { + 'dims': [ 1 ] + }); + expected = [ [ 1.0, -2.0 ], [ 4.0, -3.0 ] ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.js new file mode 100644 index 000000000000..3b0e889d18e6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF 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 toSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( toSorted, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js new file mode 100644 index 000000000000..d9104343a68e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js @@ -0,0 +1,1905 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF 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 isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int8Array = require( '@stdlib/array/int8' ); +var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var toSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=scalar)', 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() { + toSorted( value, 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=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() { + toSorted( value, scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=scalar, 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() { + toSorted( value, 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (sortOrder=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() { + toSorted( value, scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (sortOrder=scalar)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, 1.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (sortOrder=ndarray)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, scalar2ndarray( 1.0 ) ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (sortOrder=scalar, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, 1.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (sortOrder=ndarray, options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( value, scalar2ndarray( 1.0 ), {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a supported string', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + 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() { + toSorted( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a supported string (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'invalid', + 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() { + toSorted( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `sortOrder` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + toSorted( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + '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() { + toSorted( x, 1.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + 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() { + toSorted( x, scalar2ndarray( 1.0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, 1.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (sortOrder=ndarray)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'generic' + }; + x = zeros( [ 2, 2 ], opts ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, scalar2ndarray( 1.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, 1.0, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option (sortOrder=string)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, 'asc', { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option (sortOrder=ndarray)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 'foo', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + toSorted( x, scalar2ndarray( 1.0 ), { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if the input ndarray cannot be safely cast to the output data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + 'int8', + 'int16', + 'int32', + 'uint8', + 'uint8c', + 'uint16', + 'uint32' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if the input ndarray cannot be safely cast to the output data type (sortOrder=scalar)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + 'int8', + 'int16', + 'int32', + 'uint8', + 'uint8c', + 'uint16', + 'uint32' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, 1.0, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if the input ndarray cannot be safely cast to the output data type (sortOrder=string)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + 'int8', + 'int16', + 'int32', + 'uint8', + 'uint8c', + 'uint16', + 'uint32' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, 'asc', { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if the input ndarray cannot be safely cast to the output data type (sortOrder=ndarray)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + values = [ + 'int8', + 'int16', + 'int32', + 'uint8', + 'uint8c', + 'uint16', + 'uint32' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toSorted( x, scalar2ndarray( 1.0 ), { + 'dtype': value + }); + }; + } +}); + +tape( 'the function returns a sorted ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a sorted ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a sorted ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, { + 'dims': [ 0, 1 ] + }); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a sorted ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, { + 'dims': [ 0, 1 ] + }); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a sorted ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, { + 'dims': [] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a sorted ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, { + 'dims': [] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, { + 'dims': [ 1 ] + }); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 1.0 ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = toSorted( x, -1.0 ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 1.0, {} ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = toSorted( x, -1.0, {} ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 0.0, {} ); + expected = [ -1.0, 2.0, -3.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, scalar2ndarray( 1.0, opts ) ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( -1.0, opts ) ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( 0.0, opts ) ); + expected = [ -1.0, 2.0, -3.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, scalar2ndarray( 1.0, opts ), {} ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( -1.0, opts ), {} ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( 0.0, opts ), {} ); + expected = [ -1.0, 2.0, -3.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 1.0, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, -1.0, { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, 0.0, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, scalar2ndarray( 1.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( -1.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = toSorted( x, scalar2ndarray( 0.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (string literals)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'asc' ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'ascending' ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'desc' ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'descending' ); + expected = [ 4.0, 2.0, -1.0, -3.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (string literals, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'asc', {} ); + expected = [ -3.0, -1.0, 2.0, 4.0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'descending', { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 4.0 ], [ -3.0, 2.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a `sortOrder` argument (ndarray)', function test( t ) { + var sortOrder; + var expected; + var actual; + var xbuf; + var obuf; + var opts; + var x; + + opts = { + 'dtype': 'generic' + }; + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + obuf = [ 1.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = toSorted( x, sortOrder, { + 'dims': [ 0 ] + }); + expected = [ [ -3.0, 4.0 ], [ -1.0, 2.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + obuf = [ 1.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = toSorted( x, sortOrder, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 4.0 ], [ 2.0, -3.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, -2.0, -3.0, 4.0 ]; + x = new ndarray( opts.dtype, xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + obuf = [ 0.0, -1.0 ]; + sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = toSorted( x, sortOrder, { + 'dims': [ 1 ] + }); + expected = [ [ 1.0, -2.0 ], [ 4.0, -3.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an output data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float32Array( [ -1.0, 2.0, -3.0, 4.0 ] ); + x = new ndarray( 'float32', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, { + 'dtype': 'float64' + }); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( resolveStr( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an output data type (sortOrder=scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Float64Array( [ -1.0, 2.0, -3.0, 4.0 ] ); + x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 1.0, { + 'dtype': 'float32' + }); + expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( resolveStr( getDType( actual ) ), 'float32', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an output data type (sortOrder=string)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Int8Array( [ -1, 2, -3, 4 ] ); + x = new ndarray( 'int8', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = toSorted( x, 'desc', { + 'dtype': 'int32' + }); + expected = [ [ 4, 2 ], [ -1, -3 ] ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( resolveStr( getDType( actual ) ), 'int32', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From de575b5c72dc0f28a899fcdf7f75c337182e0510 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Apr 2026 17:13:22 +0500 Subject: [PATCH 2/8] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/to-sorted/README.md | 4 +- .../to-sorted/benchmark/benchmark.assign.js | 2 +- .../@stdlib/blas/ext/to-sorted/docs/repl.txt | 8 +- .../blas/ext/to-sorted/docs/types/index.d.ts | 6 +- .../blas/ext/to-sorted/docs/types/test.ts | 162 ++++++++-------- .../@stdlib/blas/ext/to-sorted/lib/assign.js | 105 +++++++++-- .../blas/ext/to-sorted/test/test.assign.js | 174 +++++++----------- 7 files changed, 242 insertions(+), 219 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md index 7ef60699488f..58c55f44e653 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/README.md @@ -110,7 +110,7 @@ var y = toSorted( x, { // returns [ -3.0, -1.0, 2.0 ] ``` -#### toSorted.assign( x, out\[, sortOrder]\[, options] ) +#### toSorted.assign( x\[, sortOrder], out\[, options] ) Sorts the elements of an input [ndarray][@stdlib/ndarray/ctor] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns the results to an output [ndarray][@stdlib/ndarray/ctor]. @@ -131,8 +131,8 @@ var bool = ( y === out ); The function has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. -- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. - **sortOrder**: sort order (_optional_). May be either a scalar value, string, or an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] sort order must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] sort order must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the sort order is `1` (i.e., increasing order). +- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. - **options**: function options (_optional_). The function accepts the following options: diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js index 46b96082d327..192240fdbc68 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js @@ -69,7 +69,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = assign( x, y, ( i%2 ) ? 1 : -1 ); + o = assign( x, ( i%2 ) ? 1 : -1, y ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt index 0c0d5f2a5272..bf5df08719a5 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/repl.txt @@ -58,7 +58,7 @@ [ -4.0, -3.0, -1.0, 2.0 ] -{{alias}}.assign( x, out[, sortOrder][, options] ) +{{alias}}.assign( x[, sortOrder], out[, options] ) Sorts elements of an input ndarray along one or more ndarray dimensions and assigns the results to an output ndarray. @@ -67,9 +67,6 @@ x: ndarray Input array. Must have a real-valued or "generic" data type. - out: ndarray - Output array. Must have a real-valued or "generic" data type. - sortOrder: ndarray|number|string (optional) Sort order. May be either a scalar value, string, or an ndarray having a real-valued or "generic" data type. If provided an ndarray, the value @@ -89,6 +86,9 @@ By default, the sort order is `1` (i.e., increasing order). + out: ndarray + Output array. Must have a real-valued or "generic" data type. + options: Object (optional) Function options. diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts index 578f44d0931c..c4b0d6723d97 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/index.d.ts @@ -202,8 +202,8 @@ interface ToSorted { * - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. * * @param x - input ndarray - * @param out - output ndarray * @param sortOrder - sort order + * @param out - output ndarray * @param options - function options * @returns output ndarray * @@ -217,13 +217,13 @@ interface ToSorted { * var y = zeros( [ 3, 1, 2 ] ); * // returns [ [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ], [ [ 0.0, 0.0 ] ] ] * - * var out = toSorted.assign( x, y, 1 ); + * var out = toSorted.assign( x, 1, y ); * // returns [ [ [ -5.0, -3.0 ] ], [ [ 1.0, 2.0 ] ], [ [ 4.0, 6.0 ] ] ] * * var bool = ( out === y ); * // returns true */ - assign( x: T, out: U, sortOrder: SortOrder, options?: BaseOptions ): U; + assign( x: T, sortOrder: SortOrder, out: U, options?: BaseOptions ): U; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts index 2150dc358383..c53f7bfe3512 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts @@ -185,9 +185,9 @@ import toSorted = require( './index' ); }); toSorted.assign( x, y ); // $ExpectType float64ndarray - toSorted.assign( x, y, 1.0 ); // $ExpectType float64ndarray toSorted.assign( x, y, {} ); // $ExpectType float64ndarray - toSorted.assign( x, y, 1.0, {} ); // $ExpectType float64ndarray + toSorted.assign( x, 1.0, y ); // $ExpectType float64ndarray + toSorted.assign( x, 1.0, y, {} ); // $ExpectType float64ndarray } // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... @@ -205,15 +205,6 @@ import toSorted = require( './index' ); toSorted.assign( {}, y ); // $ExpectError toSorted.assign( ( x: number ): number => x, y ); // $ExpectError - toSorted.assign( '5', y, 1.0 ); // $ExpectError - toSorted.assign( 5, y, 1.0 ); // $ExpectError - toSorted.assign( true, y, 1.0 ); // $ExpectError - toSorted.assign( false, y, 1.0 ); // $ExpectError - toSorted.assign( null, y, 1.0 ); // $ExpectError - toSorted.assign( void 0, y, 1.0 ); // $ExpectError - toSorted.assign( {}, y, 1.0 ); // $ExpectError - toSorted.assign( ( x: number ): number => x, y, 1.0 ); // $ExpectError - toSorted.assign( '5', y, {} ); // $ExpectError toSorted.assign( 5, y, {} ); // $ExpectError toSorted.assign( true, y, {} ); // $ExpectError @@ -223,17 +214,49 @@ import toSorted = require( './index' ); toSorted.assign( {}, y, {} ); // $ExpectError toSorted.assign( ( x: number ): number => x, y, {} ); // $ExpectError - toSorted.assign( '5', y, 1.0, {} ); // $ExpectError - toSorted.assign( 5, y, 1.0, {} ); // $ExpectError - toSorted.assign( true, y, 1.0, {} ); // $ExpectError - toSorted.assign( false, y, 1.0, {} ); // $ExpectError - toSorted.assign( null, y, 1.0, {} ); // $ExpectError - toSorted.assign( void 0, y, 1.0, {} ); // $ExpectError - toSorted.assign( {}, y, 1.0, {} ); // $ExpectError - toSorted.assign( ( x: number ): number => x, y, 1.0, {} ); // $ExpectError + toSorted.assign( '5', 1.0, y ); // $ExpectError + toSorted.assign( 5, 1.0, y ); // $ExpectError + toSorted.assign( true, 1.0, y ); // $ExpectError + toSorted.assign( false, 1.0, y ); // $ExpectError + toSorted.assign( null, 1.0, y ); // $ExpectError + toSorted.assign( void 0, 1.0, y ); // $ExpectError + toSorted.assign( {}, 1.0, y ); // $ExpectError + toSorted.assign( ( x: number ): number => x, 1.0, y ); // $ExpectError + + toSorted.assign( '5', 1.0, y, {} ); // $ExpectError + toSorted.assign( 5, 1.0, y, {} ); // $ExpectError + toSorted.assign( true, 1.0, y, {} ); // $ExpectError + toSorted.assign( false, 1.0, y, {} ); // $ExpectError + toSorted.assign( null, 1.0, y, {} ); // $ExpectError + toSorted.assign( void 0, 1.0, y, {} ); // $ExpectError + toSorted.assign( {}, 1.0, y, {} ); // $ExpectError + toSorted.assign( ( x: number ): number => x, 1.0, y, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sort order argument which is not an ndarray, supported string literal, or scalar value... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const y = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + toSorted.assign( x, true, y ); // $ExpectError + toSorted.assign( x, false, y ); // $ExpectError + toSorted.assign( x, [], y ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x, y ); // $ExpectError + + toSorted.assign( x, 'foo', y, {} ); // $ExpectError + toSorted.assign( x, true, y, {} ); // $ExpectError + toSorted.assign( x, false, y, {} ); // $ExpectError + toSorted.assign( x, null, y, {} ); // $ExpectError + toSorted.assign( x, void 0, y, {} ); // $ExpectError + toSorted.assign( x, [], y, {} ); // $ExpectError + toSorted.assign( x, ( x: number ): number => x, y, {} ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +// The compiler throws an error if the `assign` method is provided an output argument which is not an ndarray... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' @@ -248,59 +271,26 @@ import toSorted = require( './index' ); toSorted.assign( x, {} ); // $ExpectError toSorted.assign( x, ( x: number ): number => x ); // $ExpectError - toSorted.assign( x, '5', 1.0 ); // $ExpectError - toSorted.assign( x, 5, 1.0 ); // $ExpectError - toSorted.assign( x, true, 1.0 ); // $ExpectError - toSorted.assign( x, false, 1.0 ); // $ExpectError - toSorted.assign( x, null, 1.0 ); // $ExpectError - toSorted.assign( x, void 0, 1.0 ); // $ExpectError - toSorted.assign( x, {}, 1.0 ); // $ExpectError - toSorted.assign( x, ( x: number ): number => x, 1.0 ); // $ExpectError - - toSorted.assign( x, '5', {} ); // $ExpectError - toSorted.assign( x, 5, {} ); // $ExpectError - toSorted.assign( x, true, {} ); // $ExpectError - toSorted.assign( x, false, {} ); // $ExpectError - toSorted.assign( x, null, {} ); // $ExpectError - toSorted.assign( x, void 0, {} ); // $ExpectError - toSorted.assign( x, {}, {} ); // $ExpectError - toSorted.assign( x, ( x: number ): number => x, {} ); // $ExpectError - - toSorted.assign( x, '5', 1.0, {} ); // $ExpectError - toSorted.assign( x, 5, 1.0, {} ); // $ExpectError - toSorted.assign( x, true, 1.0, {} ); // $ExpectError - toSorted.assign( x, false, 1.0, {} ); // $ExpectError - toSorted.assign( x, null, 1.0, {} ); // $ExpectError - toSorted.assign( x, void 0, 1.0, {} ); // $ExpectError - toSorted.assign( x, {}, 1.0, {} ); // $ExpectError - toSorted.assign( x, ( x: number ): number => x, 1.0, {} ); // $ExpectError -} - -// The compiler throws an error if the `assign` method is provided a sort order argument which is not an ndarray, supported string literal, or scalar value... -{ - const x = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - const y = zeros( [ 2, 2 ], { - 'dtype': 'float64' - }); - - toSorted.assign( x, y, true ); // $ExpectError - toSorted.assign( x, y, false ); // $ExpectError - toSorted.assign( x, y, [] ); // $ExpectError - toSorted.assign( x, y, ( x: number ): number => x ); // $ExpectError - - toSorted.assign( x, y, 'foo', {} ); // $ExpectError - toSorted.assign( x, y, true, {} ); // $ExpectError - toSorted.assign( x, y, false, {} ); // $ExpectError - toSorted.assign( x, y, null, {} ); // $ExpectError - toSorted.assign( x, y, void 0, {} ); // $ExpectError - toSorted.assign( x, y, [], {} ); // $ExpectError - toSorted.assign( x, y, {}, {} ); // $ExpectError - toSorted.assign( x, y, ( x: number ): number => x, {} ); // $ExpectError + toSorted.assign( x, 1.0, '5' ); // $ExpectError + toSorted.assign( x, 1.0, 5 ); // $ExpectError + toSorted.assign( x, 1.0, true ); // $ExpectError + toSorted.assign( x, 1.0, false ); // $ExpectError + toSorted.assign( x, 1.0, null ); // $ExpectError + toSorted.assign( x, 1.0, void 0 ); // $ExpectError + toSorted.assign( x, 1.0, {} ); // $ExpectError + toSorted.assign( x, 1.0, ( x: number ): number => x ); // $ExpectError + + toSorted.assign( x, 1.0, '5', {} ); // $ExpectError + toSorted.assign( x, 1.0, 5, {} ); // $ExpectError + toSorted.assign( x, 1.0, true, {} ); // $ExpectError + toSorted.assign( x, 1.0, false, {} ); // $ExpectError + toSorted.assign( x, 1.0, null, {} ); // $ExpectError + toSorted.assign( x, 1.0, void 0, {} ); // $ExpectError + toSorted.assign( x, 1.0, {}, {} ); // $ExpectError + toSorted.assign( x, 1.0, ( x: number ): number => x, {} ); // $ExpectError } -// The compiler throws an error if the `assign` method is provided a options argument which is not an object... +// The compiler throws an error if the `assign` method is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' @@ -309,17 +299,19 @@ import toSorted = require( './index' ); 'dtype': 'float64' }); + toSorted.assign( x, y, '5' ); // $ExpectError toSorted.assign( x, y, true ); // $ExpectError toSorted.assign( x, y, false ); // $ExpectError + toSorted.assign( x, y, null ); // $ExpectError toSorted.assign( x, y, [] ); // $ExpectError toSorted.assign( x, y, ( x: number ): number => x ); // $ExpectError - toSorted.assign( x, y, 1.0, '5' ); // $ExpectError - toSorted.assign( x, y, 1.0, true ); // $ExpectError - toSorted.assign( x, y, 1.0, false ); // $ExpectError - toSorted.assign( x, y, 1.0, null ); // $ExpectError - toSorted.assign( x, y, 1.0, [] ); // $ExpectError - toSorted.assign( x, y, 1.0, ( x: number ): number => x ); // $ExpectError + toSorted.assign( x, 1.0, y, '5' ); // $ExpectError + toSorted.assign( x, 1.0, y, true ); // $ExpectError + toSorted.assign( x, 1.0, y, false ); // $ExpectError + toSorted.assign( x, 1.0, y, null ); // $ExpectError + toSorted.assign( x, 1.0, y, [] ); // $ExpectError + toSorted.assign( x, 1.0, y, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an invalid `dims` option... @@ -339,13 +331,13 @@ import toSorted = require( './index' ); toSorted.assign( x, y, { 'dims': {} } ); // $ExpectError toSorted.assign( x, y, { 'dims': ( x: number ): number => x } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': '5' } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': 5 } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': true } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': false } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': null } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': {} } ); // $ExpectError - toSorted.assign( x, y, 1.0, { 'dims': ( x: number ): number => x } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': '5' } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': 5 } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': true } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': false } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': null } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': {} } ); // $ExpectError + toSorted.assign( x, 1.0, y, { 'dims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... @@ -359,5 +351,5 @@ import toSorted = require( './index' ); toSorted.assign(); // $ExpectError toSorted.assign( x ); // $ExpectError - toSorted.assign( x, y, 10.0, {}, {} ); // $ExpectError + toSorted.assign( x, 1.0, y, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js index 9c3d88ea1cf2..9f553b7ef369 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/lib/assign.js @@ -20,6 +20,9 @@ // MODULES // +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var isMostlySafeCast = require( '@stdlib/ndarray/base/assert/is-mostly-safe-data-type-cast' ); var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); @@ -35,17 +38,17 @@ var format = require( '@stdlib/string/format' ); * Sorts the elements of an input ndarray along one or more ndarray dimensions and assigns the results to an output ndarray. * * @param {ndarrayLike} x - input ndarray -* @param {ndarrayLike} y - output ndarray * @param {(ndarrayLike|number|string)} [sortOrder=1.0] - sort order +* @param {ndarrayLike} out - output ndarray * @param {Options} [options] - function options * @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation * @throws {TypeError} first argument must be an ndarray-like object -* @throws {TypeError} second argument must be an ndarray-like object * @throws {TypeError} sort order argument must be either an ndarray-like object, a numeric value, or a supported string +* @throws {TypeError} output argument must be an ndarray-like object * @throws {TypeError} options argument must be an object * @throws {RangeError} dimension indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions -* @throws {TypeError} first argument cannot be safely cast to the data type of the second argument +* @throws {TypeError} first argument cannot be safely cast to the data type of the output argument * @throws {Error} must provide valid options * @returns {ndarray} output ndarray * @@ -65,31 +68,95 @@ var format = require( '@stdlib/string/format' ); * var bool = ( y === out ); * // returns true */ -function assign( x, y ) { +function assign( x, sortOrder, out ) { + var hasOptions; + var options; var nargs; var xdt; - var ydt; + var odt; + var so; + var o; + + nargs = arguments.length; if ( !isndarrayLike( x ) ) { throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); } - if ( !isndarrayLike( y ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', y ) ); + // Initialize the sort order to ascending: + so = 1; + + // Initialize a flag indicating whether an `options` argument was provided: + hasOptions = false; + + // Case: assign( x, out ) + if ( nargs <= 2 ) { + o = sortOrder; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', o ) ); + } } - xdt = getDType( x ); - ydt = getDType( y ); - if ( !isMostlySafeCast( xdt, ydt ) ) { - throw new TypeError( format( 'invalid argument. First argument cannot be safely cast to the output data type. Data types: [%s, %s].', resolveStr( xdt ), resolveStr( ydt ) ) ); + // Case: assign( x, ???, ??? ) + else if ( nargs === 3 ) { + // Case: assign( x, sort_order, out ) + if ( isndarrayLike( out ) ) { + o = out; + + // Case: assign( x, sort_order_scalar, out ) + if ( isNumber( sortOrder ) || isString( sortOrder ) ) { + so = sortOrder; + } + // Case: assign( x, sort_order_ndarray, out ) + else if ( isndarrayLike( sortOrder ) ) { + so = sortOrder; + } + // Case: assign( x, ???, out ) + else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray-like object, a numeric value, or a supported string. Value: `%s`.', sortOrder ) ); + } + } + // Case: assign( x, out, options ) + else { + o = sortOrder; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', o ) ); + } + options = out; + hasOptions = true; + } } - nargs = arguments.length; - copy( [ x, y ] ); - if ( nargs <= 2 ) { - return sort( y ); + // Case: assign( x, sort_order, out, options ) + else { // nargs > 3 + // Case: assign( x, sort_order_scalar, out, options ) + if ( isNumber( sortOrder ) || isString( sortOrder ) ) { + so = sortOrder; + } + // Case: assign( x, sort_order_ndarray, out, options ) + else if ( isndarrayLike( sortOrder ) ) { + so = sortOrder; + } + // Case: assign( x, ???, out, options ) + else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray-like object, a numeric value, or a supported string. Value: `%s`.', sortOrder ) ); + } + o = out; + if ( !isndarrayLike( o ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', o ) ); + } + options = arguments[ 3 ]; + hasOptions = true; + } + if ( hasOptions && !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + xdt = getDType( x ); + odt = getDType( o ); + if ( !isMostlySafeCast( xdt, odt ) ) { + throw new TypeError( format( 'invalid argument. First argument cannot be safely cast to the output data type. Data types: [%s, %s].', resolveStr( xdt ), resolveStr( odt ) ) ); } - if ( nargs === 3 ) { - return sort( y, arguments[ 2 ] ); + copy( [ x, o ] ); + if ( hasOptions ) { + return sort( o, so, options ); } - // nargs > 3 - return sort( y, arguments[ 2 ], arguments[ 3 ] ); + return sort( o, so ); } diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js index 0e330b7fd6fa..cd4465f75d58 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js @@ -88,7 +88,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), 1.0 ); + assign( value, 1.0, zeros( [ 2, 2 ] ) ); }; } }); @@ -116,7 +116,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ) ); + assign( value, scalar2ndarray( 1.0 ), zeros( [ 2, 2 ] ) ); }; } }); @@ -172,7 +172,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), 1.0, {} ); + assign( value, 1.0, zeros( [ 2, 2 ] ), {} ); }; } }); @@ -200,7 +200,7 @@ tape( 'the function throws an error if provided a first argument which is not an function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), {} ); + assign( value, scalar2ndarray( 1.0 ), zeros( [ 2, 2 ] ), {} ); }; } }); @@ -263,7 +263,7 @@ tape( 'the function throws an error if provided a first argument which does not function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), 1.0 ); + assign( value, 1.0, zeros( [ 2, 2 ] ) ); }; } }); @@ -284,7 +284,7 @@ tape( 'the function throws an error if provided a first argument which does not function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ) ); + assign( value, scalar2ndarray( 1.0 ), zeros( [ 2, 2 ] ) ); }; } }); @@ -305,7 +305,7 @@ tape( 'the function throws an error if provided a first argument which does not function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), 1.0, {} ); + assign( value, 1.0, zeros( [ 2, 2 ] ), {} ); }; } }); @@ -326,12 +326,12 @@ tape( 'the function throws an error if provided a first argument which does not function badValue( value ) { return function badValue() { - assign( value, zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), {} ); + assign( value, scalar2ndarray( 1.0 ), zeros( [ 2, 2 ] ), {} ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object', function test( t ) { var values; var i; @@ -359,7 +359,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=scalar)', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (sortOrder=scalar)', function test( t ) { var values; var i; @@ -382,12 +382,12 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, 1.0 ); + assign( zeros( [ 2, 2 ] ), 1.0, value ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (sortOrder=ndarray)', function test( t ) { var values; var i; @@ -400,7 +400,6 @@ tape( 'the function throws an error if provided a second argument which is not a null, void 0, [], - {}, function noop() {} ]; for ( i = 0; i < values.length; i++ ) { @@ -410,12 +409,12 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ) ); + assign( zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), value ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (options)', function test( t ) { var values; var i; @@ -443,7 +442,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=scalar, options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (sortOrder=scalar, options)', function test( t ) { var values; var i; @@ -466,12 +465,12 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, 1.0, {} ); + assign( zeros( [ 2, 2 ] ), 1.0, value, {} ); }; } }); -tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (sortOrder=ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which is not an ndarray-like object (sortOrder=ndarray, options)', function test( t ) { var values; var i; @@ -494,12 +493,12 @@ tape( 'the function throws an error if provided a second argument which is not a function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ), {} ); + assign( zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), value, {} ); }; } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type', function test( t ) { var values; var i; @@ -520,7 +519,7 @@ tape( 'the function throws an error if provided a second argument which does not } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type (options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type (options)', function test( t ) { var values; var i; @@ -541,7 +540,7 @@ tape( 'the function throws an error if provided a second argument which does not } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=scalar)', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type (sortOrder=scalar)', function test( t ) { var values; var i; @@ -557,12 +556,12 @@ tape( 'the function throws an error if provided a second argument which does not function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, 1.0 ); + assign( zeros( [ 2, 2 ] ), 1.0, value ); }; } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=ndarray)', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type (sortOrder=ndarray)', function test( t ) { var values; var i; @@ -578,12 +577,12 @@ tape( 'the function throws an error if provided a second argument which does not function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ) ); + assign( zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), value ); }; } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=scalar, options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type (sortOrder=scalar, options)', function test( t ) { var values; var i; @@ -599,12 +598,12 @@ tape( 'the function throws an error if provided a second argument which does not function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, 1.0, {} ); + assign( zeros( [ 2, 2 ] ), 1.0, value, {} ); }; } }); -tape( 'the function throws an error if provided a second argument which does not have a supported data type (sortOrder=ndarray, options)', function test( t ) { +tape( 'the function throws an error if provided an output argument which does not have a supported data type (sortOrder=ndarray, options)', function test( t ) { var values; var i; @@ -620,12 +619,12 @@ tape( 'the function throws an error if provided a second argument which does not function badValue( value ) { return function badValue() { - assign( zeros( [ 2, 2 ] ), value, scalar2ndarray( 1.0 ), {} ); + assign( zeros( [ 2, 2 ] ), scalar2ndarray( 1.0 ), value, {} ); }; } }); -tape( 'the function throws an error if provided a second argument having dimensions greater than or less than the dimensions of input ndarray', function test( t ) { +tape( 'the function throws an error if provided an output argument having dimensions greater than or less than the dimensions of input ndarray', function test( t ) { var values; var i; @@ -723,7 +722,7 @@ tape( 'the function throws an error if provided a `sortOrder` argument which is function badValue( value ) { return function badValue() { - assign( x, y, value ); + assign( x, value, y ); }; } }); @@ -758,7 +757,7 @@ tape( 'the function throws an error if provided a `sortOrder` argument which is function badValue( value ) { return function badValue() { - assign( x, y, value, {} ); + assign( x, value, y, {} ); }; } }); @@ -789,7 +788,7 @@ tape( 'the function throws an error if provided a `sortOrder` argument which is function badValue( value ) { return function badValue() { - assign( x, y, value ); + assign( x, value, y ); }; } }); @@ -820,42 +819,7 @@ tape( 'the function throws an error if provided a `sortOrder` argument which is function badValue( value ) { return function badValue() { - assign( x, y, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var x; - var y; - var i; - - x = zeros( [ 2, 2 ], { - 'dtype': 'generic' - }); - - y = zeros( [ 2, 2 ], { - 'dtype': 'generic' - }); - - values = [ - '5', - 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() { - assign( x, y, value ); + assign( x, value, y, {} ); }; } }); @@ -892,7 +856,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - assign( x, y, 1.0, value ); + assign( x, 1.0, y, value ); }; } }); @@ -929,7 +893,7 @@ tape( 'the function throws an error if provided an options argument which is not function badValue( value ) { return function badValue() { - assign( x, y, scalar2ndarray( 1.0, opts ), value ); + assign( x, scalar2ndarray( 1.0, opts ), y, value ); }; } }); @@ -1007,7 +971,7 @@ tape( 'the function throws an error if provided a `dims` option which is not an function badValue( value ) { return function badValue() { - assign( x, y, 1.0, { + assign( x, 1.0, y, { 'dims': value }); }; @@ -1047,7 +1011,7 @@ tape( 'the function throws an error if provided a `dims` option which is not an function badValue( value ) { return function badValue() { - assign( x, y, scalar2ndarray( 1.0, opts ), { + assign( x, scalar2ndarray( 1.0, opts ), y, { 'dims': value }); }; @@ -1113,7 +1077,7 @@ tape( 'the function throws an error if provided a `dims` option which contains o function badValue( value ) { return function badValue() { - assign( x, y, 1.0, { + assign( x, 1.0, y, { 'dims': value }); }; @@ -1146,7 +1110,7 @@ tape( 'the function throws an error if provided a `dims` option which contains o function badValue( value ) { return function badValue() { - assign( x, y, scalar2ndarray( 1.0, opts ), { + assign( x, scalar2ndarray( 1.0, opts ), y, { 'dims': value }); }; @@ -1210,7 +1174,7 @@ tape( 'the function throws an error if provided a `dims` option which contains t function badValue( value ) { return function badValue() { - assign( x, y, 1.0, { + assign( x, 1.0, y, { 'dims': value }); }; @@ -1242,7 +1206,7 @@ tape( 'the function throws an error if provided a `dims` option which contains t function badValue( value ) { return function badValue() { - assign( x, y, scalar2ndarray( 1.0, opts ), { + assign( x, scalar2ndarray( 1.0, opts ), y, { 'dims': value }); }; @@ -1310,7 +1274,7 @@ tape( 'the function throws an error if provided a `dims` option which contains d function badValue( value ) { return function badValue() { - assign( x, y, 1.0, { + assign( x, 1.0, y, { 'dims': value }); }; @@ -1344,7 +1308,7 @@ tape( 'the function throws an error if provided a `dims` option which contains d function badValue( value ) { return function badValue() { - assign( x, y, scalar2ndarray( 1.0, opts ), { + assign( x, scalar2ndarray( 1.0, opts ), y, { 'dims': value }); }; @@ -1579,7 +1543,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar)', functio 'order': 'row-major' }); - actual = assign( x, y, 1.0 ); + actual = assign( x, 1.0, y ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1592,7 +1556,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar)', functio 'order': 'column-major' }); - actual = assign( x, y, -1.0 ); + actual = assign( x, -1.0, y ); expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1615,7 +1579,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, options)' 'order': 'row-major' }); - actual = assign( x, y, 1.0, {} ); + actual = assign( x, 1.0, y, {} ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1628,7 +1592,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, options)' 'order': 'column-major' }); - actual = assign( x, y, -1.0, {} ); + actual = assign( x, -1.0, y, {} ); expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); @@ -1641,7 +1605,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, options)' 'order': 'row-major' }); - actual = assign( x, y, 0.0, {} ); + actual = assign( x, 0.0, y, {} ); expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); @@ -1668,7 +1632,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun 'order': 'row-major' }); - actual = assign( x, y, scalar2ndarray( 1.0, opts ) ); + actual = assign( x, scalar2ndarray( 1.0, opts ), y ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1681,7 +1645,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( -1.0, opts ) ); + actual = assign( x, scalar2ndarray( -1.0, opts ), y ); expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1694,7 +1658,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( 0.0, opts ) ); + actual = assign( x, scalar2ndarray( 0.0, opts ), y ); expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1721,7 +1685,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio 'order': 'row-major' }); - actual = assign( x, y, scalar2ndarray( 1.0, opts ), {} ); + actual = assign( x, scalar2ndarray( 1.0, opts ), y, {} ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1734,7 +1698,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( -1.0, opts ), {} ); + actual = assign( x, scalar2ndarray( -1.0, opts ), y, {} ); expected = [ [ 4.0, -1.0 ], [ 2.0, -3.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1747,7 +1711,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( 0.0, opts ), {} ); + actual = assign( x, scalar2ndarray( 0.0, opts ), y, {} ); expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1770,7 +1734,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, broadcast 'order': 'row-major' }); - actual = assign( x, y, 1.0, { + actual = assign( x, 1.0, y, { 'dims': [ 0 ] }); expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; @@ -1785,7 +1749,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, broadcast 'order': 'column-major' }); - actual = assign( x, y, -1.0, { + actual = assign( x, -1.0, y, { 'dims': [ 0 ] }); expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; @@ -1800,7 +1764,7 @@ tape( 'the function supports providing a `sortOrder` argument (scalar, broadcast 'order': 'column-major' }); - actual = assign( x, y, 0.0, { + actual = assign( x, 0.0, y, { 'dims': [ 0 ] }); expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; @@ -1829,7 +1793,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad 'order': 'row-major' }); - actual = assign( x, y, scalar2ndarray( 1.0, opts ), { + actual = assign( x, scalar2ndarray( 1.0, opts ), y, { 'dims': [ 0 ] }); expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; @@ -1844,7 +1808,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( -1.0, opts ), { + actual = assign( x, scalar2ndarray( -1.0, opts ), y, { 'dims': [ 0 ] }); expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; @@ -1859,7 +1823,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad 'order': 'column-major' }); - actual = assign( x, y, scalar2ndarray( 0.0, opts ), { + actual = assign( x, scalar2ndarray( 0.0, opts ), y, { 'dims': [ 0 ] }); expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; @@ -1883,7 +1847,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals)' 'dtype': 'generic' }); - actual = assign( x, y, 'asc' ); + actual = assign( x, 'asc', y ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1892,7 +1856,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals)' xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = assign( x, y, 'ascending' ); + actual = assign( x, 'ascending', y ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1901,7 +1865,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals)' xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = assign( x, y, 'desc' ); + actual = assign( x, 'desc', y ); expected = [ [ 4.0, 2.0 ], [ -1.0, -3.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1910,7 +1874,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals)' xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = assign( x, y, 'descending' ); + actual = assign( x, 'descending', y ); expected = [ [ 4.0, 2.0 ], [ -1.0, -3.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1932,7 +1896,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals, 'dtype': 'generic' }); - actual = assign( x, y, 'asc', {} ); + actual = assign( x, 'asc', y, {} ); expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.strictEqual( actual, y, 'returns expected value' ); @@ -1941,7 +1905,7 @@ tape( 'the function supports providing a `sortOrder` argument (string literals, xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - actual = assign( x, y, 'descending', { + actual = assign( x, 'descending', y, { 'dims': [ 0 ] }); expected = [ [ -1.0, 4.0 ], [ -3.0, 2.0 ] ]; @@ -1973,7 +1937,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi obuf = [ 1.0, -1.0 ]; sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); - actual = assign( x, y, sortOrder, { + actual = assign( x, sortOrder, y, { 'dims': [ 0 ] }); expected = [ [ -3.0, 4.0 ], [ -1.0, 2.0 ] ]; @@ -1990,7 +1954,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi obuf = [ 1.0, -1.0 ]; sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); - actual = assign( x, y, sortOrder, { + actual = assign( x, sortOrder, y, { 'dims': [ 0 ] }); expected = [ [ -1.0, 4.0 ], [ 2.0, -3.0 ] ]; @@ -2007,7 +1971,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi obuf = [ 0.0, -1.0 ]; sortOrder = new ndarray( opts.dtype, obuf, [ 2 ], [ 1 ], 0, 'row-major' ); - actual = assign( x, y, sortOrder, { + actual = assign( x, sortOrder, y, { 'dims': [ 1 ] }); expected = [ [ 1.0, -2.0 ], [ 4.0, -3.0 ] ]; From 4fddfd2c868f4cccc9cae3dc8536ee6bebce2133 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:16:27 -0700 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js | 4 +--- .../@stdlib/blas/ext/to-sorted/benchmark/benchmark.js | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js index 192240fdbc68..d3352da8d1db 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.assign.js @@ -51,9 +51,7 @@ function createBenchmark( len ) { var y; x = uniform( [ len ], -50.0, 50.0, options ); - y = zeros( [ len ], { - 'dtype': options.dtype - }); + y = zeros( [ len ], options ); return benchmark; diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js index 634df1bdf68f..c13161c2a759 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/benchmark/benchmark.js @@ -47,7 +47,6 @@ var options = { */ function createBenchmark( len ) { var x = uniform( [ len ], -50.0, 50.0, options ); - return benchmark; /** From 0a1f03c15fe4e8fffa1fb5782ff5cdcb884e830b Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:20:21 -0700 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts index c53f7bfe3512..387ef3220e8b 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/docs/types/test.ts @@ -98,7 +98,7 @@ import toSorted = require( './index' ); toSorted( x, ( x: number ): number => x, {} ); // $ExpectError } -// The compiler throws an error if the function is provided a options argument which is not an object... +// The compiler throws an error if the function is provided an options argument which is not an object... { const x = zeros( [ 2, 2 ], { 'dtype': 'float64' From b7caeae16846214352181056bef6dcafd09b20c8 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:35:40 -0700 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js index cd4465f75d58..b8467affbf41 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js @@ -624,7 +624,7 @@ tape( 'the function throws an error if provided an output argument which does no } }); -tape( 'the function throws an error if provided an output argument having dimensions greater than or less than the dimensions of input ndarray', function test( t ) { +tape( 'the function throws an error if provided an output argument having a shape which is incompatible with the input ndarray', function test( t ) { var values; var i; From 9643b8952143a735ceb124e3b1d569cb14a55b27 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:40:18 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/to-sorted/test/test.assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js index b8467affbf41..27ac3271bf81 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.assign.js @@ -692,7 +692,7 @@ tape( 'the function throws an error if the input ndarray cannot be safely cast t } }); -tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a support string', function test( t ) { +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a supported string', function test( t ) { var values; var x; var y; @@ -727,7 +727,7 @@ tape( 'the function throws an error if provided a `sortOrder` argument which is } }); -tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a support string (options)', function test( t ) { +tape( 'the function throws an error if provided a `sortOrder` argument which is not an ndarray-like object, a numeric scalar, or a supported string (options)', function test( t ) { var values; var x; var y; From 90fccb4cf534ffa32adde156d3f52b066c9f08a3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:48:07 -0700 Subject: [PATCH 7/8] test: fix assertions Signed-off-by: Athan --- .../blas/ext/to-sorted/test/test.main.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js index d9104343a68e..53f16d8e3e6b 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js @@ -1493,7 +1493,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ -3.0, -1.0, 2.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1505,7 +1505,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ 4.0, 2.0, -1.0, -3.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1517,7 +1517,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ -1.0, 2.0, -3.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1542,7 +1542,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ -3.0, -1.0, 2.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1554,7 +1554,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ 4.0, 2.0, -1.0, -3.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1566,7 +1566,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ -1.0, 2.0, -3.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1644,7 +1644,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1658,7 +1658,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1672,7 +1672,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1795,7 +1795,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ -3.0, 4.0 ], [ -1.0, 2.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1811,7 +1811,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ -1.0, 4.0 ], [ 2.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1827,7 +1827,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ 1.0, -2.0 ], [ 4.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( getDType( actual ), opts.dtype, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); From b3a2cb62e7eb1fbdaa5c7d72c59a1309dcc0cab5 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 22:53:28 -0700 Subject: [PATCH 8/8] test: update assertions Signed-off-by: Athan --- .../blas/ext/to-sorted/test/test.main.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js index 53f16d8e3e6b..6f8e9aa027c7 100644 --- a/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/to-sorted/test/test.main.js @@ -26,7 +26,6 @@ var isSameArray = require( '@stdlib/assert/is-same-array' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var Int8Array = require( '@stdlib/array/int8' ); -var resolveStr = require( '@stdlib/ndarray/base/dtype-resolve-str' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var zeros = require( '@stdlib/ndarray/zeros' ); var empty = require( '@stdlib/ndarray/empty' ); @@ -1493,7 +1492,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ -3.0, -1.0, 2.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1505,7 +1504,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ 4.0, 2.0, -1.0, -3.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1517,7 +1516,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray)', fun expected = [ -1.0, 2.0, -3.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1542,7 +1541,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ -3.0, -1.0, 2.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1554,7 +1553,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ 4.0, 2.0, -1.0, -3.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1566,7 +1565,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, optio expected = [ -1.0, 2.0, -3.0, 4.0 ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); @@ -1644,7 +1643,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ -3.0, 2.0 ], [ -1.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1658,7 +1657,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ 2.0, 4.0 ], [ -1.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1672,7 +1671,7 @@ tape( 'the function supports providing a `sortOrder` argument (0d ndarray, broad expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1795,7 +1794,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ -3.0, 4.0 ], [ -1.0, 2.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1811,7 +1810,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ -1.0, 4.0 ], [ 2.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1827,7 +1826,7 @@ tape( 'the function supports providing a `sortOrder` argument (ndarray)', functi expected = [ [ 1.0, -2.0 ], [ 4.0, -3.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( isEqualDataType( getDType( actual ), opts.dtype ), true, 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1850,7 +1849,7 @@ tape( 'the function supports specifying an output data type', function test( t ) expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( resolveStr( getDType( actual ) ), 'float64', 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), 'float64' ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1873,7 +1872,7 @@ tape( 'the function supports specifying an output data type (sortOrder=scalar)', expected = [ [ -3.0, -1.0 ], [ 2.0, 4.0 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( resolveStr( getDType( actual ) ), 'float32', 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), 'float32' ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -1896,7 +1895,7 @@ tape( 'the function supports specifying an output data type (sortOrder=string)', expected = [ [ 4, 2 ], [ -1, -3 ] ]; t.notEqual( actual, x, 'returns expected value' ); - t.strictEqual( resolveStr( getDType( actual ) ), 'int32', 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), 'int32' ), true, 'returns expected value' ); t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );