Skip to content

Commit 60cf0fb

Browse files
committed
feat: add blas/ext/base/zunitspace
--- 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 c1d72a0 commit 60cf0fb

33 files changed

Lines changed: 3720 additions & 0 deletions
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
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+
# zunitspace
22+
23+
> Fill a double-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from a specified value.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zunitspace = require( '@stdlib/blas/ext/base/zunitspace' );
31+
```
32+
33+
#### zunitspace( N, start, x, strideX )
34+
35+
Fills a double-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from a specified value.
36+
37+
```javascript
38+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
39+
var Complex128Array = require( '@stdlib/array/complex128' );
40+
41+
var x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
42+
43+
zunitspace( x.length, new Complex128( 3.0, 0.0 ), x, 1 );
44+
// x => <Complex128Array>[ 3.0, 0.0, 4.0, 0.0, 5.0, 0.0, 6.0, 0.0 ]
45+
```
46+
47+
The function has the following parameters:
48+
49+
- **N**: number of indexed elements.
50+
- **start**: starting [`Complex128`][@stdlib/complex/float64/ctor] value.
51+
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
52+
- **strideX**: stride length.
53+
54+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element:
55+
56+
<!-- eslint-disable max-len -->
57+
58+
```javascript
59+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
60+
var Complex128Array = require( '@stdlib/array/complex128' );
61+
62+
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
63+
64+
zunitspace( 3, new Complex128( 3.0, 0.0 ), x, 2 );
65+
// x => <Complex128Array>[ 3.0, 0.0, 3.0, 4.0, 4.0, 0.0, 7.0, 8.0, 5.0, 0.0, 11.0, 12.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+
<!-- eslint-disable max-len -->
71+
72+
```javascript
73+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
74+
var Complex128Array = require( '@stdlib/array/complex128' );
75+
76+
// Initial array...
77+
var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
78+
79+
// Create an offset view...
80+
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
81+
82+
// Fill every other element...
83+
zunitspace( 3, new Complex128( 3.0, 0.0 ), x1, 2 );
84+
// x0 => <Complex128Array>[ 1.0, 2.0, 3.0, 0.0, 5.0, 6.0, 4.0, 0.0, 9.0, 10.0, 5.0, 0.0 ]
85+
```
86+
87+
#### zunitspace.ndarray( N, start, x, strideX, offsetX )
88+
89+
Fills a double-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from a specified value using alternative indexing semantics.
90+
91+
```javascript
92+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
93+
var Complex128Array = require( '@stdlib/array/complex128' );
94+
95+
var x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
96+
97+
zunitspace.ndarray( x.length, new Complex128( 3.0, 0.0 ), x, 1, 0 );
98+
// x => <Complex128Array>[ 3.0, 0.0, 4.0, 0.0, 5.0, 0.0, 6.0, 0.0 ]
99+
```
100+
101+
The function has the following additional parameters:
102+
103+
- **offsetX**: starting index.
104+
105+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements:
106+
107+
<!-- eslint-disable max-len -->
108+
109+
```javascript
110+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
111+
var Complex128Array = require( '@stdlib/array/complex128' );
112+
113+
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
114+
115+
zunitspace.ndarray( 3, new Complex128( 3.0, 0.0 ), x, 1, x.length-3 );
116+
// x => <Complex128Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 3.0, 0.0, 4.0, 0.0, 5.0, 0.0 ]
117+
```
118+
119+
</section>
120+
121+
<!-- /.usage -->
122+
123+
<section class="notes">
124+
125+
## Notes
126+
127+
- If `N <= 0`, both functions return `x` unchanged.
128+
129+
</section>
130+
131+
<!-- /.notes -->
132+
133+
<section class="examples">
134+
135+
## Examples
136+
137+
<!-- eslint no-undef: "error" -->
138+
139+
```javascript
140+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
141+
var Complex128Array = require( '@stdlib/array/complex128' );
142+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
143+
var zunitspace = require( '@stdlib/blas/ext/base/zunitspace' );
144+
145+
var xbuf = discreteUniform( 20, -100, 100, {
146+
'dtype': 'float64'
147+
});
148+
var x = new Complex128Array( xbuf.buffer );
149+
console.log( x );
150+
151+
zunitspace( x.length, new Complex128( 3.0, 0.0 ), x, 1 );
152+
console.log( x );
153+
```
154+
155+
</section>
156+
157+
<!-- /.examples -->
158+
159+
<!-- C interface documentation. -->
160+
161+
* * *
162+
163+
<section class="c">
164+
165+
## C APIs
166+
167+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
168+
169+
<section class="intro">
170+
171+
</section>
172+
173+
<!-- /.intro -->
174+
175+
<!-- C usage documentation. -->
176+
177+
<section class="usage">
178+
179+
### Usage
180+
181+
```c
182+
#include "stdlib/blas/ext/base/zunitspace.h"
183+
```
184+
185+
#### stdlib_strided_zunitspace( N, start, \*X, strideX )
186+
187+
Fills a double-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from a specified value.
188+
189+
```c
190+
#include "stdlib/complex/float64/ctor.h"
191+
192+
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
193+
194+
const stdlib_complex128_t start = stdlib_complex128( 3.0, 0.0 );
195+
196+
stdlib_strided_zunitspace( 4, start, (stdlib_complex128_t *)x, 1 );
197+
```
198+
199+
The function accepts the following arguments:
200+
201+
- **N**: `[in] CBLAS_INT` number of indexed elements.
202+
- **start**: `[in] stdlib_complex128_t` starting value.
203+
- **X**: `[out] stdlib_complex128_t*` input array.
204+
- **strideX**: `[in] CBLAS_INT` stride length.
205+
206+
```c
207+
void API_SUFFIX(stdlib_strided_zunitspace)( const CBLAS_INT N, const stdlib_complex128_t start, stdlib_complex128_t *X, const CBLAS_INT strideX );
208+
```
209+
210+
#### stdlib_strided_zunitspace_ndarray( N, start, \*X, strideX, offsetX )
211+
212+
Fills a double-precision complex floating-point strided array with linearly spaced numeric elements which increment by `1` starting from a specified value using alternative indexing semantics.
213+
214+
```c
215+
#include "stdlib/complex/float64/ctor.h"
216+
217+
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
218+
219+
const stdlib_complex128_t start = stdlib_complex128( 3.0, 0.0 );
220+
221+
stdlib_strided_zunitspace_ndarray( 4, start, (stdlib_complex128_t *)x, 1, 0 );
222+
```
223+
224+
The function accepts the following arguments:
225+
226+
- **N**: `[in] CBLAS_INT` number of indexed elements.
227+
- **start**: `[in] stdlib_complex128_t` starting value.
228+
- **X**: `[out] stdlib_complex128_t*` input array.
229+
- **strideX**: `[in] CBLAS_INT` stride length.
230+
- **offsetX**: `[in] CBLAS_INT` starting index.
231+
232+
```c
233+
void API_SUFFIX(stdlib_strided_zunitspace_ndarray)( const CBLAS_INT N, const stdlib_complex128_t start, stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
234+
```
235+
236+
</section>
237+
238+
<!-- /.usage -->
239+
240+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
241+
242+
<section class="notes">
243+
244+
</section>
245+
246+
<!-- /.notes -->
247+
248+
<!-- C API usage examples. -->
249+
250+
<section class="examples">
251+
252+
### Examples
253+
254+
```c
255+
#include "stdlib/blas/ext/base/zunitspace.h"
256+
#include "stdlib/complex/float64/ctor.h"
257+
#include <stdio.h>
258+
259+
int main( void ) {
260+
// Create a strided array of interleaved real and imaginary components:
261+
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
262+
263+
// Specify the number of elements:
264+
const int N = 4;
265+
266+
// Specify a stride:
267+
const int strideX = 1;
268+
269+
// Specify a starting value:
270+
const stdlib_complex128_t start = stdlib_complex128( 3.0, 0.0 );
271+
272+
// Fill the array:
273+
stdlib_strided_zunitspace( N, start, (stdlib_complex128_t *)x, strideX );
274+
275+
// Print the result:
276+
for ( int i = 0; i < 8; i++ ) {
277+
printf( "x[ %i ] = %lf\n", i, x[ i ] );
278+
}
279+
}
280+
```
281+
282+
</section>
283+
284+
<!-- /.examples -->
285+
286+
</section>
287+
288+
<!-- /.c -->
289+
290+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
291+
292+
<section class="related">
293+
294+
</section>
295+
296+
<!-- /.related -->
297+
298+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
299+
300+
<section class="links">
301+
302+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
303+
304+
[@stdlib/complex/float64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/ctor
305+
306+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
307+
308+
</section>
309+
310+
<!-- /.links -->

0 commit comments

Comments
 (0)