From 753ad36eb05555927fa004000a2980fde6dd0592 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 10 Jan 2026 12:03:34 +0500 Subject: [PATCH 1/5] feat: add writable parameter --- 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: 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 --- --- .../remove-singleton-dimensions/README.md | 42 +++------- .../benchmark/benchmark.js | 17 ++-- .../benchmark/benchmark.ndims.js | 5 +- .../remove-singleton-dimensions/docs/repl.txt | 23 ++---- .../docs/types/index.d.ts | 25 +----- .../docs/types/test.ts | 32 +++++--- .../examples/index.js | 30 ++----- .../remove-singleton-dimensions/lib/index.js | 21 +---- .../remove-singleton-dimensions/lib/main.js | 35 ++------ .../remove-singleton-dimensions/test/test.js | 81 +++++++------------ 10 files changed, 102 insertions(+), 209 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md index f5de94717b5d..d4bad1e6d462 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md @@ -49,16 +49,18 @@ var array = require( '@stdlib/ndarray/array' ); // Create a 1x2x2 ndarray: var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); -// returns +// returns [ [ [ 1, 2 ], [ 3, 4 ] ] ] // Remove singleton dimensions: var y = removeSingletonDimensions( x ); -// returns - -var sh = y.shape; -// returns [ 2, 2 ] +// returns [ [ 1, 2 ], [ 3, 4 ] ] ``` +The function accepts the following arguments: + +- **x**: input ndarray. +- **writable**: boolean indicating whether a returned ndarray should be writable. + @@ -85,33 +87,15 @@ var sh = y.shape; ```javascript -var array = require( '@stdlib/ndarray/array' ); -var numel = require( '@stdlib/ndarray/base/numel' ); -var ind2sub = require( '@stdlib/ndarray/ind2sub' ); +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' ); -// Create a 5-dimensional array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { - 'ndmin': 5 -}); -// returns - -// Remove singleton dimensions: -var y = removeSingletonDimensions( x ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} +var y = removeSingletonDimensions( x, false ); +console.log( ndarray2array( y ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.js index cfca24fd32d1..60f6e0d03a73 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.js @@ -25,13 +25,14 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarrayBase = require( '@stdlib/ndarray/base/ctor' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var removeSingletonDimensions = require( './../lib' ); // MAIN // -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { +bench( format( '%s::base_ndarray,2d', pkg ), function benchmark( b ) { var strides; var values; var buffer; @@ -59,7 +60,7 @@ bench( pkg+'::base_ndarray,2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = removeSingletonDimensions( values[ i%values.length ] ); + out = removeSingletonDimensions( values[ i%values.length ], false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } @@ -72,7 +73,7 @@ bench( pkg+'::base_ndarray,2d', function benchmark( b ) { b.end(); }); -bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b ) { +bench( format( '%s::base_ndarray,2d,no_singleton_dimensions', pkg ), function benchmark( b ) { var strides; var values; var buffer; @@ -100,7 +101,7 @@ bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b ) b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = removeSingletonDimensions( values[ i%values.length ] ); + out = removeSingletonDimensions( values[ i%values.length ], false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } @@ -113,7 +114,7 @@ bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b ) b.end(); }); -bench( pkg+'::ndarray,2d', function benchmark( b ) { +bench( format( '%s::ndarray,2d', pkg ), function benchmark( b ) { var strides; var values; var buffer; @@ -141,7 +142,7 @@ bench( pkg+'::ndarray,2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = removeSingletonDimensions( values[ i%values.length ] ); + out = removeSingletonDimensions( values[ i%values.length ], false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } @@ -154,7 +155,7 @@ bench( pkg+'::ndarray,2d', function benchmark( b ) { b.end(); }); -bench( pkg+'::ndarray,2d,no_singleton_dimensions', function benchmark( b ) { +bench( format( '%s::ndarray,2d,no_singleton_dimensions', pkg ), function benchmark( b ) { var strides; var values; var buffer; @@ -182,7 +183,7 @@ bench( pkg+'::ndarray,2d,no_singleton_dimensions', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = removeSingletonDimensions( values[ i%values.length ] ); + out = removeSingletonDimensions( values[ i%values.length ], false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js index 3573c7055d0e..b77034a6d8bc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js @@ -23,6 +23,7 @@ var bench = require( '@stdlib/bench' ); var array = require( '@stdlib/ndarray/array' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var removeSingletonDimensions = require( './../lib' ); @@ -54,7 +55,7 @@ function createBenchmark( ndims ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = removeSingletonDimensions( x ); + out = removeSingletonDimensions( x, false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } @@ -87,7 +88,7 @@ function main() { for ( i = min; i <= max; i++ ) { f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:singleton_dimensions='+i, f ); + bench( format( '%s::ndarray,2d:singleton_dimensions=%s', pkg, i ), f ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt index b98834b89d8a..aabc49cd0464 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x ) +{{alias}}( x, writable ) Returns an array without singleton dimensions. If a provided ndarray does not have any singleton dimensions, the function @@ -13,6 +13,9 @@ x: ndarray Input array. + writable: boolean + Boolean indicating whether a returned array should be writable. + Returns ------- out: ndarray @@ -21,21 +24,9 @@ Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ], { 'ndmin': 5 } ) - - > var sh = x.shape - [ 1, 1, 1, 2, 2 ] - > var y = {{alias}}( x ) - - > sh = y.shape - [ 2, 2 ] - > var v = y.get( 0, 0 ) - 1 - > v = y.get( 0, 1 ) - 2 - > v = y.get( 1, 0 ) - 3 - > v = y.get( 1, 1 ) - 4 + [ [ [ [ [1, 2 ], [ 3, 4 ] ] ] ] ] + > var y = {{alias}}( x, false ) + [ [ 1, 2 ], [ 3, 4 ] ] See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts index edca210957f5..64b866c6441d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts @@ -31,6 +31,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view. * * @param x - input array +* @param writable - boolean indicating whether a returned array should be writable * @returns squeezed array * * @example @@ -39,30 +40,12 @@ import { ndarray } from '@stdlib/types/ndarray'; * var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { * 'ndmin': 5 * }); -* // returns -* -* var shx = x.shape; -* // returns [ 1, 1, 1, 2, 2 ] +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * * var y = removeSingletonDimensions( x ); -* // returns -* -* var shy = y.shape; -* // returns [ 2, 2 ] -* -* var v = y.get( 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0 ); -* // returns 3 -* -* v = y.get( 1, 1 ); -* // returns 4 +* // returns [ [ 1, 2 ], [ 3, 4 ] ] */ -declare function removeSingletonDimensions( x: ndarray ): ndarray; +declare function removeSingletonDimensions( x: ndarray, writable: boolean ): ndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts index 9369e480e0b5..52cd96acd033 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts @@ -26,19 +26,31 @@ import removeSingletonDimensions = require( './index' ); { const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - removeSingletonDimensions( x ); // $ExpectType ndarray + removeSingletonDimensions( x, false ); // $ExpectType ndarray } // The compiler throws an error if the function is not provided a first argument which is an ndarray... { - removeSingletonDimensions( '5' ); // $ExpectError - removeSingletonDimensions( 5 ); // $ExpectError - removeSingletonDimensions( true ); // $ExpectError - removeSingletonDimensions( false ); // $ExpectError - removeSingletonDimensions( null ); // $ExpectError - removeSingletonDimensions( {} ); // $ExpectError - removeSingletonDimensions( [ '5' ] ); // $ExpectError - removeSingletonDimensions( ( x: number ): number => x ); // $ExpectError + removeSingletonDimensions( '5', false ); // $ExpectError + removeSingletonDimensions( 5, false ); // $ExpectError + removeSingletonDimensions( true, false ); // $ExpectError + removeSingletonDimensions( false, false ); // $ExpectError + removeSingletonDimensions( null, false ); // $ExpectError + removeSingletonDimensions( {}, false ); // $ExpectError + removeSingletonDimensions( [ '5' ], false ); // $ExpectError + removeSingletonDimensions( ( x: number ): number => x, false ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a first argument which is a boolean... +{ + const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + + removeSingletonDimensions( x, '5' ); // $ExpectError + removeSingletonDimensions( x, 5 ); // $ExpectError + removeSingletonDimensions( x, null ); // $ExpectError + removeSingletonDimensions( x, {} ); // $ExpectError + removeSingletonDimensions( x, [ '5' ] ); // $ExpectError + removeSingletonDimensions( x, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -46,5 +58,5 @@ import removeSingletonDimensions = require( './index' ); const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); removeSingletonDimensions(); // $ExpectError - removeSingletonDimensions( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError + removeSingletonDimensions( x, false, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js index b9bf8d542b31..2ec8d1e98206 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js @@ -18,30 +18,12 @@ 'use strict'; -var array = require( '@stdlib/ndarray/array' ); -var numel = require( '@stdlib/ndarray/base/numel' ); -var ind2sub = require( '@stdlib/ndarray/ind2sub' ); +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var removeSingletonDimensions = require( './../lib' ); -// Create a 5-dimensional array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { - 'ndmin': 5 -}); -// returns +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); -// Remove singleton dimensions: -var y = removeSingletonDimensions( x ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} +var y = removeSingletonDimensions( x, false ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js index 31b5ba30a4a0..f5267d746491 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js @@ -30,28 +30,13 @@ * var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { * 'ndmin': 5 * }); -* // returns +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * * var shx = x.shape; * // returns [ 1, 1, 1, 2, 2 ] * -* var y = removeSingletonDimensions( x ); -* // returns -* -* var shy = y.shape; -* // returns [ 2, 2 ] -* -* var v = y.get( 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0 ); -* // returns 3 -* -* v = y.get( 1, 1 ); -* // returns 4 +* var y = removeSingletonDimensions( x, false ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js index e3ab756fd771..36bc4fbf6ca6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js @@ -20,7 +20,6 @@ // MODULES // -var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); var getDType = require( '@stdlib/ndarray/base/dtype' ); var getShape = require( '@stdlib/ndarray/base/shape' ); var getStrides = require( '@stdlib/ndarray/base/strides' ); @@ -40,6 +39,7 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view. * * @param {ndarray} x - input array +* @param {boolean} writable - boolean indicating whether a returned array should be writable * @returns {ndarray} squeezed array * * @example @@ -48,30 +48,15 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { * 'ndmin': 5 * }); -* // returns +* // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * * var shx = x.shape; * // returns [ 1, 1, 1, 2, 2 ] * -* var y = removeSingletonDimensions( x ); -* // returns -* -* var shy = y.shape; -* // returns [ 2, 2 ] -* -* var v = y.get( 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0 ); -* // returns 3 -* -* v = y.get( 1, 1 ); -* // returns 4 +* var y = removeSingletonDimensions( x, false ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] */ -function removeSingletonDimensions( x ) { +function removeSingletonDimensions( x, writable ) { var strides; var shape; var sh; @@ -97,13 +82,9 @@ function removeSingletonDimensions( x ) { // We did not find any singleton dimensions... return x; } - if ( isReadOnly( x ) ) { - // If provided a read-only view, the returned array should also be read-only... - return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len - 'readonly': true - }); - } - return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ) ); // eslint-disable-line max-len + return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len + 'readonly': !writable + }); } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js index c4694217f175..3e9fa82f3de8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js @@ -43,10 +43,20 @@ tape( 'if a provided array does not contain singleton dimensions, the function r x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); sh = x.shape; - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, sh, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); + + x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); + sh = x.shape; + + y = removeSingletonDimensions( x, true ); + + t.strictEqual( y, x, 'returns expected value' ); + t.deepEqual( y.shape, sh, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -59,7 +69,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); sh = x.shape; - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, sh, 'returns expected value' ); @@ -67,7 +77,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (0D)', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, 0D)', function test( t ) { var sh; var x; var y; @@ -75,7 +85,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r x = ndarray( 'generic', [ 1 ], [], [ 0 ], 0, 'row-major' ); sh = x.shape; - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, sh, 'returns expected value' ); @@ -83,7 +93,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (empty)', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, empty)', function test( t ) { var sh; var x; var y; @@ -91,7 +101,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); sh = x.shape; - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, sh, 'returns expected value' ); @@ -107,75 +117,39 @@ tape( 'the function removes singleton dimensions (leading)', function test( t ) 'ndmin': 5 }); - y = removeSingletonDimensions( x ); - - t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function removes singleton dimensions (trailing)', function test( t ) { - var x; - var y; - - x = array( [ 1, 2, 3, 4 ], { - 'shape': [ 2, 1, 2, 1, 1, 1 ] - }); - - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); t.strictEqual( y.data, x.data, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function removes singleton dimensions (base)', function test( t ) { - var x; - var y; - - x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 1, 1, 2, 1, 2 ], [ 4, 4, 2, 2, 1 ], 0, 'row-major' ); - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); t.strictEqual( y.data, x.data, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); -tape( 'if provided a read-only array, the function returns a read-only array', function test( t ) { +tape( 'the function removes singleton dimensions (trailing)', function test( t ) { var x; var y; x = array( [ 1, 2, 3, 4 ], { - 'shape': [ 2, 1, 2, 1, 1, 1 ], - 'readonly': true + 'shape': [ 2, 1, 2, 1, 1, 1 ] }); - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); t.strictEqual( y.data, x.data, 'returns expected value' ); t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a writable array, the function returns a writable array', function test( t ) { - var x; - var y; - - x = array( [ 1, 2, 3, 4 ], { - 'shape': [ 2, 1, 2, 1, 1, 1 ], - 'readonly': false - }); - - y = removeSingletonDimensions( x ); + y = removeSingletonDimensions( x, true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); @@ -185,17 +159,16 @@ tape( 'if provided a writable array, the function returns a writable array', fun t.end(); }); -tape( 'if provided a writable array, the function returns a writable array (base)', function test( t ) { +tape( 'the function removes singleton dimensions (base)', function test( t ) { var x; var y; - x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); - y = removeSingletonDimensions( x ); + x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 1, 1, 2, 1, 2 ], [ 4, 4, 2, 2, 1 ], 0, 'row-major' ); + y = removeSingletonDimensions( x, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); t.strictEqual( y.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); From 04ec3e9e28ef463697f83f0887d0d9bcd6f27387 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 10 Jan 2026 01:32:31 -0800 Subject: [PATCH 2/5] docs: fix missing parameter Signed-off-by: Athan --- .../@stdlib/ndarray/base/remove-singleton-dimensions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md index d4bad1e6d462..ea1891ae11c3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md @@ -40,7 +40,7 @@ limitations under the License. var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' ); ``` -#### removeSingletonDimensions( x ) +#### removeSingletonDimensions( x, writable ) Returns an ndarray without singleton dimensions (i.e., dimensions whose size is equal to `1`). From ae311be8f4b6d93a648ec2eb1ced9e6cfdea4af9 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 10 Jan 2026 01:33:28 -0800 Subject: [PATCH 3/5] docs: fix missing parameter in function call Signed-off-by: Athan --- .../@stdlib/ndarray/base/remove-singleton-dimensions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md index ea1891ae11c3..34967763b600 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md @@ -52,7 +52,7 @@ var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); // returns [ [ [ 1, 2 ], [ 3, 4 ] ] ] // Remove singleton dimensions: -var y = removeSingletonDimensions( x ); +var y = removeSingletonDimensions( x, false ); // returns [ [ 1, 2 ], [ 3, 4 ] ] ``` From fbe9a4b70535ef09c34ad1871b82b7847722c6a5 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 10 Jan 2026 22:20:14 +0500 Subject: [PATCH 4/5] refactor: add 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: na - 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 --- --- .../remove-singleton-dimensions/README.md | 2 +- .../benchmark/benchmark.ndims.js | 2 +- .../docs/types/index.d.ts | 2 +- .../docs/types/test.ts | 3 +- .../examples/index.js | 2 +- .../remove-singleton-dimensions/lib/index.js | 3 -- .../remove-singleton-dimensions/lib/main.js | 3 -- .../remove-singleton-dimensions/test/test.js | 39 ++++++++----------- 8 files changed, 22 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md index 34967763b600..8c9ffe5f0490 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md @@ -91,7 +91,7 @@ var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' ); -var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +var x = uniform( [ 1, 1, 3, 3, 3 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); var y = removeSingletonDimensions( x, false ); diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js index b77034a6d8bc..98f0753e7177 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/benchmark/benchmark.ndims.js @@ -88,7 +88,7 @@ function main() { for ( i = min; i <= max; i++ ) { f = createBenchmark( i ); - bench( format( '%s::ndarray,2d:singleton_dimensions=%s', pkg, i ), f ); + bench( format( '%s::ndarray,2d:singleton_dimensions=%d', pkg, i ), f ); } } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts index 64b866c6441d..20e41e16e437 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts @@ -42,7 +42,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * }); * // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * -* var y = removeSingletonDimensions( x ); +* var y = removeSingletonDimensions( x, false ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] */ declare function removeSingletonDimensions( x: ndarray, writable: boolean ): ndarray; diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts index 52cd96acd033..2c4ce0a1218b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/test.ts @@ -41,7 +41,7 @@ import removeSingletonDimensions = require( './index' ); removeSingletonDimensions( ( x: number ): number => x, false ); // $ExpectError } -// The compiler throws an error if the function is not provided a first argument which is a boolean... +// The compiler throws an error if the function is not provided a second argument which is a boolean... { const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); @@ -58,5 +58,6 @@ import removeSingletonDimensions = require( './index' ); const x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); removeSingletonDimensions(); // $ExpectError + removeSingletonDimensions( x ); // $ExpectError removeSingletonDimensions( x, false, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js index 2ec8d1e98206..21b43da0097f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/examples/index.js @@ -22,7 +22,7 @@ var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var removeSingletonDimensions = require( './../lib' ); -var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +var x = uniform( [ 1, 1, 3, 3, 3 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); var y = removeSingletonDimensions( x, false ); diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js index f5267d746491..4010399b87d3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js @@ -32,9 +32,6 @@ * }); * // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * -* var shx = x.shape; -* // returns [ 1, 1, 1, 2, 2 ] -* * var y = removeSingletonDimensions( x, false ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] */ diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js index 36bc4fbf6ca6..7d5064bdad25 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js @@ -50,9 +50,6 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * }); * // returns [ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ] * -* var shx = x.shape; -* // returns [ 1, 1, 1, 2, 2 ] -* * var y = removeSingletonDimensions( x, false ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] */ diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js index 3e9fa82f3de8..2bb97d201de9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js @@ -22,6 +22,8 @@ var tape = require( 'tape' ); var array = require( '@stdlib/ndarray/array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); var removeSingletonDimensions = require( './../lib' ); @@ -36,75 +38,66 @@ tape( 'main export is a function', function test( t ) { }); tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged', function test( t ) { - var sh; var x; var y; x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, sh, 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; y = removeSingletonDimensions( x, true ); t.strictEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, sh, 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base)', function test( t ) { - var sh; var x; var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - sh = x.shape; y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, sh, 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end(); }); tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, 0D)', function test( t ) { - var sh; var x; var y; x = ndarray( 'generic', [ 1 ], [], [ 0 ], 0, 'row-major' ); - sh = x.shape; y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, sh, 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end(); }); tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, empty)', function test( t ) { - var sh; var x; var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - sh = x.shape; y = removeSingletonDimensions( x, false ); t.strictEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, sh, 'returns expected value' ); + t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end(); }); @@ -120,15 +113,15 @@ tape( 'the function removes singleton dimensions (leading)', function test( t ) y = removeSingletonDimensions( x, false ); t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); y = removeSingletonDimensions( x, true ); t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); @@ -145,15 +138,15 @@ tape( 'the function removes singleton dimensions (trailing)', function test( t ) y = removeSingletonDimensions( x, false ); t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); y = removeSingletonDimensions( x, true ); t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); @@ -168,7 +161,7 @@ tape( 'the function removes singleton dimensions (base)', function test( t ) { t.notEqual( y, x, 'returns expected value' ); t.deepEqual( y.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( y.data, x.data, 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); t.end(); }); From 69dcd01051dd39a8f8957c93cd4892db773b11ff Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 11 Jan 2026 15:47:54 +0500 Subject: [PATCH 5/5] 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: na - 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 --- --- .../remove-singleton-dimensions/README.md | 3 +-- .../remove-singleton-dimensions/docs/repl.txt | 6 +----- .../docs/types/index.d.ts | 3 +-- .../remove-singleton-dimensions/lib/main.js | 6 +++--- .../remove-singleton-dimensions/test/test.js | 20 +++++++++---------- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md index 8c9ffe5f0490..fdb967f088ef 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md @@ -71,8 +71,7 @@ The function accepts the following arguments: ## Notes -- If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged. -- If a provided ndarray does have singleton dimensions, the function returns a new ndarray view. +- The function always returns a new view of the input ndarray. diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt index aabc49cd0464..e4e369eacf0f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/repl.txt @@ -2,11 +2,7 @@ {{alias}}( x, writable ) Returns an array without singleton dimensions. - If a provided ndarray does not have any singleton dimensions, the function - returns the provided ndarray unchanged. - - If a provided ndarray does have singleton dimensions, the function returns a - new ndarray view. + The function always returns a new view of the input ndarray. Parameters ---------- diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts index 20e41e16e437..23b5ae3b0774 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/docs/types/index.d.ts @@ -27,8 +27,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * * ## Notes * -* - If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged. -* - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view. +* - The function always returns a new view of the input ndarray. * * @param x - input array * @param writable - boolean indicating whether a returned array should be writable diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js index 7d5064bdad25..5bfb5fd3752f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js @@ -35,8 +35,7 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * * ## Notes * -* - If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged. -* - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view. +* - The function always returns a new view of the input ndarray. * * @param {ndarray} x - input array * @param {boolean} writable - boolean indicating whether a returned array should be writable @@ -77,7 +76,8 @@ function removeSingletonDimensions( x, writable ) { } if ( shape.length === N ) { // We did not find any singleton dimensions... - return x; + shape = sh; + strides = st; } return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len 'readonly': !writable diff --git a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js index 2bb97d201de9..9db2198c2109 100644 --- a/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js @@ -37,7 +37,7 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns a new view of the input array', function test( t ) { var x; var y; @@ -45,22 +45,22 @@ tape( 'if a provided array does not contain singleton dimensions, the function r y = removeSingletonDimensions( x, false ); - t.strictEqual( y, x, 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); y = removeSingletonDimensions( x, true ); - t.strictEqual( y, x, 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base)', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns a new view of the input array (base)', function test( t ) { var x; var y; @@ -68,13 +68,13 @@ tape( 'if a provided array does not contain singleton dimensions, the function r y = removeSingletonDimensions( x, false ); - t.strictEqual( y, x, 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, 0D)', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns a new view of the input array (base, 0D)', function test( t ) { var x; var y; @@ -82,13 +82,13 @@ tape( 'if a provided array does not contain singleton dimensions, the function r y = removeSingletonDimensions( x, false ); - t.strictEqual( y, x, 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end(); }); -tape( 'if a provided array does not contain singleton dimensions, the function returns the provided array unchanged (base, empty)', function test( t ) { +tape( 'if a provided array does not contain singleton dimensions, the function returns a new view of the input array (base, empty)', function test( t ) { var x; var y; @@ -96,7 +96,7 @@ tape( 'if a provided array does not contain singleton dimensions, the function r y = removeSingletonDimensions( x, false ); - t.strictEqual( y, x, 'returns expected value' ); + t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), getShape( x ), 'returns expected value' ); t.end();