Skip to content

Commit c08c9b7

Browse files
committed
Auto-generated commit
1 parent 6cda9f8 commit c08c9b7

15 files changed

Lines changed: 205 additions & 273 deletions

File tree

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,64 @@
22

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2026-02-28)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`e947540`](https://github.com/stdlib-js/stdlib/commit/e947540a4e87841d7bf140094e20b2768250de11) - add writable parameter to `ndarray/base/remove-singleton-dimensions` [(#9667)](https://github.com/stdlib-js/stdlib/pull/9667)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
19+
<section class="breaking-changes">
20+
21+
### BREAKING CHANGES
22+
23+
- [`e947540`](https://github.com/stdlib-js/stdlib/commit/e947540a4e87841d7bf140094e20b2768250de11): add writable parameter and always return a new view
24+
25+
- To migrate, in order to preserve prior writable behavior, users should set the final parameter equal to a boolean indicating whether the input ndarray is writable. If not, pass `false`; if yes, pass `true`.
26+
To preserve prior behavior in which the input ndarray is returned if it does not have singleton dimensions, use `ndarray/base/maybe-remove-singleton-dimensions`.
27+
28+
</section>
29+
30+
<!-- /.breaking-changes -->
31+
32+
<section class="commits">
33+
34+
### Commits
35+
36+
<details>
37+
38+
- [`e947540`](https://github.com/stdlib-js/stdlib/commit/e947540a4e87841d7bf140094e20b2768250de11) - **feat:** add writable parameter to `ndarray/base/remove-singleton-dimensions` [(#9667)](https://github.com/stdlib-js/stdlib/pull/9667) _(by Muhammad Haris, Athan Reines)_
39+
40+
</details>
41+
42+
</section>
43+
44+
<!-- /.commits -->
45+
46+
<section class="contributors">
47+
48+
### Contributors
49+
50+
A total of 2 people contributed to this release. Thank you to the following contributors:
51+
52+
- Athan Reines
53+
- Muhammad Haris
54+
55+
</section>
56+
57+
<!-- /.contributors -->
58+
59+
</section>
60+
61+
<!-- /.release -->
62+
563
<section class="release" id="v0.2.3">
664

765
## 0.2.3 (2026-02-08)

README.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ To view installation and usage instructions specific to each branch build, be su
7373
var removeSingletonDimensions = require( '@stdlib/ndarray-base-remove-singleton-dimensions' );
7474
```
7575

76-
#### removeSingletonDimensions( x )
76+
#### removeSingletonDimensions( x, writable )
7777

7878
Returns an ndarray without singleton dimensions (i.e., dimensions whose size is equal to `1`).
7979

@@ -82,16 +82,18 @@ var array = require( '@stdlib/ndarray-array' );
8282

8383
// Create a 1x2x2 ndarray:
8484
var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] );
85-
// returns <ndarray>
85+
// returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ] ]
8686

8787
// Remove singleton dimensions:
88-
var y = removeSingletonDimensions( x );
89-
// returns <ndarray>
90-
91-
var sh = y.shape;
92-
// returns [ 2, 2 ]
88+
var y = removeSingletonDimensions( x, false );
89+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
9390
```
9491

92+
The function accepts the following arguments:
93+
94+
- **x**: input ndarray.
95+
- **writable**: boolean indicating whether a returned ndarray should be writable.
96+
9597
</section>
9698

9799
<!-- /.usage -->
@@ -102,8 +104,8 @@ var sh = y.shape;
102104

103105
## Notes
104106

105-
- If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged.
106-
- If a provided ndarray does have singleton dimensions, the function returns a new ndarray view.
107+
- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.
108+
- The function **always** returns a new ndarray instance even if the input ndarray does not contain any singleton dimensions.
107109

108110
</section>
109111

@@ -118,33 +120,15 @@ var sh = y.shape;
118120
<!-- eslint no-undef: "error" -->
119121

120122
```javascript
121-
var array = require( '@stdlib/ndarray-array' );
122-
var numel = require( '@stdlib/ndarray-base-numel' );
123-
var ind2sub = require( '@stdlib/ndarray-ind2sub' );
123+
var uniform = require( '@stdlib/random-uniform' );
124+
var ndarray2array = require( '@stdlib/ndarray-to-array' );
124125
var removeSingletonDimensions = require( '@stdlib/ndarray-base-remove-singleton-dimensions' );
125126

126-
// Create a 5-dimensional array:
127-
var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {
128-
'ndmin': 5
129-
});
130-
// returns <ndarray>
131-
132-
// Remove singleton dimensions:
133-
var y = removeSingletonDimensions( x );
134-
// returns <ndarray>
135-
136-
// Retrieve the shape:
137-
var sh = y.shape;
138-
// returns [ 2, 2 ]
139-
140-
// Retrieve the number of elements:
141-
var N = numel( sh );
127+
var x = uniform( [ 1, 1, 3, 3, 3 ], -10.0, 10.0 );
128+
console.log( ndarray2array( x ) );
142129

143-
// Loop through the array elements...
144-
var i;
145-
for ( i = 0; i < N; i++ ) {
146-
console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) );
147-
}
130+
var y = removeSingletonDimensions( x, false );
131+
console.log( ndarray2array( y ) );
148132
```
149133

150134
</section>

benchmark/benchmark.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ var Float64Array = require( '@stdlib/array-float64' );
2525
var ndarrayBase = require( '@stdlib/ndarray-base-ctor' );
2626
var ndarray = require( '@stdlib/ndarray-ctor' );
2727
var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
28+
var format = require( '@stdlib/string-format' );
2829
var pkg = require( './../package.json' ).name;
2930
var removeSingletonDimensions = require( './../lib' );
3031

3132

3233
// MAIN //
3334

34-
bench( pkg+'::base_ndarray,2d', function benchmark( b ) {
35+
bench( format( '%s::base_ndarray,2d', pkg ), function benchmark( b ) {
3536
var strides;
3637
var values;
3738
var buffer;
@@ -59,7 +60,7 @@ bench( pkg+'::base_ndarray,2d', function benchmark( b ) {
5960

6061
b.tic();
6162
for ( i = 0; i < b.iterations; i++ ) {
62-
out = removeSingletonDimensions( values[ i%values.length ] );
63+
out = removeSingletonDimensions( values[ i%values.length ], false );
6364
if ( typeof out !== 'object' ) {
6465
b.fail( 'should return an object' );
6566
}
@@ -72,7 +73,7 @@ bench( pkg+'::base_ndarray,2d', function benchmark( b ) {
7273
b.end();
7374
});
7475

75-
bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b ) {
76+
bench( format( '%s::base_ndarray,2d,no_singleton_dimensions', pkg ), function benchmark( b ) {
7677
var strides;
7778
var values;
7879
var buffer;
@@ -100,7 +101,7 @@ bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b )
100101

101102
b.tic();
102103
for ( i = 0; i < b.iterations; i++ ) {
103-
out = removeSingletonDimensions( values[ i%values.length ] );
104+
out = removeSingletonDimensions( values[ i%values.length ], false );
104105
if ( typeof out !== 'object' ) {
105106
b.fail( 'should return an object' );
106107
}
@@ -113,7 +114,7 @@ bench( pkg+'::base_ndarray,2d,no_singleton_dimensions', function benchmark( b )
113114
b.end();
114115
});
115116

116-
bench( pkg+'::ndarray,2d', function benchmark( b ) {
117+
bench( format( '%s::ndarray,2d', pkg ), function benchmark( b ) {
117118
var strides;
118119
var values;
119120
var buffer;
@@ -141,7 +142,7 @@ bench( pkg+'::ndarray,2d', function benchmark( b ) {
141142

142143
b.tic();
143144
for ( i = 0; i < b.iterations; i++ ) {
144-
out = removeSingletonDimensions( values[ i%values.length ] );
145+
out = removeSingletonDimensions( values[ i%values.length ], false );
145146
if ( typeof out !== 'object' ) {
146147
b.fail( 'should return an object' );
147148
}
@@ -154,7 +155,7 @@ bench( pkg+'::ndarray,2d', function benchmark( b ) {
154155
b.end();
155156
});
156157

157-
bench( pkg+'::ndarray,2d,no_singleton_dimensions', function benchmark( b ) {
158+
bench( format( '%s::ndarray,2d,no_singleton_dimensions', pkg ), function benchmark( b ) {
158159
var strides;
159160
var values;
160161
var buffer;
@@ -182,7 +183,7 @@ bench( pkg+'::ndarray,2d,no_singleton_dimensions', function benchmark( b ) {
182183

183184
b.tic();
184185
for ( i = 0; i < b.iterations; i++ ) {
185-
out = removeSingletonDimensions( values[ i%values.length ] );
186+
out = removeSingletonDimensions( values[ i%values.length ], false );
186187
if ( typeof out !== 'object' ) {
187188
b.fail( 'should return an object' );
188189
}

benchmark/benchmark.ndims.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var bench = require( '@stdlib/bench-harness' );
2424
var array = require( '@stdlib/ndarray-array' );
2525
var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
26+
var format = require( '@stdlib/string-format' );
2627
var pkg = require( './../package.json' ).name;
2728
var removeSingletonDimensions = require( './../lib' );
2829

@@ -54,7 +55,7 @@ function createBenchmark( ndims ) {
5455

5556
b.tic();
5657
for ( i = 0; i < b.iterations; i++ ) {
57-
out = removeSingletonDimensions( x );
58+
out = removeSingletonDimensions( x, false );
5859
if ( typeof out !== 'object' ) {
5960
b.fail( 'should return an object' );
6061
}
@@ -87,7 +88,7 @@ function main() {
8788

8889
for ( i = min; i <= max; i++ ) {
8990
f = createBenchmark( i );
90-
bench( pkg+'::ndarray,2d:singleton_dimensions='+i, f );
91+
bench( format( '%s::ndarray,2d:singleton_dimensions=%d', pkg, i ), f );
9192
}
9293
}
9394

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)