Skip to content

Commit 1cb0826

Browse files
Merge branch 'stdlib-js:develop' into develop
2 parents 38fa07e + 0562a32 commit 1cb0826

File tree

18 files changed

+5307
-6
lines changed

18 files changed

+5307
-6
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Yaswanth Kosuru <[email protected]>
223223
Yernar Yergaziyev <[email protected]>
224224
Yugal Kaushik <[email protected]>
225225
Yuvi Mittal <[email protected]>
226+
Zuhair Ahmad <[email protected]>
226227
deepak427 <[email protected]>
227228
devshree-bhati <[email protected]>
228229

lib/node_modules/@stdlib/ndarray/base/pop/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Returns an array containing a truncated view of an input ndarray and a view of t
4646

4747
```javascript
4848
var ndarray = require( '@stdlib/ndarray/ctor' );
49+
var getShape = require( '@stdlib/ndarray/shape' );
4950
var ndarray2array = require( '@stdlib/ndarray/to-array' );
5051

5152
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
@@ -56,7 +57,7 @@ var offset = 0;
5657
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
5758
// returns <ndarray>
5859

59-
var sh = x.shape;
60+
var sh = getShape( x );
6061
// returns [ 3, 2 ]
6162

6263
var arr = ndarray2array( x );

lib/node_modules/@stdlib/ndarray/base/pop/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ function pop( x, dim, writable ) {
8989
s[ dim ] = sh[ dim ] - 1;
9090

9191
// Create a truncated view:
92-
v0 = sliceTo( x, s, true, writable );
92+
v0 = sliceTo( x, s, false, writable );
9393

9494
// Create a view of the last element(s):
95-
v1 = sliceFrom( x, s, true, writable );
95+
v1 = sliceFrom( x, s, false, writable );
9696

9797
return [ v0, v1 ];
9898
}

lib/node_modules/@stdlib/ndarray/base/pop/test/test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,70 @@ tape( 'the function returns an array containing ndarrays (ndims=3, writable)', f
356356

357357
t.end();
358358
});
359+
360+
tape( 'the function returns empty views if provided an empty array (ndims=2)', function test( t ) {
361+
var actual;
362+
var buf;
363+
var ord;
364+
var sh;
365+
var st;
366+
var o;
367+
var x;
368+
369+
buf = zeroTo( 8, 'float64' );
370+
st = [ 4, 1 ];
371+
o = 0;
372+
ord = 'row-major';
373+
374+
sh = [ 2, 0 ];
375+
x = new ndarray( 'float64', buf, sh, st, o, ord );
376+
377+
actual = pop( x, 0, false );
378+
379+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
380+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
381+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
382+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
383+
t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' );
384+
t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' );
385+
t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' );
386+
t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' );
387+
388+
actual = pop( x, 1, false );
389+
390+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
391+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
392+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
393+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
394+
t.deepEqual( getShape( actual[0] ), [ 2, 0 ], 'returns expected value' );
395+
t.deepEqual( getShape( actual[1] ), [ 2, 0 ], 'returns expected value' );
396+
t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' );
397+
t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' );
398+
399+
sh = [ 0, 4 ];
400+
x = new ndarray( 'float64', buf, sh, st, o, ord );
401+
402+
actual = pop( x, 0, false );
403+
404+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
405+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
406+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
407+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
408+
t.deepEqual( getShape( actual[0] ), [ 0, 4 ], 'returns expected value' );
409+
t.deepEqual( getShape( actual[1] ), [ 0, 4 ], 'returns expected value' );
410+
t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' );
411+
t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' );
412+
413+
actual = pop( x, 1, false );
414+
415+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
416+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
417+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
418+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
419+
t.deepEqual( getShape( actual[0] ), [ 0, 3 ], 'returns expected value' );
420+
t.deepEqual( getShape( actual[1] ), [ 0, 1 ], 'returns expected value' );
421+
t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' );
422+
t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' );
423+
424+
t.end();
425+
});
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# shift
22+
23+
> Return an array containing a truncated view of an input ndarray and a view of the first element(s) along a specified dimension.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var shift = require( '@stdlib/ndarray/base/shift' );
41+
```
42+
43+
#### shift( x, dim, writable )
44+
45+
Returns an array containing a truncated view of an input ndarray and a view of the first element(s) along a specified dimension.
46+
47+
```javascript
48+
var ndarray = require( '@stdlib/ndarray/ctor' );
49+
var getShape = require( '@stdlib/ndarray/shape' );
50+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
51+
52+
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
53+
var shape = [ 3, 2 ];
54+
var strides = [ 2, 1 ];
55+
var offset = 0;
56+
57+
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
58+
// returns <ndarray>
59+
60+
var sh = getShape( x );
61+
// returns [ 3, 2 ]
62+
63+
var arr = ndarray2array( x );
64+
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
65+
66+
var y = shift( x, 0, false );
67+
// returns [ <ndarray>, <ndarray> ]
68+
69+
arr = ndarray2array( y[ 0 ] );
70+
// returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
71+
72+
arr = ndarray2array( y[ 1 ] );
73+
// returns [ [ 1.0, 2.0 ] ]
74+
```
75+
76+
The function accepts the following arguments:
77+
78+
- **x**: input ndarray.
79+
- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`.
80+
- **writable**: boolean indicating whether a returned ndarray should be writable.
81+
82+
</section>
83+
84+
<!-- /.usage -->
85+
86+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
87+
88+
<section class="notes">
89+
90+
## Notes
91+
92+
- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.
93+
94+
</section>
95+
96+
<!-- /.notes -->
97+
98+
<!-- Package usage examples. -->
99+
100+
<section class="examples">
101+
102+
## Examples
103+
104+
<!-- eslint no-undef: "error" -->
105+
106+
```javascript
107+
var array = require( '@stdlib/ndarray/array' );
108+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
109+
var zeroTo = require( '@stdlib/array/base/zero-to' );
110+
var shift = require( '@stdlib/ndarray/base/shift' );
111+
112+
// Create a linear ndarray buffer:
113+
var buf = zeroTo( 27 );
114+
115+
// Create an ndarray which is a stack of three 3x3 matrices:
116+
var x = array( buf, {
117+
'shape': [ 3, 3, 3 ]
118+
});
119+
120+
// Remove the first row from each matrix:
121+
var y = shift( x, 1, false );
122+
// returns [ <ndarray>, <ndarray> ]
123+
124+
console.log( ndarray2array( y[ 0 ] ) );
125+
console.log( ndarray2array( y[ 1 ] ) );
126+
```
127+
128+
</section>
129+
130+
<!-- /.examples -->
131+
132+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
133+
134+
<section class="references">
135+
136+
</section>
137+
138+
<!-- /.references -->
139+
140+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
141+
142+
<section class="related">
143+
144+
</section>
145+
146+
<!-- /.related -->
147+
148+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
149+
150+
<section class="links">
151+
152+
</section>
153+
154+
<!-- /.links -->

0 commit comments

Comments
 (0)