Skip to content

Commit 68d2365

Browse files
ShabiShett07kgrytestdlib-bot
authored
feat: add C and Fortran implementation for blas/base/zdscal
PR-URL: #7086 Ref: #2039 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Reviewed-by: Aman Bhansali <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent c60545c commit 68d2365

29 files changed

+3287
-4
lines changed

lib/node_modules/@stdlib/blas/base/zdscal/README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,150 @@ console.log( x.toString() );
149149

150150
<!-- /.examples -->
151151

152+
<!-- C interface documentation. -->
153+
154+
* * *
155+
156+
<section class="c">
157+
158+
## C APIs
159+
160+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
161+
162+
<section class="intro">
163+
164+
</section>
165+
166+
<!-- /.intro -->
167+
168+
<!-- C usage documentation. -->
169+
170+
<section class="usage">
171+
172+
### Usage
173+
174+
```c
175+
#include "stdlib/blas/base/zdscal.h"
176+
```
177+
178+
#### c_zdscal( N, alpha, \*X, strideX )
179+
180+
Scales a double-precision complex floating-point vector by a double-precision floating-point constant.
181+
182+
```c
183+
#include "stdlib/complex/float64/ctor.h"
184+
185+
stdlib_complex128_t x[] = {
186+
stdlib_complex128( 1.0, 2.0 ),
187+
stdlib_complex128( 3.0, 4.0 ),
188+
stdlib_complex128( 5.0, 6.0 )
189+
};
190+
191+
c_zdscal( 3, 2.0, x, 1 );
192+
```
193+
194+
The function accepts the following arguments:
195+
196+
- **N**: `[in] CBLAS_INT` number of indexed elements.
197+
- **alpha**: `[in] double` scalar constant.
198+
- **X**: `[inout] stdlib_complex128_t*` input array.
199+
- **strideX**: `[in] CBLAS_INT` index increment for `x`.
200+
201+
```c
202+
void c_zdscal( const CBLAS_INT N, const double alpha, void *X, const CBLAS_INT strideX );
203+
```
204+
205+
#### c_zdscal_ndarray( N, alpha, \*X, strideX, offsetX )
206+
207+
Scales a double-precision complex floating-point vector by a double-precision floating-point constant using alternative indexing semantics.
208+
209+
```c
210+
#include "stdlib/complex/float64/ctor.h"
211+
212+
stdlib_complex128_t x[] = {
213+
stdlib_complex128( 1.0, 2.0 ),
214+
stdlib_complex128( 3.0, 4.0 ),
215+
stdlib_complex128( 5.0, 6.0 )
216+
};
217+
218+
c_zdscal_ndarray( 3, 2.0, x, 1, 0 );
219+
```
220+
221+
The function accepts the following arguments:
222+
223+
- **N**: `[in] CBLAS_INT` number of indexed elements.
224+
- **alpha**: `[in] double` scalar constant.
225+
- **X**: `[inout] void*` input array.
226+
- **strideX**: `[in] CBLAS_INT` index increment for `x`.
227+
- **offsetX**: `[in] CBLAS_INT` starting index for `x`.
228+
229+
```c
230+
void c_zdscal_ndarray( const CBLAS_INT N, const double alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
231+
```
232+
233+
</section>
234+
235+
<!-- /.usage -->
236+
237+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
238+
239+
<section class="notes">
240+
241+
</section>
242+
243+
<!-- /.notes -->
244+
245+
<!-- C API usage examples. -->
246+
247+
<section class="examples">
248+
249+
### Examples
250+
251+
```c
252+
#include "stdlib/blas/base/zdscal.h"
253+
#include "stdlib/complex/float64/ctor.h"
254+
#include "stdlib/complex/float64/real.h"
255+
#include "stdlib/complex/float64/imag.h"
256+
#include <stdio.h>
257+
258+
int main( void ) {
259+
stdlib_complex128_t x[] = {
260+
stdlib_complex128( 1.0, 2.0 ),
261+
stdlib_complex128( 3.0, 4.0 ),
262+
stdlib_complex128( 5.0, 6.0 ),
263+
stdlib_complex128( 7.0, 8.0 )
264+
};
265+
266+
// Specify the number of elements:
267+
const int N = 4;
268+
269+
// Specify the stride length:
270+
const int strideX = 1;
271+
272+
c_zdscal( N, 2.0, (void *)x, strideX );
273+
274+
// Print the result:
275+
for ( int i = 0; i < N; i++ ) {
276+
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
277+
}
278+
279+
c_zdscal_ndarray( N, 2.0, (void *)x, strideX, 0 );
280+
281+
// Print the result:
282+
for ( int i = 0; i < N; i++ ) {
283+
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
284+
}
285+
}
286+
```
287+
288+
</section>
289+
290+
<!-- /.examples -->
291+
292+
</section>
293+
294+
<!-- /.c -->
295+
152296
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
153297
154298
<section class="related">
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var zdscal = tryRequire( resolve( __dirname, './../lib/zdscal.native.js' ) );
37+
var opts = {
38+
'skip': ( zdscal instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
var x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );
56+
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var viewX;
67+
var i;
68+
69+
viewX = reinterpret( x, 0 );
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
zdscal( x.length, 2.0, x, 1 );
73+
if ( isnan( viewX[ i%(len*2) ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( viewX[ i%(len*2) ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = pow( 10, i );
106+
f = createBenchmark( len );
107+
bench( pkg+'::native:len='+len, opts, f );
108+
}
109+
}
110+
111+
main();
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var zdscal = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
37+
var opts = {
38+
'skip': ( zdscal instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
var x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );
56+
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var viewX;
67+
var i;
68+
69+
viewX = reinterpret( x, 0 );
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
zdscal( x.length, 2.0, x, 1, 0 );
73+
if ( isnan( viewX[ i%(len*2) ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
}
77+
b.toc();
78+
if ( isnan( viewX[ i%(len*2) ] ) ) {
79+
b.fail( 'should not return NaN' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
}
84+
}
85+
86+
87+
// MAIN //
88+
89+
/**
90+
* Main execution sequence.
91+
*
92+
* @private
93+
*/
94+
function main() {
95+
var len;
96+
var min;
97+
var max;
98+
var f;
99+
var i;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( i = min; i <= max; i++ ) {
105+
len = pow( 10, i );
106+
f = createBenchmark( len );
107+
bench( pkg+'::native:ndarray:len='+len, opts, f );
108+
}
109+
}
110+
111+
main();

0 commit comments

Comments
 (0)