Skip to content

Commit 3be6d44

Browse files
committed
feat: add blas/ext/base/cxsa
--- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - 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 cf7b40a commit 3be6d44

33 files changed

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

0 commit comments

Comments
 (0)