From 90a9e336ed38fcf44c7fdc9dcac4a8531f880b39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:25:07 +0000 Subject: [PATCH] Auto-generated commit --- dist/index.js | 6 +++--- dist/index.js.map | 6 +++--- lib/main.js | 14 ++++++++++---- package.json | 6 ++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 9d9d4a2..f6cc44c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ -"use strict";var d=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var u=d(function(h,o){ -var f=require('@stdlib/ndarray-base-assert-is-read-only/dist');function v(r){var e,s,n,i,a,t;for(n=r.shape,i=r.strides,a=n.length,e=[],s=[],t=0;t\n*\n* var shx = x.shape;\n* // returns [ 1, 1, 1, 2, 2 ]\n*\n* var y = removeSingletonDimensions( x );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 2, 2 ]\n*\n* var v = y.get( 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0 );\n* // returns 3\n*\n* v = y.get( 1, 1 );\n* // returns 4\n*/\nfunction removeSingletonDimensions( x ) {\n\tvar strides;\n\tvar shape;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar i;\n\n\tsh = x.shape;\n\tst = x.strides;\n\tN = sh.length;\n\n\tstrides = [];\n\tshape = [];\n\n\t// Check for singleton dimensions...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( sh[ i ] !== 1 ) {\n\t\t\tshape.push( sh[ i ] );\n\t\t\tstrides.push( st[ i ] );\n\t\t}\n\t}\n\tif ( shape.length === N ) {\n\t\t// We did not find any singleton dimensions...\n\t\treturn x;\n\t}\n\tif ( isReadOnly( x ) ) {\n\t\t// If provided a read-only view, the returned array should also be read-only...\n\t\treturn new x.constructor( x.dtype, x.data, shape, strides, x.offset, x.order, { // eslint-disable-line max-len\n\t\t\t'readonly': true\n\t\t});\n\t}\n\treturn new x.constructor( x.dtype, x.data, shape, strides, x.offset, x.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = removeSingletonDimensions;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Remove singleton dimensions.\n*\n* @module @stdlib/ndarray-base-remove-singleton-dimensions\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var removeSingletonDimensions = require( '@stdlib/ndarray-base-remove-singleton-dimensions' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {\n* 'ndmin': 5\n* });\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 1, 1, 1, 2, 2 ]\n*\n* var y = removeSingletonDimensions( x );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 2, 2 ]\n*\n* var v = y.get( 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0 );\n* // returns 3\n*\n* v = y.get( 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,0CAA2C,EA6CrE,SAASC,EAA2BC,EAAI,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,IARAH,EAAKH,EAAE,MACPI,EAAKJ,EAAE,QACPK,EAAIF,EAAG,OAEPF,EAAU,CAAC,EACXC,EAAQ,CAAC,EAGHI,EAAI,EAAGA,EAAID,EAAGC,IACdH,EAAIG,CAAE,IAAM,IAChBJ,EAAM,KAAMC,EAAIG,CAAE,CAAE,EACpBL,EAAQ,KAAMG,EAAIE,CAAE,CAAE,GAGxB,OAAKJ,EAAM,SAAWG,EAEdL,EAEHF,EAAYE,CAAE,EAEX,IAAIA,EAAE,YAAaA,EAAE,MAAOA,EAAE,KAAME,EAAOD,EAASD,EAAE,OAAQA,EAAE,MAAO,CAC7E,SAAY,EACb,CAAC,EAEK,IAAIA,EAAE,YAAaA,EAAE,MAAOA,EAAE,KAAME,EAAOD,EAASD,EAAE,OAAQA,EAAE,KAAM,CAC9E,CAKAH,EAAO,QAAUE,IC/CjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isReadOnly", "removeSingletonDimensions", "x", "strides", "shape", "sh", "st", "N", "i", "main"] + "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\n\n\n// MAIN //\n\n/**\n* Returns an array without singleton dimensions.\n*\n* ## Notes\n*\n* - If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged.\n* - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view.\n*\n* @param {ndarray} x - input array\n* @returns {ndarray} squeezed array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {\n* 'ndmin': 5\n* });\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 1, 1, 1, 2, 2 ]\n*\n* var y = removeSingletonDimensions( x );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 2, 2 ]\n*\n* var v = y.get( 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0 );\n* // returns 3\n*\n* v = y.get( 1, 1 );\n* // returns 4\n*/\nfunction removeSingletonDimensions( x ) {\n\tvar strides;\n\tvar shape;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar i;\n\n\tsh = getShape( x, false );\n\tst = getStrides( x, false );\n\tN = sh.length;\n\n\tstrides = [];\n\tshape = [];\n\n\t// Check for singleton dimensions...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( sh[ i ] !== 1 ) {\n\t\t\tshape.push( sh[ i ] );\n\t\t\tstrides.push( st[ i ] );\n\t\t}\n\t}\n\tif ( shape.length === N ) {\n\t\t// We did not find any singleton dimensions...\n\t\treturn x;\n\t}\n\tif ( isReadOnly( x ) ) {\n\t\t// If provided a read-only view, the returned array should also be read-only...\n\t\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ), { // eslint-disable-line max-len\n\t\t\t'readonly': true\n\t\t});\n\t}\n\treturn new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = removeSingletonDimensions;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Remove singleton dimensions.\n*\n* @module @stdlib/ndarray-base-remove-singleton-dimensions\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var removeSingletonDimensions = require( '@stdlib/ndarray-base-remove-singleton-dimensions' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {\n* 'ndmin': 5\n* });\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 1, 1, 1, 2, 2 ]\n*\n* var y = removeSingletonDimensions( x );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 2, 2 ]\n*\n* var v = y.get( 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0 );\n* // returns 3\n*\n* v = y.get( 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,0CAA2C,EACjEC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EA6C1D,SAASC,EAA2BC,EAAI,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAUJ,IARAH,EAAKT,EAAUM,EAAG,EAAM,EACxBI,EAAKT,EAAYK,EAAG,EAAM,EAC1BK,EAAIF,EAAG,OAEPF,EAAU,CAAC,EACXC,EAAQ,CAAC,EAGHI,EAAI,EAAGA,EAAID,EAAGC,IACdH,EAAIG,CAAE,IAAM,IAChBJ,EAAM,KAAMC,EAAIG,CAAE,CAAE,EACpBL,EAAQ,KAAMG,EAAIE,CAAE,CAAE,GAGxB,OAAKJ,EAAM,SAAWG,EAEdL,EAEHR,EAAYQ,CAAE,EAEX,IAAIA,EAAE,YAAaP,EAAUO,CAAE,EAAGF,EAASE,CAAE,EAAGE,EAAOD,EAASL,EAAWI,CAAE,EAAGH,EAAUG,CAAE,EAAG,CACrG,SAAY,EACb,CAAC,EAEK,IAAIA,EAAE,YAAaP,EAAUO,CAAE,EAAGF,EAASE,CAAE,EAAGE,EAAOD,EAASL,EAAWI,CAAE,EAAGH,EAAUG,CAAE,CAAE,CACtG,CAKAT,EAAO,QAAUQ,ICrDjB,IAAIQ,EAAO,IAKX,OAAO,QAAUA", + "names": ["require_main", "__commonJSMin", "exports", "module", "isReadOnly", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "removeSingletonDimensions", "x", "strides", "shape", "sh", "st", "N", "i", "main"] } diff --git a/lib/main.js b/lib/main.js index 81e6bc7..9f10a54 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,6 +21,12 @@ // 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' ); +var getOffset = require( '@stdlib/ndarray-base-offset' ); +var getOrder = require( '@stdlib/ndarray-base-order' ); +var getData = require( '@stdlib/ndarray-base-data-buffer' ); // MAIN // @@ -73,8 +79,8 @@ function removeSingletonDimensions( x ) { var N; var i; - sh = x.shape; - st = x.strides; + sh = getShape( x, false ); + st = getStrides( x, false ); N = sh.length; strides = []; @@ -93,11 +99,11 @@ function removeSingletonDimensions( x ) { } if ( isReadOnly( x ) ) { // If provided a read-only view, the returned array should also be read-only... - return new x.constructor( x.dtype, x.data, shape, strides, x.offset, x.order, { // 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': true }); } - return new x.constructor( x.dtype, x.data, shape, strides, x.offset, x.order ); // eslint-disable-line max-len + return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), getOrder( x ) ); // eslint-disable-line max-len } diff --git a/package.json b/package.json index ce1bfb8..f11dc98 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,12 @@ }, "dependencies": { "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", + "@stdlib/ndarray-base-data-buffer": "github:stdlib-js/ndarray-base-data-buffer#main", + "@stdlib/ndarray-base-dtype": "github:stdlib-js/ndarray-base-dtype#main", + "@stdlib/ndarray-base-offset": "github:stdlib-js/ndarray-base-offset#main", + "@stdlib/ndarray-base-order": "github:stdlib-js/ndarray-base-order#main", + "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", + "@stdlib/ndarray-base-strides": "github:stdlib-js/ndarray-base-strides#main", "@stdlib/types": "^0.1.0" }, "devDependencies": {