Skip to content

Commit e3d6715

Browse files
committed
Auto-generated commit
1 parent de18be6 commit e3d6715

27 files changed

Lines changed: 2301 additions & 6 deletions

File tree

CHANGELOG.md

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

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

7-
## Unreleased (2026-04-24)
7+
## Unreleased (2026-04-25)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`8cb6c7c`](https://github.com/stdlib-js/stdlib/commit/8cb6c7c7a1d109ec00a04312ecf23532036f45ac) - add `ndarray/base/append-singleton-dimensions` [(#11782)](https://github.com/stdlib-js/stdlib/pull/11782)
14+
- [`94fc2ce`](https://github.com/stdlib-js/stdlib/commit/94fc2ced847969980cae2241b175f0f9f799658e) - add `ndarray/base/to-rot90` [(#11748)](https://github.com/stdlib-js/stdlib/pull/11748)
1315
- [`c88ea56`](https://github.com/stdlib-js/stdlib/commit/c88ea56a2f3acfe5ce345108eb42ea991b689d3f) - add `toRotr90` to namespace
1416
- [`465a072`](https://github.com/stdlib-js/stdlib/commit/465a072ec949832752bd1aa2bdb7a3b165e90763) - add `ndarray/base/to-rotr90` [(#11747)](https://github.com/stdlib-js/stdlib/pull/11747)
1517
- [`bb94409`](https://github.com/stdlib-js/stdlib/commit/bb944095335edac473c0c655d7300228ed856ca5) - add `rot90` to namespace
@@ -881,6 +883,9 @@ A total of 49 issues were closed in this release:
881883

882884
<details>
883885

886+
- [`8cb6c7c`](https://github.com/stdlib-js/stdlib/commit/8cb6c7c7a1d109ec00a04312ecf23532036f45ac) - **feat:** add `ndarray/base/append-singleton-dimensions` [(#11782)](https://github.com/stdlib-js/stdlib/pull/11782) _(by Muhammad Haris, Athan Reines)_
887+
- [`3ca7c21`](https://github.com/stdlib-js/stdlib/commit/3ca7c2179081a36fa279dbb1e12f8e81d811e997) - **docs:** propagate recent `ndarray/base` comment and note fixes to sibling packages [(#11762)](https://github.com/stdlib-js/stdlib/pull/11762) _(by Philipp Burckhardt)_
888+
- [`94fc2ce`](https://github.com/stdlib-js/stdlib/commit/94fc2ced847969980cae2241b175f0f9f799658e) - **feat:** add `ndarray/base/to-rot90` [(#11748)](https://github.com/stdlib-js/stdlib/pull/11748) _(by Muhammad Haris, Athan Reines)_
884889
- [`c88ea56`](https://github.com/stdlib-js/stdlib/commit/c88ea56a2f3acfe5ce345108eb42ea991b689d3f) - **feat:** add `toRotr90` to namespace _(by Athan Reines)_
885890
- [`465a072`](https://github.com/stdlib-js/stdlib/commit/465a072ec949832752bd1aa2bdb7a3b165e90763) - **feat:** add `ndarray/base/to-rotr90` [(#11747)](https://github.com/stdlib-js/stdlib/pull/11747) _(by Muhammad Haris, Athan Reines)_
886891
- [`1bb47ae`](https://github.com/stdlib-js/stdlib/commit/1bb47aee4385a96718afb38792d96ec5ec09e7da) - **docs:** fix comment _(by Athan Reines)_
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
# appendSingletonDimensions
22+
23+
> Append singleton dimensions.
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+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var appendSingletonDimensions = require( '@stdlib/ndarray/base/append-singleton-dimensions' );
43+
```
44+
45+
#### appendSingletonDimensions( x, n, writable )
46+
47+
Returns an ndarray with a specified number of appended singleton dimensions (i.e., dimensions whose size is equal to `1`).
48+
49+
<!-- eslint-disable id-length -->
50+
51+
```javascript
52+
var array = require( '@stdlib/ndarray/array' );
53+
54+
// Create a 2x2 ndarray:
55+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
56+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
57+
58+
// Append singleton dimensions:
59+
var y = appendSingletonDimensions( x, 3, false );
60+
// returns <ndarray>[ [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 4 ] ] ] ] ]
61+
```
62+
63+
The function accepts the following arguments:
64+
65+
- **x**: input ndarray.
66+
- **n**: number of singleton dimensions to append.
67+
- **writable**: boolean indicating whether a returned ndarray should be writable.
68+
69+
</section>
70+
71+
<!-- /.usage -->
72+
73+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
74+
75+
<section class="notes">
76+
77+
## Notes
78+
79+
- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances.
80+
81+
</section>
82+
83+
<!-- /.notes -->
84+
85+
<!-- Package usage examples. -->
86+
87+
<section class="examples">
88+
89+
## Examples
90+
91+
<!-- eslint-disable id-length -->
92+
93+
<!-- eslint no-undef: "error" -->
94+
95+
```javascript
96+
var uniform = require( '@stdlib/random/uniform' );
97+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
98+
var appendSingletonDimensions = require( '@stdlib/ndarray/base/append-singleton-dimensions' );
99+
100+
var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
101+
console.log( ndarray2array( x ) );
102+
103+
var y = appendSingletonDimensions( x, 3, false );
104+
console.log( ndarray2array( y ) );
105+
```
106+
107+
</section>
108+
109+
<!-- /.examples -->
110+
111+
<!-- 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. -->
112+
113+
<section class="references">
114+
115+
</section>
116+
117+
<!-- /.references -->
118+
119+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
120+
121+
<section class="related">
122+
123+
</section>
124+
125+
<!-- /.related -->
126+
127+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="links">
130+
131+
</section>
132+
133+
<!-- /.links -->
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 Float64Array = require( '@stdlib/array/float64' );
25+
var ndarrayBase = require( './../../../base/ctor' );
26+
var ndarray = require( './../../../ctor' );
27+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var appendSingletonDimensions = require( './../lib' );
31+
32+
33+
// MAIN //
34+
35+
bench( format( '%s::base_ndarray,2d', pkg ), function benchmark( b ) {
36+
var strides;
37+
var values;
38+
var buffer;
39+
var offset;
40+
var dtype;
41+
var shape;
42+
var order;
43+
var out;
44+
var i;
45+
46+
dtype = 'float64';
47+
buffer = new Float64Array( 2 );
48+
shape = [ 2 ];
49+
strides = [ 1 ];
50+
offset = 0;
51+
order = 'row-major';
52+
53+
values = [
54+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
55+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
56+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
57+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
58+
ndarrayBase( dtype, buffer, shape, strides, offset, order )
59+
];
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
out = appendSingletonDimensions( values[ i%values.length ], 1, false );
64+
if ( typeof out !== 'object' ) {
65+
b.fail( 'should return an object' );
66+
}
67+
}
68+
b.toc();
69+
if ( !isndarrayLike( out ) ) {
70+
b.fail( 'should return an ndarray' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
});
75+
76+
bench( format( '%s::ndarray,2d', pkg ), function benchmark( b ) {
77+
var strides;
78+
var values;
79+
var buffer;
80+
var offset;
81+
var dtype;
82+
var shape;
83+
var order;
84+
var out;
85+
var i;
86+
87+
dtype = 'float64';
88+
buffer = new Float64Array( 2 );
89+
shape = [ 2 ];
90+
strides = [ 1 ];
91+
offset = 0;
92+
order = 'row-major';
93+
94+
values = [
95+
ndarray( dtype, buffer, shape, strides, offset, order ),
96+
ndarray( dtype, buffer, shape, strides, offset, order ),
97+
ndarray( dtype, buffer, shape, strides, offset, order ),
98+
ndarray( dtype, buffer, shape, strides, offset, order ),
99+
ndarray( dtype, buffer, shape, strides, offset, order )
100+
];
101+
102+
b.tic();
103+
for ( i = 0; i < b.iterations; i++ ) {
104+
out = appendSingletonDimensions( values[ i%values.length ], 1, false );
105+
if ( typeof out !== 'object' ) {
106+
b.fail( 'should return an object' );
107+
}
108+
}
109+
b.toc();
110+
if ( !isndarrayLike( out ) ) {
111+
b.fail( 'should return an ndarray' );
112+
}
113+
b.pass( 'benchmark finished' );
114+
b.end();
115+
});
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 array = require( './../../../array' );
25+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var appendSingletonDimensions = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} ndims - number of singleton dimensions
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( ndims ) {
41+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var out;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
out = appendSingletonDimensions( x, ndims, false );
57+
if ( typeof out !== 'object' ) {
58+
b.fail( 'should return an object' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isndarrayLike( out ) ) {
63+
b.fail( 'should return an ndarray' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var min;
80+
var max;
81+
var f;
82+
var i;
83+
84+
min = 1;
85+
max = 10;
86+
87+
for ( i = min; i <= max; i++ ) {
88+
f = createBenchmark( i );
89+
bench( format( '%s::ndarray,2d:singleton_dimensions=%d', pkg, i ), f );
90+
}
91+
}
92+
93+
main();

0 commit comments

Comments
 (0)