diff --git a/lib/node_modules/@stdlib/slice/base/shape/README.md b/lib/node_modules/@stdlib/slice/base/shape/README.md new file mode 100644 index 00000000000..55517f3ce18 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/README.md @@ -0,0 +1,158 @@ + + +# sliceShape + +> Compute the shape of a [normalized multi-slice][@stdlib/slice/base/normalize-multi-slice]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var sliceShape = require( '@stdlib/slice/base/shape' ); +``` + + + +#### sliceShape( slice ) + +Returns the shape of a [normalized multi-slice][@stdlib/slice/base/normalize-multi-slice]. + + + +```javascript +var S = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); + +var s = new MultiSlice( S( -4, null, -1 ), S( 2, 10, 1 ) ); +// returns + +s = normalizeMultiSlice( s, [ 10, 10 ], false ); +// returns + +var sh = sliceShape( s ); +// returns [ 7, 8 ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + + + +```javascript +var S = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +var sliceShape = require( '@stdlib/slice/base/shape' ); + +var s1 = new MultiSlice( S( 3, null, -1 ), S( 3, 7, 1 ) ); +var s2 = normalizeMultiSlice( s1, [ 10, 10 ], false ); +var sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 4, 4 ]' + +s1 = new MultiSlice( null, S( -1, -8, -2 ) ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 11, 4 ]' + +s1 = new MultiSlice( S( null, null, 1 ), null ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 11, 12 ]' + +s1 = new MultiSlice( S( 5, 5, 1 ), null ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 0, 12 ]' + +s1 = new MultiSlice( S( 5, 5, 1 ), S( 3, 3, 1 ) ); +s2 = normalizeMultiSlice( s1, [ 10, 10 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 0, 0 ]' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/slice/base/shape/benchmark/benchmark.js b/lib/node_modules/@stdlib/slice/base/shape/benchmark/benchmark.js new file mode 100644 index 00000000000..fbc793ac0ff --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/benchmark/benchmark.js @@ -0,0 +1,254 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; +var S = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +var pkg = require( './../package.json' ).name; +var sliceShape = require( './../lib' ); + + +// VARIABLES // + +/* eslint-disable new-cap */ + +var SLICES = [ + S( null, null, null ), + S( 0, 10, 2 ), + S( null, 10, 2 ), + S( 0, null, 2 ), + S( 0, 10, null ), + S( -20, -5, -2 ), + S( 5, 20, 2 ), + S( null, null, -1 ), + S( 5, -20, -2 ), + S( 20, null, -1 ), + S( 0, -2, 2 ), + S( -5, null, 2 ) +]; + +/* eslint-enable new-cap */ + + +// MAIN // + +bench( pkg+':ndims=1', function benchmark( b ) { + var values; + var shape; + var out; + var i; + + shape = [ 10 ]; + + values = [ + normalizeMultiSlice( new MultiSlice( SLICES[ 0 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 1 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 2 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 3 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 4 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 5 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 6 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 7 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 8 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 9 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 10 ] ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 11 ] ), shape, false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sliceShape( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isNonNegativeIntegerArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=2', function benchmark( b ) { + var values; + var shape; + var out; + var s; + var i; + + shape = [ 10, 10 ]; + s = SLICES[ 5 ]; + + values = [ + normalizeMultiSlice( new MultiSlice( SLICES[ 0 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 1 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 2 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 3 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 4 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 5 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 6 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 7 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 8 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 9 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 10 ], s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 11 ], s ), shape, false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sliceShape( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isNonNegativeIntegerArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=3', function benchmark( b ) { + var values; + var shape; + var out; + var s; + var i; + + shape = [ 10, 10, 10 ]; + s = SLICES[ 5 ]; + + values = [ + normalizeMultiSlice( new MultiSlice( SLICES[ 0 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 1 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 2 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 3 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 4 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 5 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 6 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 7 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 8 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 9 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 10 ], s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 11 ], s, s ), shape, false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sliceShape( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isNonNegativeIntegerArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=4', function benchmark( b ) { + var values; + var shape; + var out; + var s; + var i; + + shape = [ 10, 10, 10, 10 ]; + s = SLICES[ 5 ]; + + values = [ + normalizeMultiSlice( new MultiSlice( SLICES[ 0 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 1 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 2 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 3 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 4 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 5 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 6 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 7 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 8 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 9 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 10 ], s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 11 ], s, s, s ), shape, false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sliceShape( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isNonNegativeIntegerArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=5', function benchmark( b ) { + var values; + var shape; + var out; + var s; + var i; + + shape = [ 10, 10, 10, 10, 10 ]; + s = SLICES[ 5 ]; + + values = [ + normalizeMultiSlice( new MultiSlice( SLICES[ 0 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 1 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 2 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 3 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 4 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 5 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 6 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 7 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 8 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 9 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 10 ], s, s, s, s ), shape, false ), + normalizeMultiSlice( new MultiSlice( SLICES[ 11 ], s, s, s, s ), shape, false ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sliceShape( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isNonNegativeIntegerArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/slice/base/shape/docs/repl.txt b/lib/node_modules/@stdlib/slice/base/shape/docs/repl.txt new file mode 100644 index 00000000000..177ececdd6e --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( slice ) + Returns the shape of a normalized multi-slice. + + Parameters + ---------- + slice: MultiSlice + Input normalized multi-slice object. + + Returns + ------- + sh: Array + Slice shape. + + Examples + -------- + > var s = new {{alias:@stdlib/slice/ctor}}( 1, 10, 1 ); + > var ms = new {{alias:@stdlib/slice/multi}}( s, s ); + > {{alias}}( ms ) + [ 9, 9 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/slice/base/shape/docs/types/index.d.ts b/lib/node_modules/@stdlib/slice/base/shape/docs/types/index.d.ts new file mode 100644 index 00000000000..a881d343a33 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/docs/types/index.d.ts @@ -0,0 +1,84 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { MultiSlice } from '@stdlib/types/slice'; + +/** +* Returns the shape of a normalized multi-slice. +* +* @param slice - input multi-slice +* @returns slice shape +* +* @example +* var Slice = require( `@stdlib/slice/ctor` ); +* var MultiSlice = require( `@stdlib/slice/multi` ); +* var normalizeMultiSlice = require( `@stdlib/slice/base/normalize-multi-slice` ); +* +* var s = new MultiSlice( new Slice( 2, null, 1 ), null, 10 ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5, 20 ], false ) ); +* // returns [ 8, 5, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 3, 12 ], false ) ); +* // returns [ 9, 3, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 10, 15 ], false ) ); +* // returns [ 3, 10, 1 ] +* +* @example +* var Slice = require( `@stdlib/slice/ctor` ); +* var MultiSlice = require( `@stdlib/slice/multi` ); +* var normalizeMultiSlice = require( `@stdlib/slice/base/normalize-multi-slice` ); +* +* var s = new MultiSlice( null, new Slice( -1, 3, -2 ) ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5 ], false ) ); +* // returns [ 10, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 10 ], false ) ); +* // returns [ 11, 3 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 15 ], false ) ); +* // returns [ 5, 6 ] +* +* @example +* var Slice = require( `@stdlib/slice/ctor` ); +* var MultiSlice = require( `@stdlib/slice/multi` ); +* var normalizeMultiSlice = require( `@stdlib/slice/base/normalize-multi-slice` ); +* +* var s = new MultiSlice( 1, new Slice( 0, 0, 1 ) ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5 ], false ) ); +* // returns [ 1, 0 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 10 ], false ) ); +* // returns [ 1, 0 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 15 ], false ) ); +* // returns [ 1, 0 ] +*/ +declare function sliceShape( slice: MultiSlice ): Array; + + +// EXPORTS // + +export = sliceShape; diff --git a/lib/node_modules/@stdlib/slice/base/shape/docs/types/test.ts b/lib/node_modules/@stdlib/slice/base/shape/docs/types/test.ts new file mode 100644 index 00000000000..00050023c13 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/docs/types/test.ts @@ -0,0 +1,49 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import MultiSlice = require( '@stdlib/slice/multi' ); +import sliceShape = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + sliceShape( new MultiSlice( null, null ) ); // $ExpectType number[] + sliceShape( new MultiSlice( null, null, null ) ); // $ExpectType number[] +} + +// The compiler throws an error if the function is provided a first argument which is not a multi-slice object... +{ + sliceShape( '1' ); // $ExpectError + sliceShape( 1 ); // $ExpectError + sliceShape( true ); // $ExpectError + sliceShape( false ); // $ExpectError + sliceShape( null ); // $ExpectError + sliceShape( undefined ); // $ExpectError + sliceShape( [] ); // $ExpectError + sliceShape( {} ); // $ExpectError + sliceShape( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + sliceShape(); // $ExpectError + sliceShape( new MultiSlice( null, null ), 10 ); // $ExpectError + sliceShape( new MultiSlice( null, null ), 10, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/slice/base/shape/examples/index.js b/lib/node_modules/@stdlib/slice/base/shape/examples/index.js new file mode 100644 index 00000000000..40c07a71160 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/examples/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable new-cap */ + +'use strict'; + +var S = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +var sliceShape = require( './../lib' ); + +var s1 = new MultiSlice( S( 3, null, -1 ), S( 3, 7, 1 ) ); +var s2 = normalizeMultiSlice( s1, [ 10, 10 ], false ); +var sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 4, 4 ]' + +s1 = new MultiSlice( null, S( -1, -8, -2 ) ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 11, 4 ]' + +s1 = new MultiSlice( S( null, null, 1 ), null ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 11, 12 ]' + +s1 = new MultiSlice( S( 5, 5, 1 ), null ); +s2 = normalizeMultiSlice( s1, [ 11, 12 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 0, 12 ]' + +s1 = new MultiSlice( S( 5, 5, 1 ), S( 3, 3, 1 ) ); +s2 = normalizeMultiSlice( s1, [ 10, 10 ], false ); +sh = sliceShape( s2 ); +console.log( '%s => %s', s1.toString(), s2.toString() ); +console.log( '[ %s ]', sh.join( ', ' ) ); +// => '[ 0, 0 ]' diff --git a/lib/node_modules/@stdlib/slice/base/shape/lib/index.js b/lib/node_modules/@stdlib/slice/base/shape/lib/index.js new file mode 100644 index 00000000000..f226e3cf7a6 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/lib/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the shape of a normalized multi-slice. +* +* @module @stdlib/slice/base/shape +* +* @example +* var Slice = require( '@stdlib/slice/ctor' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +* var sliceShape = require( '@stdlib/slice/base/shape' ); +* +* var s = new MultiSlice( new Slice( 2, null, 1 ), null, 10 ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5, 20 ], false ) ); +* // returns [ 8, 5, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 3, 12 ], false ) ); +* // returns [ 9, 3, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 10, 15 ], false ) ); +* // returns [ 3, 10, 1 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/slice/base/shape/lib/main.js b/lib/node_modules/@stdlib/slice/base/shape/lib/main.js new file mode 100644 index 00000000000..00158216be5 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/lib/main.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var sliceLength = require( '@stdlib/slice/base/length' ); + + +// MAIN // + +/** +* Returns the shape of a normalized multi-slice. +* +* @param {MultiSlice} slice - normalized MultiSlice object +* @returns {NonNegativeIntegerArray} slice shape +* +* @example +* var Slice = require( '@stdlib/slice/ctor' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +* +* var s = new MultiSlice( new Slice( 2, null, 1 ), null, 10 ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5, 20 ], false ) ); +* // returns [ 8, 5, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 3, 12 ], false ) ); +* // returns [ 9, 3, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 10, 15 ], false ) ); +* // returns [ 3, 10, 1 ] +* +* @example +* var Slice = require( '@stdlib/slice/ctor' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +* +* var s = new MultiSlice( null, new Slice( -1, 3, -2 ) ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5 ], false ) ); +* // returns [ 10, 1 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 10 ], false ) ); +* // returns [ 11, 3 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 15 ], false ) ); +* // returns [ 5, 6 ] +* +* @example +* var Slice = require( '@stdlib/slice/ctor' ); +* var MultiSlice = require( '@stdlib/slice/multi' ); +* var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +* +* var s = new MultiSlice( 1, new Slice( 0, 0, 1 ) ); +* +* var v = sliceShape( normalizeMultiSlice( s, [ 10, 5 ], false ) ); +* // returns [ 1, 0 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 11, 10 ], false ) ); +* // returns [ 1, 0 ] +* +* v = sliceShape( normalizeMultiSlice( s, [ 5, 15 ], false ) ); +* // returns [ 1, 0 ] +*/ +function sliceShape( slice ) { + var data; + var out; + var i; + + data = slice.data; + out = []; + for ( i = 0; i < data.length; i++ ) { + out.push( sliceLength( data[ i ] ) ); + } + return out; +} + + +// EXPORTS // + +module.exports = sliceShape; diff --git a/lib/node_modules/@stdlib/slice/base/shape/package.json b/lib/node_modules/@stdlib/slice/base/shape/package.json new file mode 100644 index 00000000000..a49f70297b2 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/slice/base/shape", + "version": "0.0.0", + "description": "Compute the shape of a normalized multi-slice.", + "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", + "base", + "slice", + "range", + "subsequence", + "subseq", + "sequence", + "ndarray", + "normalized", + "canonical", + "reduced", + "shape", + "numel", + "dims", + "dimensions" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/slice/base/shape/test/test.js b/lib/node_modules/@stdlib/slice/base/shape/test/test.js new file mode 100644 index 00000000000..8399ddc4411 --- /dev/null +++ b/lib/node_modules/@stdlib/slice/base/shape/test/test.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var S = require( '@stdlib/slice/ctor' ); +var MultiSlice = require( '@stdlib/slice/multi' ); +var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' ); +var sliceShape = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sliceShape, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the shape of a normalized multi-slice', function test( t ) { + var expected; + var actual; + var values; + var shape; + var i; + + shape = [ 10, 5 ]; + + /* eslint-disable new-cap */ + + values = [ + normalizeMultiSlice( new MultiSlice( S(), null ), shape, false ), + normalizeMultiSlice( new MultiSlice( 2, S( 10 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( 2, 10 ), S() ), shape, false ), + normalizeMultiSlice( new MultiSlice( null, S( 2, null ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( null, 10 ), S( null, 10 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( -2 ), -2 ), shape, false ), + normalizeMultiSlice( new MultiSlice( -2, S( -5, -2 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( null, 10, 2 ), S( -5, null ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( null, S( 3, 3, 1 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( 5, 3, 1 ), null ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( 3, 5, -1 ), 2 ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( -5, -5, 1 ), S() ), shape, false ), + normalizeMultiSlice( new MultiSlice( null, S( 0, 0, 1 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( 10, 10, 1 ), S( 1, 1, 1 ) ), shape, false ), + normalizeMultiSlice( new MultiSlice( S( null, 10, 3 ), S( -5, null, 2 ) ), shape, false ) + ]; + + /* eslint-enable new-cap */ + + expected = [ + // Slice( 0, 10, 1 ), Slice( 0, 5, 1 ) + [ 10, 5 ], + + // Slice( 2, 3, 1 ), Slice( 0, 5, 1 ) + [ 1, 5 ], + + // Slice( 2, 10, 1 ), S( 0, 5, 1 ) + [ 8, 5 ], + + // Slice( 0, 10, 1 ), Slice( 2, 5, 1 ) + [ 10, 3 ], + + // Slice( 0, 10, 1 ), Slice( 0, 5, 1 ) + [ 10, 5 ], + + // Slice( 0, 8, 1 ), Slice( 3, 4, 1 ) + [ 8, 1 ], + + // Slice( 8, 9, 1 ), Slice( 0, 3, 1 ) + [ 1, 3 ], + + // Slice( 0, 10, 2 ), Slice( 0, 5, 1 ) + [ 5, 5 ], + + // Slice( 0, 10, 1 ), Slice( 3, 3, 1 ) + [ 10, 0 ], + + // Slice( 5, 3, 1 ), Slice( 0, 5, 1 ) + [ 0, 5 ], + + // Slice( 3, 5, -1 ), Slice( 2, 3, 1 ) + [ 0, 1 ], + + // Slice( 5, 5, 1 ), Slice( 0, 5, 1 ) + [ 0, 5 ], + + // Slice( 0, 10, 1 ), Slice( 0, 0, 1 ) + [ 10, 0 ], + + // Slice( 10, 10, 1 ), Slice( 1, 1, 1 ) + [ 0, 0 ], + + // Slice( 0, 10, 3 ), Slice( 0, 5, 2 ) + [ 4, 3 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + actual = sliceShape( values[ i ] ); + t.deepEqual( actual, expected[ i ], 'returns expected value. slice: ' + values[ i ].toString() ); + } + t.end(); +});