Skip to content

Commit cd5ad1c

Browse files
Pranavchikukgryte
andauthored
feat: add lapack/base/dge-trans
PR-URL: #2734 Ref: #2464 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 3646d49 commit cd5ad1c

File tree

16 files changed

+2758
-0
lines changed

16 files changed

+2758
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# dge-trans
22+
23+
> Convert a matrix from row-major layout to column-major layout or vice versa.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dgetrans = require( '@stdlib/lapack/base/dge-trans' );
31+
```
32+
33+
#### dgetrans( order, M, N, A, LDA, out, LDO )
34+
35+
Converts a matrix from row-major layout to column-major layout or vice versa.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
41+
var out = new Float64Array( 6 );
42+
43+
out = dgetrans( 'row-major', 2, 3, A, 3, out, 2 );
44+
// returns <Float64Array>[ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout.
50+
- **M**: number of rows in `A`.
51+
- **N**: number of columns in `A`.
52+
- **A**: input [`Float64Array`][mdn-float64array].
53+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
54+
- **out**: output [`Float64Array`][mdn-float64array].
55+
- **LDO**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`).
56+
57+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
58+
59+
<!-- eslint-disable stdlib/capitalized-comments -->
60+
61+
```javascript
62+
var Float64Array = require( '@stdlib/array/float64' );
63+
64+
// Initial arrays...
65+
var A0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
66+
var Out0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
67+
68+
// Create offset views...
69+
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
70+
var Out1 = new Float64Array( Out0.buffer, Out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
71+
72+
dgetrans( 'row-major', 2, 2, A1, 2, Out1, 2 );
73+
// Out0 => <Float64Array>[ 0.0, 1.0, 3.0, 2.0, 4.0 ]
74+
```
75+
76+
#### dgetrans.ndarray( M, N, A, sa1, sa2, oa, out, so1, so2, oo )
77+
78+
Converts a matrix from row-major layout to column-major layout or vice versa using alternative indexing semantics.
79+
80+
```javascript
81+
var Float64Array = require( '@stdlib/array/float64' );
82+
83+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
84+
var out = new Float64Array( 6 );
85+
86+
out = dgetrans.ndarray( 2, 3, A, 3, 1, 0, out, 2, 1, 0 );
87+
// returns <Float64Array>[ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ]
88+
```
89+
90+
The function has the following parameters:
91+
92+
- **M**: number of rows in `A`.
93+
- **N**: number of columns in `A`.
94+
- **A**: input [`Float64Array`][mdn-float64array].
95+
- **sa1**: stride of the first dimension of `A`.
96+
- **sa2**: stride of the second dimension of `A`.
97+
- **oa**: starting index for `A`.
98+
- **out**: output [`Float64Array`][mdn-float64array].
99+
- **so1**: stride of the first dimension of `out`.
100+
- **so2**: stride of the second dimension of `out`.
101+
- **oo**: starting index for `out`.
102+
103+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,
104+
105+
```javascript
106+
var Float64Array = require( '@stdlib/array/float64' );
107+
108+
var A = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
109+
var out = new Float64Array( [ 0.0, 0.0, 11.0, 312.0, 53.0, 412.0 ] );
110+
111+
dgetrans.ndarray( 2, 2, A, 2, 1, 1, out, 2, 1, 2 );
112+
// out => <Float64Array>[ 0.0, 0.0, 1.0, 3.0, 2.0, 4.0 ]
113+
```
114+
115+
</section>
116+
117+
<!-- /.usage -->
118+
119+
<section class="notes">
120+
121+
## Notes
122+
123+
- `dgetrans()` corresponds to the [LAPACK][lapack] utility routine [`dge_trans`][lapack-dge-trans].
124+
125+
</section>
126+
127+
<!-- /.notes -->
128+
129+
<section class="examples">
130+
131+
## Examples
132+
133+
<!-- eslint-disable max-len -->
134+
135+
<!-- eslint no-undef: "error" -->
136+
137+
```javascript
138+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
139+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
140+
var numel = require( '@stdlib/ndarray/base/numel' );
141+
var Float64Array = require( '@stdlib/array/float64' );
142+
var dgetrans = require( '@stdlib/lapack/base/dge-trans' );
143+
144+
var shapeA = [ 2, 3 ];
145+
var shapeOut = [ 3, 2 ];
146+
147+
// Row-major layout...
148+
var order = 'row-major';
149+
150+
var stridesA = shape2strides( shapeA, order );
151+
var stridesOut = shape2strides( shapeOut, order );
152+
153+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
154+
console.log( ndarray2array( A, shapeA, stridesA, 0, order ) );
155+
156+
var out = new Float64Array( numel( shapeA ) );
157+
158+
out = dgetrans( order, shapeA[0], shapeA[1], A, stridesA[0], out, stridesOut[0] );
159+
console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) );
160+
161+
// Column-major layout...
162+
order = 'column-major';
163+
164+
stridesA = shape2strides( shapeA, order );
165+
stridesOut = shape2strides( shapeOut, order );
166+
167+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
168+
console.log( ndarray2array( A, shapeA, stridesA, 0, order ) );
169+
170+
out = new Float64Array( numel( shapeA ) );
171+
172+
out = dgetrans( order, shapeA[0], shapeA[1], A, stridesA[1], out, stridesOut[1] );
173+
console.log( ndarray2array( out, shapeOut, stridesOut, 0, order ) );
174+
175+
// Input and output arrays have different layouts...
176+
stridesA = shape2strides( shapeA, 'row-major' );
177+
stridesOut = shape2strides( shapeOut, 'column-major' );
178+
179+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
180+
console.log( ndarray2array( A, shapeA, stridesA, 0, 'row-major' ) );
181+
182+
out = new Float64Array( numel( shapeA ) );
183+
184+
out = dgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 );
185+
console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'column-major' ) );
186+
187+
// Input and output arrays have different layouts...
188+
stridesA = shape2strides( shapeA, 'column-major' );
189+
stridesOut = shape2strides( shapeOut, 'row-major' );
190+
191+
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
192+
console.log( ndarray2array( A, shapeA, stridesA, 0, 'column-major' ) );
193+
194+
out = new Float64Array( numel( shapeA ) );
195+
196+
out = dgetrans.ndarray( shapeA[0], shapeA[1], A, stridesA[0], stridesA[1], 0, out, stridesOut[0], stridesOut[1], 0 );
197+
console.log( ndarray2array( out, shapeOut, stridesOut, 0, 'row-major' ) );
198+
```
199+
200+
</section>
201+
202+
<!-- /.examples -->
203+
204+
<!-- C interface documentation. -->
205+
206+
* * *
207+
208+
<section class="c">
209+
210+
## C APIs
211+
212+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
213+
214+
<section class="intro">
215+
216+
</section>
217+
218+
<!-- /.intro -->
219+
220+
<!-- C usage documentation. -->
221+
222+
<section class="usage">
223+
224+
### Usage
225+
226+
```c
227+
TODO
228+
```
229+
230+
#### TODO
231+
232+
TODO.
233+
234+
```c
235+
TODO
236+
```
237+
238+
TODO
239+
240+
```c
241+
TODO
242+
```
243+
244+
</section>
245+
246+
<!-- /.usage -->
247+
248+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
249+
250+
<section class="notes">
251+
252+
</section>
253+
254+
<!-- /.notes -->
255+
256+
<!-- C API usage examples. -->
257+
258+
<section class="examples">
259+
260+
### Examples
261+
262+
```c
263+
TODO
264+
```
265+
266+
</section>
267+
268+
<!-- /.examples -->
269+
270+
</section>
271+
272+
<!-- /.c -->
273+
274+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
275+
276+
<section class="related">
277+
278+
</section>
279+
280+
<!-- /.related -->
281+
282+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
283+
284+
<section class="links">
285+
286+
[lapack]: https://www.netlib.org/lapack/explore-html/
287+
288+
[lapack-dge-trans]: https://github.com/OpenMathLib/OpenBLAS/blob/develop/lapack-netlib/LAPACKE/utils/lapacke_dge_trans.c
289+
290+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
291+
292+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
293+
294+
</section>
295+
296+
<!-- /.links -->

0 commit comments

Comments
 (0)