Skip to content

Commit 4eeada0

Browse files
committed
feat: add ndarray/base/to-transposed
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 05e2a72 commit 4eeada0

File tree

10 files changed

+1661
-0
lines changed

10 files changed

+1661
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
# to-transposed
22+
23+
> Return a new transposed ndarray.
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 toTransposed = require( '@stdlib/ndarray/base/to-transposed' );
41+
```
42+
43+
#### toTransposed( x )
44+
45+
Returns a new transposed ndarray.
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
51+
// returns <ndarray>[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
52+
53+
var out = toTransposed( x );
54+
// returns <ndarray>[ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
55+
```
56+
57+
The function accepts the following arguments:
58+
59+
- **x**: input ndarray.
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+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<!-- Package usage examples. -->
74+
75+
<section class="examples">
76+
77+
## Examples
78+
79+
<!-- eslint-disable stdlib/no-redeclare -->
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var Float64Array = require( '@stdlib/array/float64' );
85+
var ndarray = require( '@stdlib/ndarray/ctor' );
86+
var rpad = require( '@stdlib/string/right-pad' );
87+
var toTransposed = require( '@stdlib/ndarray/base/to-transposed' );
88+
89+
function print( arr, name ) {
90+
var str;
91+
var sh;
92+
var p;
93+
var i;
94+
var j;
95+
var k;
96+
97+
sh = arr.shape;
98+
for ( i = 0; i < sh[0]; i++ ) {
99+
str = name+'['+i+',:,:] = [ ';
100+
p = str.length + 1;
101+
for ( j = 0; j < sh[1]; j++ ) {
102+
if ( j > 0 ) {
103+
str += rpad( '\n', p, ' ' );
104+
}
105+
for ( k = 0; k < sh[2]; k++ ) {
106+
str += arr.get( i, j, k );
107+
if ( k < sh[2]-1 ) {
108+
str += ', ';
109+
}
110+
}
111+
}
112+
console.log( str + ' ]\n' );
113+
}
114+
}
115+
116+
// Create a data buffer:
117+
var buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
118+
119+
// Create a stack of matrices:
120+
var x = new ndarray( 'float64', buf, [ 2, 2, 3 ], [ 0, 3, 1 ], 0, 'row-major' );
121+
122+
// Transpose the stack of matrices:
123+
var y = toTransposed( x );
124+
125+
// Print the stacks:
126+
console.log( '' );
127+
print( x, 'X' );
128+
console.log( '' );
129+
print( y, 'Y' );
130+
```
131+
132+
</section>
133+
134+
<!-- /.examples -->
135+
136+
<!-- 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. -->
137+
138+
<section class="references">
139+
140+
</section>
141+
142+
<!-- /.references -->
143+
144+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
145+
146+
<section class="related">
147+
148+
</section>
149+
150+
<!-- /.related -->
151+
152+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
153+
154+
<section class="links">
155+
156+
<!-- <related-links> -->
157+
158+
<!-- </related-links> -->
159+
160+
</section>
161+
162+
<!-- /.links -->

0 commit comments

Comments
 (0)