Skip to content

Commit 03e3b15

Browse files
committed
feat: add lapack/base/zlacpy
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 987497f commit 03e3b15

File tree

16 files changed

+2607
-0
lines changed

16 files changed

+2607
-0
lines changed
+260
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
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+
# zlacpy
22+
23+
> Copy all or part of a matrix `A` to another matrix `B`.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zlacpy = require( '@stdlib/lapack/base/zlacpy' );
31+
```
32+
33+
#### zlacpy( order, uplo, M, N, A, LDA, B, LDB )
34+
35+
Copies all or part of a matrix `A` to another matrix `B`.
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
40+
var A = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
41+
var B = new Complex128Array( 4 );
42+
43+
zlacpy( 'row-major', 'all', 2, 2, A, 2, B, 2 );
44+
// B => <Complex128Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout.
50+
- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of a matrix `A`.
51+
- **M**: number of rows in `A`.
52+
- **N**: number of columns in `A`.
53+
- **A**: input [`Complex128Array`][@stdlib/array/complex128].
54+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
55+
- **B**: output [`Complex128Array`][@stdlib/array/complex128].
56+
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).
57+
58+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
59+
60+
<!-- eslint-disable stdlib/capitalized-comments -->
61+
62+
```javascript
63+
var Complex128Array = require( '@stdlib/array/complex128' );
64+
65+
// Initial arrays...
66+
var A0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
67+
var B0 = new Complex128Array( 5 );
68+
69+
// Create offset views...
70+
var A1 = new Complex128Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
71+
var B1 = new Complex128Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
72+
73+
zlacpy( 'row-major', 'all', 2, 2, A1, 2, B1, 2 );
74+
// B0 => <Complex128Array>[ 0.0, 2.0, 3.0, 4.0, 5.0 ]
75+
```
76+
77+
#### zlacpy.ndarray( uplo, M, N, A, sa1, sa2, oa, B, sb1, sb2, ob )
78+
79+
Copies all or part of a matrix `A` to another matrix `B` using alternative indexing semantics.
80+
81+
```javascript
82+
var Complex128Array = require( '@stdlib/array/complex128' );
83+
84+
var A = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
85+
var B = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0 ] );
86+
87+
zlacpy.ndarray( 'all', 2, 2, A, 2, 1, 0, B, 2, 1, 0 );
88+
// B => <Complex128Array>[ 1.0, 2.0, 3.0, 4.0 ]
89+
```
90+
91+
The function has the following parameters:
92+
93+
- **uplo**: specifies whether to copy the upper or lower triangular/trapezoidal part of a matrix `A`.
94+
- **M**: number of rows in `A`.
95+
- **N**: number of columns in `A`.
96+
- **A**: input [`Complex128Array`][@stdlib/array/complex128].
97+
- **sa1**: stride of the first dimension of `A`.
98+
- **sa2**: stride of the second dimension of `A`.
99+
- **oa**: starting index for `A`.
100+
- **B**: output [`Complex128Array`][@stdlib/array/complex128].
101+
- **sb1**: stride of the first dimension of `B`.
102+
- **sb2**: stride of the second dimension of `B`.
103+
- **ob**: starting index for `B`.
104+
105+
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,
106+
107+
```javascript
108+
var Complex128Array = require( '@stdlib/array/complex128' );
109+
110+
var A = new Complex128Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] );
111+
var B = new Complex128Array( [ 0.0, 0.0, 11.0, 312.0, 53.0, 412.0 ] );
112+
113+
zlacpy.ndarray( 'all', 2, 2, A, 2, 1, 1, B, 2, 1, 2 );
114+
// B => <Complex128Array>[ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ]
115+
```
116+
117+
</section>
118+
119+
<!-- /.usage -->
120+
121+
<section class="notes">
122+
123+
## Notes
124+
125+
- `zlacpy()` corresponds to the [LAPACK][lapack] routine [`zlacpy`][lapack-zlacpy].
126+
127+
</section>
128+
129+
<!-- /.notes -->
130+
131+
<section class="examples">
132+
133+
## Examples
134+
135+
<!-- eslint no-undef: "error" -->
136+
137+
```javascript
138+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
139+
var uniform = require( '@stdlib/random/array/discrete-uniform' );
140+
var numel = require( '@stdlib/ndarray/base/numel' );
141+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
142+
var zlacpy = require( '@stdlib/lapack/base/zlacpy' );
143+
144+
var shape = [ 5, 8 ];
145+
var order = 'row-major';
146+
var strides = shape2strides( shape, order );
147+
148+
var N = numel( shape );
149+
150+
var A = uniform( N, -10, 10, {
151+
'dtype': 'complex128'
152+
});
153+
console.log( ndarray2array( A, shape, strides, 0, order ) );
154+
155+
var B = uniform( N, -10, 10, {
156+
'dtype': 'complex128'
157+
});
158+
console.log( ndarray2array( B, shape, strides, 0, order ) );
159+
160+
zlacpy( order, 'all', shape[ 0 ], shape[ 1 ], A, strides[ 0 ], B, strides[ 0 ] );
161+
console.log( ndarray2array( B, shape, strides, 0, order ) );
162+
```
163+
164+
</section>
165+
166+
<!-- /.examples -->
167+
168+
<!-- C interface documentation. -->
169+
170+
* * *
171+
172+
<section class="c">
173+
174+
## C APIs
175+
176+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
177+
178+
<section class="intro">
179+
180+
</section>
181+
182+
<!-- /.intro -->
183+
184+
<!-- C usage documentation. -->
185+
186+
<section class="usage">
187+
188+
### Usage
189+
190+
```c
191+
TODO
192+
```
193+
194+
#### TODO
195+
196+
TODO.
197+
198+
```c
199+
TODO
200+
```
201+
202+
TODO
203+
204+
```c
205+
TODO
206+
```
207+
208+
</section>
209+
210+
<!-- /.usage -->
211+
212+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
213+
214+
<section class="notes">
215+
216+
</section>
217+
218+
<!-- /.notes -->
219+
220+
<!-- C API usage examples. -->
221+
222+
<section class="examples">
223+
224+
### Examples
225+
226+
```c
227+
TODO
228+
```
229+
230+
</section>
231+
232+
<!-- /.examples -->
233+
234+
</section>
235+
236+
<!-- /.c -->
237+
238+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
239+
240+
<section class="related">
241+
242+
</section>
243+
244+
<!-- /.related -->
245+
246+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
247+
248+
<section class="links">
249+
250+
[lapack]: https://www.netlib.org/lapack/explore-html/
251+
252+
[lapack-zlacpy]: https://netlib.org/lapack/explore-html/d0/d9e/group__lacpy_ga243f0a47458b9a525136a69146c10192.html#ga243f0a47458b9a525136a69146c10192
253+
254+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
255+
256+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
257+
258+
</section>
259+
260+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var zlacpy = require( './../lib/zlacpy.js' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} N - number of elements along each dimension
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( N ) {
42+
var opts;
43+
var A;
44+
var B;
45+
46+
opts = {
47+
'dtype': 'complex128'
48+
};
49+
50+
A = uniform( N*N, -10.0, 10.0, opts );
51+
B = uniform( N*N, -10.0, 10.0, opts );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var z;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
z = zlacpy( 'column-major', 'all', N, N, A, N, B, N );
67+
if ( isnan( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var min;
90+
var max;
91+
var N;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
100+
f = createBenchmark( N );
101+
bench( pkg+':order=column-major,size='+(N*N), f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)