@@ -23,16 +23,16 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
2323 < div class ='clearfix '>
2424
2525 < div class ='fl pad1y space-right2 '>
26- < span class ="strong "> 100 % </ span >
26+ < span class ="strong "> 96.11 % </ span >
2727 < span class ="quiet "> Statements</ span >
28- < span class ='fraction '> 92/92 </ span >
28+ < span class ='fraction '> 99/103 </ span >
2929 </ div >
3030
3131
3232 < div class ='fl pad1y space-right2 '>
33- < span class ="strong "> 100 % </ span >
33+ < span class ="strong "> 50 % </ span >
3434 < span class ="quiet "> Branches</ span >
35- < span class ='fraction '> 3/3 </ span >
35+ < span class ='fraction '> 2/4 </ span >
3636 </ div >
3737
3838
@@ -44,9 +44,9 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
4444
4545
4646 < div class ='fl pad1y space-right2 '>
47- < span class ="strong "> 100 % </ span >
47+ < span class ="strong "> 96.11 % </ span >
4848 < span class ="quiet "> Lines</ span >
49- < span class ='fraction '> 92/92 </ span >
49+ < span class ='fraction '> 99/103 </ span >
5050 </ div >
5151
5252
@@ -155,7 +155,19 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
155155< a name ='L90 '> </ a > < a href ='#L90 '> 90</ a >
156156< a name ='L91 '> </ a > < a href ='#L91 '> 91</ a >
157157< a name ='L92 '> </ a > < a href ='#L92 '> 92</ a >
158- < a name ='L93 '> </ a > < a href ='#L93 '> 93</ a > </ td > < td class ="line-coverage quiet "> < span class ="cline-any cline-yes "> 1x</ span >
158+ < a name ='L93 '> </ a > < a href ='#L93 '> 93</ a >
159+ < a name ='L94 '> </ a > < a href ='#L94 '> 94</ a >
160+ < a name ='L95 '> </ a > < a href ='#L95 '> 95</ a >
161+ < a name ='L96 '> </ a > < a href ='#L96 '> 96</ a >
162+ < a name ='L97 '> </ a > < a href ='#L97 '> 97</ a >
163+ < a name ='L98 '> </ a > < a href ='#L98 '> 98</ a >
164+ < a name ='L99 '> </ a > < a href ='#L99 '> 99</ a >
165+ < a name ='L100 '> </ a > < a href ='#L100 '> 100</ a >
166+ < a name ='L101 '> </ a > < a href ='#L101 '> 101</ a >
167+ < a name ='L102 '> </ a > < a href ='#L102 '> 102</ a >
168+ < a name ='L103 '> </ a > < a href ='#L103 '> 103</ a >
169+ < a name ='L104 '> </ a > < a href ='#L104 '> 104</ a > </ td > < td class ="line-coverage quiet "> < span class ="cline-any cline-yes "> 1x</ span >
170+ < span class ="cline-any cline-yes "> 1x</ span >
159171< span class ="cline-any cline-yes "> 1x</ span >
160172< span class ="cline-any cline-yes "> 1x</ span >
161173< span class ="cline-any cline-yes "> 1x</ span >
@@ -219,6 +231,10 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
219231< span class ="cline-any cline-yes "> 1x</ span >
220232< span class ="cline-any cline-yes "> 1x</ span >
221233< span class ="cline-any cline-yes "> 1x</ span >
234+ < span class ="cline-any cline-yes "> 1x</ span >
235+ < span class ="cline-any cline-yes "> 6x</ span >
236+ < span class ="cline-any cline-yes "> 6x</ span >
237+ < span class ="cline-any cline-yes "> 6x</ span >
222238< span class ="cline-any cline-yes "> 6x</ span >
223239< span class ="cline-any cline-yes "> 6x</ span >
224240< span class ="cline-any cline-yes "> 6x</ span >
@@ -229,13 +245,19 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
229245< span class ="cline-any cline-yes "> 6x</ span >
230246< span class ="cline-any cline-yes "> 6x</ span >
231247< span class ="cline-any cline-yes "> 6x</ span >
248+ < span class ="cline-any cline-no "> </ span >
249+ < span class ="cline-any cline-no "> </ span >
250+ < span class ="cline-any cline-yes "> 6x</ span >
251+ < span class ="cline-any cline-yes "> 6x</ span >
252+ < span class ="cline-any cline-yes "> 6x</ span >
253+ < span class ="cline-any cline-no "> </ span >
254+ < span class ="cline-any cline-no "> </ span >
255+ < span class ="cline-any cline-yes "> 6x</ span >
232256< span class ="cline-any cline-yes "> 6x</ span >
233257< span class ="cline-any cline-yes "> 6x</ span >
234258< span class ="cline-any cline-yes "> 6x</ span >
235259< span class ="cline-any cline-yes "> 6x</ span >
236260< span class ="cline-any cline-yes "> 6x</ span >
237- < span class ="cline-any cline-yes "> 12x</ span >
238- < span class ="cline-any cline-yes "> 12x</ span >
239261< span class ="cline-any cline-yes "> 6x</ span >
240262< span class ="cline-any cline-yes "> 6x</ span >
241263< span class ="cline-any cline-yes "> 6x</ span >
@@ -269,23 +291,25 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
269291
270292// MODULES //
271293
272- var ndims = require( '@stdlib/ndarray/base/ndims' );
273294var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' );
274295var getShape = require( '@stdlib/ndarray/base/shape' );
275296var sliceFrom = require( '@stdlib/ndarray/base/slice-from' );
276297var sliceTo = require( '@stdlib/ndarray/base/slice-to' );
298+ var nulls = require( '@stdlib/array/base/nulls' );
299+ var format = require( '@stdlib/string/format' );
277300
278301
279302// MAIN //
280303
281304/**
282- * Returns an array containing a truncated view of an input ndarray and a complementary view of the first element(s) along a specified dimension.
305+ * Returns an array containing a truncated view of an input ndarray and a view of the first element(s) along a specified dimension.
283306*
284307* @param {ndarray} x - input array
285308* @param {integer} dim - dimension along which to perform the operation
286- * @param {boolean} strict - boolean indicating whether to enforce strict bounds checking
287309* @param {boolean} writable - boolean indicating whether returned arrays should be writable
288- * @returns {Array} a list of ndarrays
310+ * @throws {TypeError} first argument must be an ndarray having one or more dimensions
311+ * @throws {RangeError} dimension index exceeds the number of dimensions
312+ * @returns {Array<ndarray>} a list of ndarrays
289313*
290314* @example
291315* var ndarray = require( '@stdlib/ndarray/ctor' );
@@ -302,36 +326,45 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
302326* var arr = ndarray2array( x );
303327* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
304328*
305- * var y = shift( x, 0, false, false );
329+ * var y = shift( x, 0, false );
306330* // returns [ <ndarray>, <ndarray> ]
307331*
308332* arr = ndarray2array( y[ 0 ] );
309- * // returns [ [ 3, 4 ], [ 5, 6 ] ]
333+ * // returns [ [ 3.0 , 4.0 ], [ 5.0 , 6.0 ] ]
310334*
311335* arr = ndarray2array( y[ 1 ] );
312- * // returns [ [ 1, 2 ] ]
336+ * // returns [ [ 1.0 , 2.0 ] ]
313337*/
314- function shift( x, dim, strict, writable ) {
338+ function shift( x, dim, writable ) {
315339 var v0;
316340 var v1;
317341 var sh;
318342 var N;
319343 var s;
320- var i;
321344
322345 // Retrieve array meta data:
323346 sh = getShape( x );
324- N = ndims( x ) ;
347+ N = sh.length ;
325348
326- // Resolve view slice:
327- s = [];
328- for ( i = 0; i < N; i++ ) {
329- s[ i ] = null;
330- }
331- dim = normalizeIndex( dim, N -1 );
349+ // Check whether we were provided a zero-dimensional array...
350+ if ( N === 0 ) < span class ="branch-0 cbranch-no " title ="branch not covered " > {</ span >
351+ < span class ="cstat-no " title ="statement not covered " > throw new TypeError( format( 'invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.', N ) );</ span >
352+ < span class ="cstat-no " title ="statement not covered " > }</ span >
353+ // Normalize the dimension index:
354+ dim = normalizeIndex( dim, N-1 );
355+ if ( dim === -1 ) < span class ="branch-0 cbranch-no " title ="branch not covered " > {</ span >
356+ < span class ="cstat-no " title ="statement not covered " > throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, dim ) );</ span >
357+ < span class ="cstat-no " title ="statement not covered " > }</ span >
358+ // Define a list of slice arguments:
359+ s = nulls( N );
332360 s[ dim ] = sh[ dim ] - ( sh[ dim ] - 1 );
333- v0 = sliceFrom( x, s, strict, writable );
334- v1 = sliceTo( x, s, strict, writable );
361+
362+ // Create a truncated view:
363+ v0 = sliceFrom( x, s, true, writable );
364+
365+ // Create a view of the first element(s):
366+ v1 = sliceTo( x, s, true, writable );
367+
335368 return [ v0, v1 ];
336369}
337370
@@ -346,7 +379,7 @@ <h1><a href="../../../../index.html">All files</a> / <a href="index.html">ndarra
346379 < div class ='footer quiet pad2 space-top1 center small '>
347380 Code coverage generated by
348381 < a href ="https://istanbul.js.org/ " target ="_blank " rel ="noopener noreferrer "> istanbul</ a >
349- at 2025-09-24T15:22:00.775Z
382+ at 2025-09-24T17:07:07.454Z
350383 </ div >
351384 < script src ="../../../../prettify.js "> </ script >
352385 < script >
0 commit comments