Skip to content

Commit 150cca9

Browse files
committed
Auto-generated commit
1 parent fab50d4 commit 150cca9

11 files changed

Lines changed: 957 additions & 1 deletion

File tree

‎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-05-10)
7+
## Unreleased (2026-05-11)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`5c1463c`](https://github.com/stdlib-js/stdlib/commit/5c1463c8c0240b44991231d5b8b120d78c6d8ad1) - add `ndarray/transpose` [(#12030)](https://github.com/stdlib-js/stdlib/pull/12030)
1314
- [`0e2b5a5`](https://github.com/stdlib-js/stdlib/commit/0e2b5a5e9dec8520a7e6676876aae915c4b2ab2c) - add `descriptor` to namespace
1415
- [`b5d65f3`](https://github.com/stdlib-js/stdlib/commit/b5d65f3863b2d9bcee6f6dbfc53fff58a10380d4) - add `ndarray/base/descriptor`
1516
- [`851962b`](https://github.com/stdlib-js/stdlib/commit/851962b6ea17e9ac3d0ab09617432121e007a0ed) - add `toReversedDimensions` to namespace
@@ -929,6 +930,7 @@ A total of 49 issues were closed in this release:
929930

930931
<details>
931932

933+
- [`5c1463c`](https://github.com/stdlib-js/stdlib/commit/5c1463c8c0240b44991231d5b8b120d78c6d8ad1) - **feat:** add `ndarray/transpose` [(#12030)](https://github.com/stdlib-js/stdlib/pull/12030) _(by Muhammad Haris, Athan Reines)_
932934
- [`b8d09ca`](https://github.com/stdlib-js/stdlib/commit/b8d09cac262a732b639c44606e0d85f974965085) - **chore:** follow-up corrections for commits merged to develop on 2026-05-10 [(#12052)](https://github.com/stdlib-js/stdlib/pull/12052) _(by Philipp Burckhardt)_
933935
- [`42c6213`](https://github.com/stdlib-js/stdlib/commit/42c6213a4a37afe7b71ed391eb67f63b3fe3f96d) - **docs:** fix `real`/`imag` import in `ndarray/base/unary-by` [(#12060)](https://github.com/stdlib-js/stdlib/pull/12060) _(by Karan Anand)_
934936
- [`e64ea31`](https://github.com/stdlib-js/stdlib/commit/e64ea3136aa617d66672f768f280a2023db457fc) - **docs:** improve doctests for complex number typed arrays in `ndarray/base/broadcast-scalar` [(#12048)](https://github.com/stdlib-js/stdlib/pull/12048) _(by Karan Anand, Athan Reines)_

‎transpose/README.md‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
# transpose
22+
23+
> Return a **read-only** view of an input [`ndarray`][@stdlib/ndarray/ctor] in which the last two dimensions are transposed.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro section element. -->
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 transpose = require( '@stdlib/ndarray/transpose' );
41+
```
42+
43+
#### transpose( x )
44+
45+
Returns a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] in which the last two dimensions are transposed.
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] );
51+
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]
52+
53+
var y = transpose( x );
54+
// returns <ndarray>[ [ 1.0, 4.0 ], [ 2.0, 5.0 ], [ 3.0, 6.0 ] ]
55+
```
56+
57+
The function accepts the following arguments:
58+
59+
- **x**: input [`ndarray`][@stdlib/ndarray/ctor].
60+
61+
</section>
62+
63+
<!-- /.usage -->
64+
65+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
66+
67+
<section class="notes">
68+
69+
## Notes
70+
71+
- The function operates on a stack of matrices, transposing the last two dimensions of the input ndarray.
72+
- The input ndarray must have at least two dimensions.
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<!-- Package usage examples. -->
79+
80+
<section class="examples">
81+
82+
## Examples
83+
84+
<!-- eslint no-undef: "error" -->
85+
86+
```javascript
87+
var uniform = require( '@stdlib/random/uniform' );
88+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
89+
var transpose = require( '@stdlib/ndarray/transpose' );
90+
91+
var x = uniform( [ 2, 3, 4 ], -10.0, 10.0 );
92+
console.log( ndarray2array( x ) );
93+
94+
var y = transpose( x );
95+
console.log( ndarray2array( y ) );
96+
```
97+
98+
</section>
99+
100+
<!-- /.examples -->
101+
102+
<!-- 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. -->
103+
104+
<section class="references">
105+
106+
</section>
107+
108+
<!-- /.references -->
109+
110+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
111+
112+
<section class="related">
113+
114+
</section>
115+
116+
<!-- /.related -->
117+
118+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="links">
121+
122+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
123+
124+
<!-- <related-links> -->
125+
126+
<!-- </related-links> -->
127+
128+
</section>
129+
130+
<!-- /.links -->

‎transpose/benchmark/benchmark.js‎

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 transpose = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( format( '%s:ndims=2', 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, 2 ], { 'dtype': 'float64' } ),
42+
empty( [ 2, 2 ], { 'dtype': 'float32' } ),
43+
empty( [ 2, 2 ], { 'dtype': 'int32' } ),
44+
empty( [ 2, 2 ], { 'dtype': 'complex128' } ),
45+
empty( [ 2, 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 = transpose( values[ i%values.length ] );
53+
if ( typeof v !== 'object' ) {
54+
b.fail( 'should return an ndarray' );
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:ndims=3', 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, 2 ], { 'dtype': 'float64' } ),
74+
empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ),
75+
empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ),
76+
empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ),
77+
empty( [ 2, 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 = transpose( values[ i%values.length ] );
85+
if ( typeof v !== 'object' ) {
86+
b.fail( 'should return an ndarray' );
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:ndims=4', 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( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ),
106+
empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ),
107+
empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ),
108+
empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ),
109+
empty( [ 2, 2, 2, 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 = transpose( values[ i%values.length ] );
117+
if ( typeof v !== 'object' ) {
118+
b.fail( 'should return an ndarray' );
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:ndims=5', 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( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ),
138+
empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ),
139+
empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ),
140+
empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ),
141+
empty( [ 2, 2, 2, 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 = transpose( values[ i%values.length ] );
149+
if ( typeof v !== 'object' ) {
150+
b.fail( 'should return an ndarray' );
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+
});

‎transpose/docs/repl.txt‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{{alias}}( x )
3+
Returns a read-only view of an input ndarray in which the last two
4+
dimensions are transposed.
5+
6+
The function operates on a stack of matrices, transposing the last two
7+
dimensions of the input ndarray.
8+
9+
The input ndarray must have at least two dimensions.
10+
11+
Parameters
12+
----------
13+
x: ndarray
14+
Input array.
15+
16+
Returns
17+
-------
18+
out: ndarray
19+
Output array view.
20+
21+
Examples
22+
--------
23+
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] )
24+
<ndarray>[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
25+
> var y = {{alias}}( x )
26+
<ndarray>[ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
27+
28+
See Also
29+
--------
30+

‎transpose/docs/types/index.d.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 { ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Returns a read-only view of an input ndarray in which the last two dimensions are transposed.
27+
*
28+
* ## Notes
29+
*
30+
* - The function operates on a stack of matrices, transposing the last two dimensions of the input ndarray.
31+
* - The input ndarray must have at least two dimensions.
32+
*
33+
* @param x - input array
34+
* @returns output array
35+
*
36+
* @example
37+
* var array = require( '@stdlib/ndarray/array' );
38+
*
39+
* var x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ] );
40+
* // returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]
41+
*
42+
* var y = transpose( x );
43+
* // returns <ndarray>[ [ 1.0, 4.0 ], [ 2.0, 5.0 ], [ 3.0, 6.0 ] ]
44+
*/
45+
declare function transpose<T extends ndarray = ndarray>( x: T ): T;
46+
47+
48+
// EXPORTS //
49+
50+
export = transpose;

0 commit comments

Comments
 (0)