Skip to content

Commit 995ecc4

Browse files
committed
feat: add blas/ext/base/zcartesian-square
--- 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 bb1eae9 commit 995ecc4

33 files changed

Lines changed: 5352 additions & 0 deletions
Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
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+
# zcartesianSquare
22+
23+
> Compute the Cartesian square for a double-precision complex floating-point strided array.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zcartesianSquare = require( '@stdlib/blas/ext/base/zcartesian-square' );
31+
```
32+
33+
#### zcartesianSquare( order, N, x, strideX, out, LDO )
34+
35+
Computes the Cartesian square for a double-precision complex floating-point strided array.
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
40+
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
41+
var out = new Complex128Array( 8 );
42+
43+
zcartesianSquare( 'row-major', x.length, x, 1, out, 2 );
44+
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
50+
- **N**: number of indexed elements.
51+
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
52+
- **strideX**: stride length for `x`.
53+
- **out**: output [`Complex128Array`][@stdlib/array/complex128].
54+
- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`).
55+
56+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian square of every other element:
57+
58+
```javascript
59+
var Complex128Array = require( '@stdlib/array/complex128' );
60+
61+
var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );
62+
var out = new Complex128Array( 8 );
63+
64+
zcartesianSquare( 'row-major', 2, x, 2, out, 2 );
65+
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
66+
```
67+
68+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
69+
70+
```javascript
71+
var Complex128Array = require( '@stdlib/array/complex128' );
72+
73+
// Initial array:
74+
var x0 = new Complex128Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] );
75+
76+
// Create an offset view:
77+
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
78+
79+
// Output array:
80+
var out = new Complex128Array( 8 );
81+
82+
zcartesianSquare( 'row-major', 2, x1, 1, out, 2 );
83+
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
84+
```
85+
86+
<!-- lint disable maximum-heading-length -->
87+
88+
#### zcartesianSquare.ndarray( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut )
89+
90+
<!-- lint enable maximum-heading-length -->
91+
92+
Computes the Cartesian square for a double-precision complex floating-point strided array using alternative indexing semantics.
93+
94+
```javascript
95+
var Complex128Array = require( '@stdlib/array/complex128' );
96+
97+
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
98+
var out = new Complex128Array( 8 );
99+
100+
zcartesianSquare.ndarray( x.length, x, 1, 0, out, 2, 1, 0 );
101+
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
102+
```
103+
104+
The function has the following parameters:
105+
106+
- **N**: number of indexed elements.
107+
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
108+
- **strideX**: stride length for `x`.
109+
- **offsetX**: starting index for `x`.
110+
- **out**: output [`Complex128Array`][@stdlib/array/complex128].
111+
- **strideOut1**: stride length for the first dimension of `out`.
112+
- **strideOut2**: stride length for the second dimension of `out`.
113+
- **offsetOut**: starting index for `out`.
114+
115+
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, to access only the last two elements:
116+
117+
```javascript
118+
var Complex128Array = require( '@stdlib/array/complex128' );
119+
120+
var x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] );
121+
var out = new Complex128Array( 8 );
122+
123+
zcartesianSquare.ndarray( 2, x, 1, 2, out, 2, 1, 0 );
124+
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
125+
```
126+
127+
</section>
128+
129+
<!-- /.usage -->
130+
131+
<section class="notes">
132+
133+
## Notes
134+
135+
- Pairs are stored as rows in the output matrix, where the first column contains the first element of each pair and the second column contains the second element.
136+
- For an input array of length `N`, the output array must contain at least `N * N * 2` indexed elements.
137+
- For row-major order, the `LDO` parameter must be greater than or equal to `2`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N*N)`.
138+
- If `N <= 0`, both functions return `out` unchanged.
139+
140+
</section>
141+
142+
<!-- /.notes -->
143+
144+
<section class="examples">
145+
146+
## Examples
147+
148+
<!-- eslint no-undef: "error" -->
149+
150+
```javascript
151+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
152+
var Complex128Array = require( '@stdlib/array/complex128' );
153+
var zcartesianSquare = require( '@stdlib/blas/ext/base/zcartesian-square' );
154+
155+
var N = 2;
156+
var xbuf = discreteUniform( N*2, 1, 10, {
157+
'dtype': 'float64'
158+
});
159+
var x = new Complex128Array( xbuf.buffer );
160+
console.log( x );
161+
162+
var out = new Complex128Array( N * N * 2 );
163+
zcartesianSquare( 'row-major', N, x, 1, out, 2 );
164+
console.log( out );
165+
```
166+
167+
</section>
168+
169+
<!-- /.examples -->
170+
171+
<!-- C interface documentation. -->
172+
173+
* * *
174+
175+
<section class="c">
176+
177+
## C APIs
178+
179+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
180+
181+
<section class="intro">
182+
183+
</section>
184+
185+
<!-- /.intro -->
186+
187+
<!-- C usage documentation. -->
188+
189+
<section class="usage">
190+
191+
### Usage
192+
193+
```c
194+
#include "stdlib/blas/ext/base/zcartesiansquare.h"
195+
```
196+
197+
#### stdlib_strided_zcartesian_square( order, N, \*X, strideX, \*Out, LDO )
198+
199+
Computes the Cartesian square for a double-precision complex floating-point strided array.
200+
201+
```c
202+
#include "stdlib/complex/float64/ctor.h"
203+
#include "stdlib/blas/base/shared.h"
204+
205+
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
206+
double out[ 16 ];
207+
208+
stdlib_strided_zcartesian_square( CblasRowMajor, 2, (const stdlib_complex128_t *)x, 1, (stdlib_complex128_t *)out, 2 );
209+
```
210+
211+
The function accepts the following arguments:
212+
213+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
214+
- **N**: `[in] CBLAS_INT` number of indexed elements.
215+
- **X**: `[in] stdlib_complex128_t*` input array.
216+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
217+
- **Out**: `[out] stdlib_complex128_t*` output array.
218+
- **LDO**: `[in] CBLAS_INT` stride length between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of `Out`). For row-major order, must be greater than or equal to `2`. For column-major order, must be greater than or equal to `max(1,N*N)`.
219+
220+
```c
221+
void stdlib_strided_zcartesian_square( const CBLAS_LAYOUT order, const CBLAS_INT N, const stdlib_complex128_t *X, const CBLAS_INT strideX, stdlib_complex128_t *Out, const CBLAS_INT LDO );
222+
```
223+
224+
<!-- lint disable maximum-heading-length -->
225+
226+
#### stdlib_strided_zcartesian_square_ndarray( N, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut )
227+
228+
<!-- lint enable maximum-heading-length -->
229+
230+
Computes the Cartesian square for a double-precision complex floating-point strided array using alternative indexing semantics.
231+
232+
```c
233+
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
234+
double out[ 16 ];
235+
236+
stdlib_strided_zcartesian_square_ndarray( 2, (const stdlib_complex128_t *)x, 1, 0, (stdlib_complex128_t *)out, 2, 1, 0 );
237+
```
238+
239+
The function accepts the following arguments:
240+
241+
- **N**: `[in] CBLAS_INT` number of indexed elements.
242+
- **X**: `[in] stdlib_complex128_t*` input array.
243+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
244+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
245+
- **Out**: `[out] stdlib_complex128_t*` output array.
246+
- **strideOut1**: `[in] CBLAS_INT` stride length for the first dimension of `Out`.
247+
- **strideOut2**: `[in] CBLAS_INT` stride length for the second dimension of `Out`.
248+
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
249+
250+
```c
251+
void stdlib_strided_zcartesian_square_ndarray( const CBLAS_INT N, const stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, stdlib_complex128_t *Out, const CBLAS_INT strideOut1, const CBLAS_INT strideOut2, const CBLAS_INT offsetOut );
252+
```
253+
254+
</section>
255+
256+
<!-- /.usage -->
257+
258+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
259+
260+
<section class="notes">
261+
262+
</section>
263+
264+
<!-- /.notes -->
265+
266+
<!-- C API usage examples. -->
267+
268+
<section class="examples">
269+
270+
### Examples
271+
272+
```c
273+
#include "stdlib/blas/ext/base/zcartesiansquare.h"
274+
#include "stdlib/complex/float64/ctor.h"
275+
#include "stdlib/blas/base/shared.h"
276+
#include <stdio.h>
277+
278+
int main( void ) {
279+
// Create a strided array of interleaved real and imaginary components:
280+
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
281+
282+
// Specify the number of indexed elements:
283+
const int N = 2;
284+
285+
// Create an output array (N*N pairs, each pair has 2 elements):
286+
double out[ 16 ];
287+
288+
// Specify strides:
289+
const int strideX = 1;
290+
const int LDO = 2;
291+
292+
// Compute the Cartesian square:
293+
stdlib_strided_zcartesian_square( CblasRowMajor, N, (const stdlib_complex128_t *)x, strideX, (stdlib_complex128_t *)out, LDO );
294+
295+
// Print the result:
296+
for ( int i = 0; i < N*N; i++ ) {
297+
printf( "out[ %i ] = ( %lf+%lfi, %lf+%lfi )\n", i, out[ i*4 ], out[ (i*4)+1 ], out[ (i*4)+2 ], out[ (i*4)+3 ] );
298+
}
299+
}
300+
```
301+
302+
</section>
303+
304+
<!-- /.examples -->
305+
306+
</section>
307+
308+
<!-- /.c -->
309+
310+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
311+
312+
<section class="related">
313+
314+
</section>
315+
316+
<!-- /.related -->
317+
318+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
319+
320+
<section class="links">
321+
322+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
323+
324+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
325+
326+
</section>
327+
328+
<!-- /.links -->

0 commit comments

Comments
 (0)