Skip to content

Commit e17e199

Browse files
committed
fix: address dimension reduction bug
1 parent cadd340 commit e17e199

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/node_modules/@stdlib/ndarray/fancy/examples/3d.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ var s = E( 1, S(0,_,2), _ );
7272
// Use the slice to create a view on the original ndarray:
7373
var y1 = x[ s ];
7474
console.log( toArray( y1 ) );
75-
// => [ [ [ 9, 10 ], [ 13, 100 ] ] ]
75+
// => [ [ 9, 10 ], [ 13, 100 ] ]
7676

7777
// Use alternative syntax:
7878
var y2 = x[ [ 1, S(0,_,2), _ ] ];
7979
console.log( toArray( y2 ) );
80-
// => [ [ [ 9, 10 ], [ 13, 100 ] ] ]
80+
// => [ [ 9, 10 ], [ 13, 100 ] ]
8181

8282
// Use alternative syntax:
8383
var y3 = x[ '1,0::2,:' ];
8484
console.log( toArray( y3 ) );
85-
// => [ [ [ 9, 10 ], [ 13, 100 ] ] ]
85+
// => [ [ 9, 10 ], [ 13, 100 ] ]
8686

8787
// Flip dimensions:
8888
var y4 = x[ [ 1, S(_,_,-2), S(_,_,-1) ] ];
8989
console.log( toArray( y4 ) );
90-
// => [ [ [ 100, 13 ], [ 10, 9 ] ] ]
90+
// => [ [ 100, 13 ], [ 10, 9 ] ]
9191

9292
// Only the second rows:
9393
var y5 = x[ [ _, 1, _ ] ];
9494
console.log( toArray( y5 ) );
95-
// => [ [ [ 5, 6 ] ], [ [ 11, 12 ] ] ]
95+
// throws [ [ 5, 6 ], [ 11, 12 ] ]

lib/node_modules/@stdlib/ndarray/fancy/lib/view.nd.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
// MODULES //
2222

2323
var normalizeMultiSlice = require( '@stdlib/slice/base/normalize-multi-slice' );
24+
var nonreducedDimensions = require( '@stdlib/slice/base/nonreduced-dimensions' );
2425
var sliceShape = require( '@stdlib/slice/base/shape' );
2526
var take = require( '@stdlib/array/base/take' );
2627
var vind2bind = require( '@stdlib/ndarray/base/vind2bind' );
2728
var numel = require( '@stdlib/ndarray/base/numel' );
2829
var format = require( '@stdlib/string/format' );
29-
var nonreducedDimensions = require( '@stdlib/slice/base/nonreduced-dimensions' );
3030
var sliceStart = require( './slice_start.js' );
3131
var sliceStrides = require( './slice_strides.js' );
3232
var options = require( './array_options.js' );
@@ -58,6 +58,7 @@ function sliceView( target, property, receiver, slice ) {
5858
var sdims;
5959
var ctor;
6060
var sh;
61+
var ns;
6162

6263
// Verify that we were successfully able to create a multi-slice:
6364
if ( slice === null ) {
@@ -76,17 +77,17 @@ function sliceView( target, property, receiver, slice ) {
7677
throw new RangeError( format( 'invalid operation. Number of array dimensions does not match the number of slice dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), slice.ndims ) );
7778
}
7879
// Normalize the slice object based on the array shape:
79-
slice = normalizeMultiSlice( slice, shape, true );
80+
ns = normalizeMultiSlice( slice, shape, true );
8081

8182
// In strict mode, if the slice exceeds array bounds, raise an exception...
82-
if ( slice.code && strict ) {
83+
if ( ns.code && strict ) {
8384
throw new RangeError( format( 'invalid operation. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );
8485
}
8586
// Resolve the output array constructor:
8687
ctor = receiver.constructor;
8788

8889
// Compute the slice shape:
89-
sh = sliceShape( slice );
90+
sh = sliceShape( ns );
9091

9192
// Resolve the indices of the non-reduced dimensions:
9293
sdims = nonreducedDimensions( slice );
@@ -96,7 +97,7 @@ function sliceView( target, property, receiver, slice ) {
9697
return empty( ctor, dtype, take( sh, sdims ), order );
9798
}
9899
// Resolve the index offset of the first element:
99-
offset = vind2bind( shape, strides, offset, order, sliceStart( slice, shape, strides, 0 ), 'throw' );
100+
offset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' );
100101

101102
// Remove reduced dimensions from the slice shape:
102103
sh = take( sh, sdims );
@@ -106,7 +107,7 @@ function sliceView( target, property, receiver, slice ) {
106107
return new ctor( dtype, target.data, [], [ 0 ], offset, order, options() ); // eslint-disable-line max-len
107108
}
108109
// Update strides according to slice steps:
109-
strides = sliceStrides( slice, strides, sdims );
110+
strides = sliceStrides( ns, strides, sdims );
110111

111112
// Return a slice view:
112113
return new ctor( dtype, target.data, sh, strides, offset, order, options() ); // eslint-disable-line max-len

0 commit comments

Comments
 (0)