Skip to content

Commit 43c0ff8

Browse files
committed
Auto-generated commit
1 parent 7915e14 commit 43c0ff8

File tree

11 files changed

+742
-1
lines changed

11 files changed

+742
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-04-11)
7+
## Unreleased (2026-04-13)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`c7633e9`](https://github.com/stdlib-js/stdlib/commit/c7633e9c62c55e333ad23d7f240fcab45fd25d98) - add `ndarray/remove-singleton-dimensions` [(#10807)](https://github.com/stdlib-js/stdlib/pull/10807)
1314
- [`3a4c3c1`](https://github.com/stdlib-js/stdlib/commit/3a4c3c1c8985cdd90373832b303a818d8e42785d) - add `rotr90` to namespace
1415
- [`cda31f5`](https://github.com/stdlib-js/stdlib/commit/cda31f53eb384a004a50c4249cb6e7d0795285d5) - add `ndarray/base/rotr90` [(#11030)](https://github.com/stdlib-js/stdlib/pull/11030)
1516
- [`142964b`](https://github.com/stdlib-js/stdlib/commit/142964bca2c6774129f0807bcb9786ebc373646d) - refactor declarations to satisfy TS's structural typing
@@ -834,6 +835,7 @@ A total of 49 issues were closed in this release:
834835

835836
<details>
836837

838+
- [`c7633e9`](https://github.com/stdlib-js/stdlib/commit/c7633e9c62c55e333ad23d7f240fcab45fd25d98) - **feat:** add `ndarray/remove-singleton-dimensions` [(#10807)](https://github.com/stdlib-js/stdlib/pull/10807) _(by Muhammad Haris, stdlib-bot)_
837839
- [`843db97`](https://github.com/stdlib-js/stdlib/commit/843db97a005833d8362c60da9a0326eca5aad1b8) - **docs:** update namespace table of contents [(#11358)](https://github.com/stdlib-js/stdlib/pull/11358) _(by stdlib-bot)_
838840
- [`b7a9481`](https://github.com/stdlib-js/stdlib/commit/b7a9481c3d78c1b7fa004038fd6c26ea0d604f79) - **test:** address failing tests _(by Athan Reines)_
839841
- [`3cdc9a7`](https://github.com/stdlib-js/stdlib/commit/3cdc9a7d5b1d8c703e01f93f3a796e6b6858bcad) - **chore:** fix JavaScript lint errors [(#10710)](https://github.com/stdlib-js/stdlib/pull/10710) _(by Partha Das)_
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# removeSingletonDimensions
22+
23+
> Return a read-only view of an input [ndarray][@stdlib/ndarray/ctor] with singleton dimensions removed.
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 removeSingletonDimensions = require( '@stdlib/ndarray/remove-singleton-dimensions' );
41+
```
42+
43+
#### removeSingletonDimensions( x )
44+
45+
Returns a read-only view of an input [ndarray][@stdlib/ndarray/ctor] with singleton dimensions removed.
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
// Create a 1x2x2 ndarray:
51+
var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] );
52+
// returns <ndarray>[ [ [ 1, 2 ], [ 3, 4 ] ] ]
53+
54+
// Remove singleton dimensions:
55+
var y = removeSingletonDimensions( x );
56+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
57+
```
58+
59+
The function accepts the following arguments:
60+
61+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
68+
69+
<section class="notes">
70+
71+
## Notes
72+
73+
- The function always returns a new ndarray instance even if the input ndarray does not contain any singleton dimensions.
74+
75+
</section>
76+
77+
<!-- /.notes -->
78+
79+
<!-- Package usage examples. -->
80+
81+
<section class="examples">
82+
83+
## Examples
84+
85+
<!-- eslint no-undef: "error" -->
86+
87+
```javascript
88+
var uniform = require( '@stdlib/random/uniform' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
90+
var removeSingletonDimensions = require( '@stdlib/ndarray/remove-singleton-dimensions' );
91+
92+
var x = uniform( [ 1, 1, 3, 3, 3 ], -10.0, 10.0 );
93+
console.log( ndarray2array( x ) );
94+
95+
var y = removeSingletonDimensions( x );
96+
console.log( ndarray2array( y ) );
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- 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. -->
104+
105+
<section class="references">
106+
107+
</section>
108+
109+
<!-- /.references -->
110+
111+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
112+
113+
<section class="related">
114+
115+
</section>
116+
117+
<!-- /.related -->
118+
119+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
120+
121+
<section class="links">
122+
123+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
124+
125+
<!-- <related-links> -->
126+
127+
<!-- </related-links> -->
128+
129+
</section>
130+
131+
<!-- /.links -->
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
25+
var empty = require( './../../empty' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var removeSingletonDimensions = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( format( '%s::no_singletons,1d', pkg ), function benchmark( b ) {
34+
var values;
35+
var v;
36+
var i;
37+
38+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
39+
40+
values = [
41+
empty( [ 2 ], { 'dtype': 'float64' } ),
42+
empty( [ 2 ], { 'dtype': 'float32' } ),
43+
empty( [ 2 ], { 'dtype': 'int32' } ),
44+
empty( [ 2 ], { 'dtype': 'complex128' } ),
45+
empty( [ 2 ], { 'dtype': 'generic' } )
46+
];
47+
48+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
49+
50+
b.tic();
51+
for ( i = 0; i < b.iterations; i++ ) {
52+
v = removeSingletonDimensions( values[ i%values.length ] );
53+
if ( typeof v !== 'object' ) {
54+
b.fail( 'should return an object' );
55+
}
56+
}
57+
b.toc();
58+
if ( !isndarrayLike( v ) ) {
59+
b.fail( 'should return an ndarray' );
60+
}
61+
b.pass( 'benchmark finished' );
62+
b.end();
63+
});
64+
65+
bench( format( '%s::no_singletons,2d', pkg ), function benchmark( b ) {
66+
var values;
67+
var v;
68+
var i;
69+
70+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
71+
72+
values = [
73+
empty( [ 2, 2 ], { 'dtype': 'float64' } ),
74+
empty( [ 2, 2 ], { 'dtype': 'float32' } ),
75+
empty( [ 2, 2 ], { 'dtype': 'int32' } ),
76+
empty( [ 2, 2 ], { 'dtype': 'complex128' } ),
77+
empty( [ 2, 2 ], { 'dtype': 'generic' } )
78+
];
79+
80+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
81+
82+
b.tic();
83+
for ( i = 0; i < b.iterations; i++ ) {
84+
v = removeSingletonDimensions( values[ i%values.length ] );
85+
if ( typeof v !== 'object' ) {
86+
b.fail( 'should return an object' );
87+
}
88+
}
89+
b.toc();
90+
if ( !isndarrayLike( v ) ) {
91+
b.fail( 'should return an ndarray' );
92+
}
93+
b.pass( 'benchmark finished' );
94+
b.end();
95+
});
96+
97+
bench( format( '%s::singletons,2d', pkg ), function benchmark( b ) {
98+
var values;
99+
var v;
100+
var i;
101+
102+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
103+
104+
values = [
105+
empty( [ 1, 2 ], { 'dtype': 'float64' } ),
106+
empty( [ 1, 2 ], { 'dtype': 'float32' } ),
107+
empty( [ 1, 2 ], { 'dtype': 'int32' } ),
108+
empty( [ 1, 2 ], { 'dtype': 'complex128' } ),
109+
empty( [ 1, 2 ], { 'dtype': 'generic' } )
110+
];
111+
112+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
113+
114+
b.tic();
115+
for ( i = 0; i < b.iterations; i++ ) {
116+
v = removeSingletonDimensions( values[ i%values.length ] );
117+
if ( typeof v !== 'object' ) {
118+
b.fail( 'should return an object' );
119+
}
120+
}
121+
b.toc();
122+
if ( !isndarrayLike( v ) ) {
123+
b.fail( 'should return an ndarray' );
124+
}
125+
b.pass( 'benchmark finished' );
126+
b.end();
127+
});
128+
129+
bench( format( '%s::singletons,3d', pkg ), function benchmark( b ) {
130+
var values;
131+
var v;
132+
var i;
133+
134+
/* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */
135+
136+
values = [
137+
empty( [ 1, 2, 2 ], { 'dtype': 'float64' } ),
138+
empty( [ 1, 2, 2 ], { 'dtype': 'float32' } ),
139+
empty( [ 1, 2, 2 ], { 'dtype': 'int32' } ),
140+
empty( [ 1, 2, 2 ], { 'dtype': 'complex128' } ),
141+
empty( [ 1, 2, 2 ], { 'dtype': 'generic' } )
142+
];
143+
144+
/* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */
145+
146+
b.tic();
147+
for ( i = 0; i < b.iterations; i++ ) {
148+
v = removeSingletonDimensions( values[ i%values.length ] );
149+
if ( typeof v !== 'object' ) {
150+
b.fail( 'should return an object' );
151+
}
152+
}
153+
b.toc();
154+
if ( !isndarrayLike( v ) ) {
155+
b.fail( 'should return an ndarray' );
156+
}
157+
b.pass( 'benchmark finished' );
158+
b.end();
159+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( x )
3+
Returns a read-only view of an input ndarray with singleton dimensions
4+
removed.
5+
6+
The function always returns a new ndarray instance even if the input ndarray
7+
does not contain any singleton dimensions.
8+
9+
Parameters
10+
----------
11+
x: ndarray
12+
Input array.
13+
14+
Returns
15+
-------
16+
out: ndarray
17+
Output array.
18+
19+
Examples
20+
--------
21+
> var opts = { 'ndmin': 5 };
22+
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ], opts )
23+
<ndarray>[ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ]
24+
> var y = {{alias}}( x )
25+
<ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
26+
27+
See Also
28+
--------
29+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { typedndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Returns a read-only view of an input ndarray with singleton dimensions removed.
27+
*
28+
* @param x - input array
29+
* @returns output array
30+
*
31+
* @example
32+
* var array = require( `@stdlib/ndarray/array` );
33+
*
34+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {
35+
* 'ndmin': 5
36+
* });
37+
* // returns <ndarray>[ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ]
38+
*
39+
* var y = removeSingletonDimensions( x );
40+
* // returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
41+
*/
42+
declare function removeSingletonDimensions<T = unknown, U extends typedndarray<T> = typedndarray<T>>( x: U ): U;
43+
44+
45+
// EXPORTS //
46+
47+
export = removeSingletonDimensions;

0 commit comments

Comments
 (0)