From 4eeada0483a7a8d7fc414523fb70587ed0efadf3 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 25 Feb 2026 23:45:40 +0500 Subject: [PATCH 1/2] feat: add ndarray/base/to-transposed --- 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 --- --- .../ndarray/base/to-transposed/README.md | 162 ++++ .../base/to-transposed/benchmark/benchmark.js | 272 ++++++ .../ndarray/base/to-transposed/docs/repl.txt | 23 + .../base/to-transposed/docs/types/index.d.ts | 45 + .../base/to-transposed/docs/types/test.ts | 49 + .../base/to-transposed/examples/index.js | 66 ++ .../ndarray/base/to-transposed/lib/index.js | 44 + .../ndarray/base/to-transposed/lib/main.js | 73 ++ .../ndarray/base/to-transposed/package.json | 68 ++ .../ndarray/base/to-transposed/test/test.js | 859 ++++++++++++++++++ 10 files changed, 1661 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md new file mode 100644 index 000000000000..1b0d16de17f8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md @@ -0,0 +1,162 @@ + + +# to-transposed + +> Return a new transposed ndarray. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toTransposed = require( '@stdlib/ndarray/base/to-transposed' ); +``` + +#### toTransposed( x ) + +Returns a new transposed ndarray. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +var out = toTransposed( x ); +// returns [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var rpad = require( '@stdlib/string/right-pad' ); +var toTransposed = require( '@stdlib/ndarray/base/to-transposed' ); + +function print( arr, name ) { + var str; + var sh; + var p; + var i; + var j; + var k; + + sh = arr.shape; + for ( i = 0; i < sh[0]; i++ ) { + str = name+'['+i+',:,:] = [ '; + p = str.length + 1; + for ( j = 0; j < sh[1]; j++ ) { + if ( j > 0 ) { + str += rpad( '\n', p, ' ' ); + } + for ( k = 0; k < sh[2]; k++ ) { + str += arr.get( i, j, k ); + if ( k < sh[2]-1 ) { + str += ', '; + } + } + } + console.log( str + ' ]\n' ); + } +} + +// Create a data buffer: +var buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create a stack of matrices: +var x = new ndarray( 'float64', buf, [ 2, 2, 3 ], [ 0, 3, 1 ], 0, 'row-major' ); + +// Transpose the stack of matrices: +var y = toTransposed( x ); + +// Print the stacks: +console.log( '' ); +print( x, 'X' ); +console.log( '' ); +print( y, 'Y' ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js new file mode 100644 index 000000000000..682bb449ef91 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js @@ -0,0 +1,272 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var toTransposed = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::2d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' }), + empty( [ 2, 2 ], { 'dtype': 'float32' }), + empty( [ 2, 2 ], { 'dtype': 'int32' }), + empty( [ 2, 2 ], { 'dtype': 'complex128' }), + empty( [ 2, 2 ], { 'dtype': 'generic' }) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::3d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' }), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' }), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' }), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' }), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' }) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::4d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' }), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' }), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' }), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' }), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' }) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::5d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' }), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' }), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' }), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' }), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' }) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toTransposed( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt new file mode 100644 index 000000000000..867ad36dde43 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt @@ -0,0 +1,23 @@ + +{{alias}}( x ) + Returns a new transposed ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + > var y = {{alias}}( x ) + [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts new file mode 100644 index 000000000000..4f2ce17a5a4c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts @@ -0,0 +1,45 @@ +/* +* @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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns a new transposed ndarray. +* +* @param x - input array +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); +* // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] +* +* var out = toTransposed( x ); +* // returns [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] +*/ +declare function toTransposed( x: ndarray ): ndarray; + + +// EXPORTS // + +export = toTransposed; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts new file mode 100644 index 000000000000..9e54382f8bc2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts @@ -0,0 +1,49 @@ +/* +* @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. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import toTransposed = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + toTransposed( zeros( 'float64', sh, ord ) ); // $ExpectType ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + toTransposed( '10' ); // $ExpectError + toTransposed( 10 ); // $ExpectError + toTransposed( false ); // $ExpectError + toTransposed( true ); // $ExpectError + toTransposed( null ); // $ExpectError + toTransposed( [] ); // $ExpectError + toTransposed( {} ); // $ExpectError + toTransposed( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + toTransposed(); // $ExpectError + toTransposed( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/examples/index.js new file mode 100644 index 000000000000..d3617977ade1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/examples/index.js @@ -0,0 +1,66 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var rpad = require( '@stdlib/string/right-pad' ); +var toTransposed = require( './../lib' ); + +function print( arr, name ) { // eslint-disable-line stdlib/no-redeclare + var str; + var sh; + var p; + var i; + var j; + var k; + + sh = arr.shape; + for ( i = 0; i < sh[0]; i++ ) { + str = name+'['+i+',:,:] = [ '; + p = str.length + 1; + for ( j = 0; j < sh[1]; j++ ) { + if ( j > 0 ) { + str += rpad( '\n', p, ' ' ); + } + for ( k = 0; k < sh[2]; k++ ) { + str += arr.get( i, j, k ); + if ( k < sh[2]-1 ) { + str += ', '; + } + } + } + console.log( str + ' ]\n' ); + } +} + +// Create a data buffer: +var buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create a stack of matrices: +var x = new ndarray( 'float64', buf, [ 2, 2, 3 ], [ 0, 3, 1 ], 0, 'row-major' ); + +// Transpose the stack of matrices: +var y = toTransposed( x ); + +// Print the stacks: +console.log( '' ); +print( x, 'X' ); +console.log( '' ); +print( y, 'Y' ); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js new file mode 100644 index 000000000000..0eb0f841bfd3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 transposed ndarray. +* +* @module @stdlib/ndarray/base/to-transposed +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var toTransposed = require( '@stdlib/ndarray/base/to-transposed' ); +* +* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); +* // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] +* +* var out = toTransposed( x ); +* // returns [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js new file mode 100644 index 000000000000..57c90477ac7b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js @@ -0,0 +1,73 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/base/dtype' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var transpose = require( '@stdlib/ndarray/base/transpose' ); +var empty = require( '@stdlib/ndarray/base/empty' ); +var assign = require( '@stdlib/ndarray/base/assign' ); + + +// MAIN // + +/** +* Returns a new transposed ndarray. +* +* @param {ndarray} x - input array +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); +* // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] +* +* var out = toTransposed( x ); +* // returns [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] +*/ +function toTransposed( x ) { + var view; + var out; + var tmp; + var sh; + + // Create transposed view of the input array: + view = transpose( x, false ); + + // Create an output array: + sh = getShape( x, true ); + tmp = sh[ sh.length-1 ]; + sh[ sh.length-1 ] = sh[ sh.length-2 ]; + sh[ sh.length-2 ] = tmp; + out = empty( getDType( x ), sh, getOrder( x ) ); + + // Copy elements from transposed view to output array: + assign( [ view, out ] ); + + return out; +} + + +// EXPORTS // + +module.exports = toTransposed; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json b/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json new file mode 100644 index 000000000000..60a77f260dd6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ndarray/base/to-transposed", + "version": "0.0.0", + "description": "Return a new transposed ndarray.", + "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", + "stdtypes", + "types", + "base", + "data", + "structure", + "ndarray", + "matrix", + "transpose", + "transposed", + "to-transposed", + "stack", + "permute", + "swap", + "swapaxes" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js new file mode 100644 index 000000000000..275cf5803fa1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js @@ -0,0 +1,859 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var base = require( '@stdlib/ndarray/base/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var toTransposed = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toTransposed, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=float64, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=float64, base, column-major)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=float64, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'float64' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=float32, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=float32, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'float32' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int32, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int32Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'int32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int32, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int32Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'int32' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int16, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int16Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'int16', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int16, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int16Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'int16' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int8, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int8Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'int8', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=int8, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Int8Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'int8' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint32, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint32Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'uint32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint32, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint32Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'uint32' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint16, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint16Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'uint16', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint16, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint16Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'uint16' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint8, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint8Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'uint8', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint8, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint8Array( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'uint8' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint8c, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6 ] ); + x = new base( 'uint8c', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=uint8c, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'uint8c' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=complex128, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0 ] ); // eslint-disable-line max-len + x = new base( 'complex128', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( real( v1 ), real( v2 ), 'returns expected value for ('+j+','+i+')' ); + t.strictEqual( imag( v1 ), imag( v2 ), 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=complex128, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0 ] ); // eslint-disable-line max-len + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'complex128' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( real( v1 ), real( v2 ), 'returns expected value for ('+j+','+i+')' ); + t.strictEqual( imag( v1 ), imag( v2 ), 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=complex64, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0 ] ); // eslint-disable-line max-len + x = new base( 'complex64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( realf( v1 ), realf( v2 ), 'returns expected value for ('+j+','+i+')' ); + t.strictEqual( imagf( v1 ), imagf( v2 ), 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=complex64, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0 ] ); // eslint-disable-line max-len + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'complex64' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( realf( v1 ), realf( v2 ), 'returns expected value for ('+j+','+i+')' ); + t.strictEqual( imagf( v1 ), imagf( v2 ), 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=generic, base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = new base( 'generic', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function returns a new transposed ndarray (dtype=generic, non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'generic' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 3; j++ ) { + v1 = x.get( i, j ); + v2 = arr.get( j, i ); + t.strictEqual( v1, v2, 'returns expected value for ('+j+','+i+')' ); + } + } + t.end(); +}); + +tape( 'the function supports stack of matrices (base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + var k; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = new base( 'generic', buf, [ 4, 2, 3 ], [ 0, 3, 1 ], 0, 'row-major' ); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 4, 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 4; i++ ) { + for ( j = 0; j < 2; j++ ) { + for ( k = 0; k < 3; k++ ) { + v1 = x.get( i, j, k ); + v2 = arr.get( i, k, j ); + t.strictEqual( v1, v2, 'returns expected value for ('+i+','+k+','+j+')' ); + } + } + } + t.end(); +}); + +tape( 'the function supports stack of matrices (non-base)', function test( t ) { + var arr; + var buf; + var v1; + var v2; + var x; + var i; + var j; + var k; + + buf = [ 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6 ]; // eslint-disable-line max-len + x = array( buf, { + 'shape': [ 4, 2, 3 ], + 'dtype': 'generic' + }); + arr = toTransposed( x ); + + t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 4, 3, 2 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + + for ( i = 0; i < 4; i++ ) { + for ( j = 0; j < 2; j++ ) { + for ( k = 0; k < 3; k++ ) { + v1 = x.get( i, j, k ); + v2 = arr.get( i, k, j ); + t.strictEqual( v1, v2, 'returns expected value for ('+i+','+k+','+j+')' ); + } + } + } + t.end(); +}); From 1a92a747f1f054a119a334c7952ad22c268623c0 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 27 Feb 2026 02:12:15 -0800 Subject: [PATCH 2/2] chore: clean-up --- 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: 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 --- --- .../ndarray/base/to-transposed/README.md | 10 +- .../base/to-transposed/benchmark/benchmark.js | 56 +++---- .../ndarray/base/to-transposed/docs/repl.txt | 3 +- .../base/to-transposed/docs/types/index.d.ts | 4 +- .../base/to-transposed/docs/types/test.ts | 2 +- .../ndarray/base/to-transposed/lib/index.js | 2 +- .../ndarray/base/to-transposed/lib/main.js | 16 +- .../ndarray/base/to-transposed/package.json | 2 +- .../ndarray/base/to-transposed/test/test.js | 154 ++++++++++++------ 9 files changed, 148 insertions(+), 101 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md index 1b0d16de17f8..769c938a4b67 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# to-transposed +# toTransposed -> Return a new transposed ndarray. +> Return a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed. @@ -42,7 +42,7 @@ var toTransposed = require( '@stdlib/ndarray/base/to-transposed' ); #### toTransposed( x ) -Returns a new transposed ndarray. +Returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -66,6 +66,10 @@ The function accepts the following arguments:
+## Notes + +- If provided an ndarray with fewer than two dimensions, the function raises an exception. +
diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js index 682bb449ef91..57ac7b77d47c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/benchmark/benchmark.js @@ -64,17 +64,17 @@ bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' }), - empty( [ 2, 2 ], { 'dtype': 'float32' }), - empty( [ 2, 2 ], { 'dtype': 'int32' }), - empty( [ 2, 2 ], { 'dtype': 'complex128' }), - empty( [ 2, 2 ], { 'dtype': 'generic' }) + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -124,17 +124,17 @@ bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' }), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' }), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' }), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' }), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' }) + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -184,17 +184,17 @@ bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' }), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' }), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' }), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' }), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' }) + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -244,17 +244,17 @@ bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { var v; var i; - /* eslint-disable object-curly-newline */ + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' }), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' }), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' }), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' }), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' }) + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) ]; - /* eslint-enable object-curly-newline */ + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt index 867ad36dde43..f22f43ef8470 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( x ) - Returns a new transposed ndarray. + Returns a new ndarray containing the elements of an input ndarray but whose + last two dimensions are transposed. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts index 4f2ce17a5a4c..e4d9a91b96d1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { ndarray } from '@stdlib/types/ndarray'; /** -* Returns a new transposed ndarray. +* Returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed. * * @param x - input array * @returns output ndarray @@ -37,7 +37,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var out = toTransposed( x ); * // returns [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ] */ -declare function toTransposed( x: ndarray ): ndarray; +declare function toTransposed( x: T ): T; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts index 9e54382f8bc2..16d1e6911e16 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/docs/types/test.ts @@ -27,7 +27,7 @@ import toTransposed = require( './index' ); const sh = [ 2, 2 ]; const ord = 'row-major'; - toTransposed( zeros( 'float64', sh, ord ) ); // $ExpectType ndarray + toTransposed( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js index 0eb0f841bfd3..0a5f29f278f9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return a new transposed ndarray. +* Return a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed. * * @module @stdlib/ndarray/base/to-transposed * diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js index 57c90477ac7b..dfa78a95ddb0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/lib/main.js @@ -20,20 +20,18 @@ // MODULES // -var getDType = require( '@stdlib/ndarray/base/dtype' ); -var getShape = require( '@stdlib/ndarray/base/shape' ); -var getOrder = require( '@stdlib/ndarray/base/order' ); var transpose = require( '@stdlib/ndarray/base/transpose' ); -var empty = require( '@stdlib/ndarray/base/empty' ); +var emptyLike = require( '@stdlib/ndarray/base/empty-like' ); var assign = require( '@stdlib/ndarray/base/assign' ); // MAIN // /** -* Returns a new transposed ndarray. +* Returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed. * * @param {ndarray} x - input array +* @throws {Error} must provide an array with two or more dimensions * @returns {ndarray} output ndarray * * @example @@ -48,18 +46,12 @@ var assign = require( '@stdlib/ndarray/base/assign' ); function toTransposed( x ) { var view; var out; - var tmp; - var sh; // Create transposed view of the input array: view = transpose( x, false ); // Create an output array: - sh = getShape( x, true ); - tmp = sh[ sh.length-1 ]; - sh[ sh.length-1 ] = sh[ sh.length-2 ]; - sh[ sh.length-2 ] = tmp; - out = empty( getDType( x ), sh, getOrder( x ) ); + out = emptyLike( view ); // Copy elements from transposed view to output array: assign( [ view, out ] ); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json b/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json index 60a77f260dd6..235c0c43a243 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/ndarray/base/to-transposed", "version": "0.0.0", - "description": "Return a new transposed ndarray.", + "description": "Return a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js index 275cf5803fa1..e1852212528f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-transposed/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); var Float64Array = require( '@stdlib/array/float64' ); var Float32Array = require( '@stdlib/array/float32' ); var Int32Array = require( '@stdlib/array/int32' ); @@ -37,6 +38,7 @@ var imag = require( '@stdlib/complex/float64/imag' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); var base = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); var array = require( '@stdlib/ndarray/array' ); var getData = require( '@stdlib/ndarray/data-buffer' ); var getDType = require( '@stdlib/ndarray/dtype' ); @@ -53,7 +55,28 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=float64, base)', function test( t ) { +tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { + var values; + var i; + + values = [ + new ndarray( 'float64', [], [], [ 0 ], 0, 'row-major' ), + new ndarray( 'float64', [ 1 ], [ 1 ], [ 1 ], 0, 'row-major' ) + ]; + + 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() { + toTransposed( value ); + }; + } +}); + +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=float64, base)', function test( t ) { var arr; var buf; var v1; @@ -66,7 +89,8 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, base)', fun x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -81,7 +105,7 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, base)', fun t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=float64, base, column-major)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=float64, base, column-major)', function test( t ) { var arr; var buf; var v1; @@ -94,7 +118,8 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, base, colum x = new base( 'float64', buf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -109,7 +134,7 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, base, colum t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=float64, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=float64, non-base)', function test( t ) { var arr; var buf; var v1; @@ -125,7 +150,8 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -140,7 +166,7 @@ tape( 'the function returns a new transposed ndarray (dtype=float64, non-base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=float32, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=float32, base)', function test( t ) { var arr; var buf; var v1; @@ -153,7 +179,8 @@ tape( 'the function returns a new transposed ndarray (dtype=float32, base)', fun x = new base( 'float32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -168,7 +195,7 @@ tape( 'the function returns a new transposed ndarray (dtype=float32, base)', fun t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=float32, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=float32, non-base)', function test( t ) { var arr; var buf; var v1; @@ -184,7 +211,8 @@ tape( 'the function returns a new transposed ndarray (dtype=float32, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -199,7 +227,7 @@ tape( 'the function returns a new transposed ndarray (dtype=float32, non-base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int32, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int32, base)', function test( t ) { var arr; var buf; var v1; @@ -212,7 +240,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int32, base)', funct x = new base( 'int32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -227,7 +256,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int32, base)', funct t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int32, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int32, non-base)', function test( t ) { var arr; var buf; var v1; @@ -243,7 +272,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int32, non-base)', f }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -258,7 +288,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int32, non-base)', f t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int16, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int16, base)', function test( t ) { var arr; var buf; var v1; @@ -271,7 +301,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int16, base)', funct x = new base( 'int16', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -286,7 +317,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int16, base)', funct t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int16, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int16, non-base)', function test( t ) { var arr; var buf; var v1; @@ -302,7 +333,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int16, non-base)', f }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -317,7 +349,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int16, non-base)', f t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int8, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int8, base)', function test( t ) { var arr; var buf; var v1; @@ -330,7 +362,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int8, base)', functi x = new base( 'int8', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -345,7 +378,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int8, base)', functi t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=int8, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=int8, non-base)', function test( t ) { var arr; var buf; var v1; @@ -361,7 +394,8 @@ tape( 'the function returns a new transposed ndarray (dtype=int8, non-base)', fu }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -376,7 +410,7 @@ tape( 'the function returns a new transposed ndarray (dtype=int8, non-base)', fu t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint32, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint32, base)', function test( t ) { var arr; var buf; var v1; @@ -389,7 +423,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint32, base)', func x = new base( 'uint32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -404,7 +439,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint32, base)', func t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint32, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint32, non-base)', function test( t ) { var arr; var buf; var v1; @@ -420,7 +455,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint32, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -435,7 +471,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint32, non-base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint16, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint16, base)', function test( t ) { var arr; var buf; var v1; @@ -448,7 +484,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint16, base)', func x = new base( 'uint16', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -463,7 +500,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint16, base)', func t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint16, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint16, non-base)', function test( t ) { var arr; var buf; var v1; @@ -479,7 +516,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint16, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -494,7 +532,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint16, non-base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint8, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint8, base)', function test( t ) { var arr; var buf; var v1; @@ -507,7 +545,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8, base)', funct x = new base( 'uint8', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -522,7 +561,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8, base)', funct t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint8, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint8, non-base)', function test( t ) { var arr; var buf; var v1; @@ -538,7 +577,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8, non-base)', f }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -553,7 +593,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8, non-base)', f t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint8c, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint8c, base)', function test( t ) { var arr; var buf; var v1; @@ -566,7 +606,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8c, base)', func x = new base( 'uint8c', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -581,7 +622,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8c, base)', func t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=uint8c, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=uint8c, non-base)', function test( t ) { var arr; var buf; var v1; @@ -597,7 +638,8 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8c, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -612,7 +654,7 @@ tape( 'the function returns a new transposed ndarray (dtype=uint8c, non-base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=complex128, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=complex128, base)', function test( t ) { var arr; var buf; var v1; @@ -625,7 +667,8 @@ tape( 'the function returns a new transposed ndarray (dtype=complex128, base)', x = new base( 'complex128', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -641,7 +684,7 @@ tape( 'the function returns a new transposed ndarray (dtype=complex128, base)', t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=complex128, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=complex128, non-base)', function test( t ) { var arr; var buf; var v1; @@ -657,7 +700,8 @@ tape( 'the function returns a new transposed ndarray (dtype=complex128, non-base }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -673,7 +717,7 @@ tape( 'the function returns a new transposed ndarray (dtype=complex128, non-base t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=complex64, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=complex64, base)', function test( t ) { var arr; var buf; var v1; @@ -686,7 +730,8 @@ tape( 'the function returns a new transposed ndarray (dtype=complex64, base)', f x = new base( 'complex64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -702,7 +747,7 @@ tape( 'the function returns a new transposed ndarray (dtype=complex64, base)', f t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=complex64, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=complex64, non-base)', function test( t ) { var arr; var buf; var v1; @@ -718,7 +763,8 @@ tape( 'the function returns a new transposed ndarray (dtype=complex64, non-base) }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -734,7 +780,7 @@ tape( 'the function returns a new transposed ndarray (dtype=complex64, non-base) t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=generic, base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=generic, base)', function test( t ) { var arr; var buf; var v1; @@ -747,7 +793,8 @@ tape( 'the function returns a new transposed ndarray (dtype=generic, base)', fun x = new base( 'generic', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -762,7 +809,7 @@ tape( 'the function returns a new transposed ndarray (dtype=generic, base)', fun t.end(); }); -tape( 'the function returns a new transposed ndarray (dtype=generic, non-base)', function test( t ) { +tape( 'the function returns a new ndarray containing the elements of an input ndarray but whose last two dimensions are transposed (dtype=generic, non-base)', function test( t ) { var arr; var buf; var v1; @@ -778,7 +825,8 @@ tape( 'the function returns a new transposed ndarray (dtype=generic, non-base)', }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -807,7 +855,8 @@ tape( 'the function supports stack of matrices (base)', function test( t ) { x = new base( 'generic', buf, [ 4, 2, 3 ], [ 0, 3, 1 ], 0, 'row-major' ); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 4, 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); @@ -841,7 +890,8 @@ tape( 'the function supports stack of matrices (non-base)', function test( t ) { }); arr = toTransposed( x ); - t.strictEqual( getDType( arr ), getDType( x ), 'returns expected value' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 4, 3, 2 ], 'returns expected value' ); t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' );