Skip to content

Commit 0dc7cda

Browse files
committed
chore: add implementation
--- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0538961 commit 0dc7cda

28 files changed

+3043
-5
lines changed

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

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,136 @@ console.log( zx.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[] = { stdlib_complex128( 1.0, 2.0 ), stdlib_complex128( 3.0, 4.0 ), stdlib_complex128( 5.0, 6.0 ) }; // interleaved real and imaginary components
186+
187+
c_zdscal( 3, 2.0, x, 1 );
188+
```
189+
190+
The function accepts the following arguments:
191+
192+
- **N**: `[in] CBLAS_INT` number of indexed elements.
193+
- **alpha**: `[in] double` constant.
194+
- **x**: `[inout] stdlib_complex128_t*` input array.
195+
- **strideX**: `[in] CBLAS_INT` index increment for `x`.
196+
197+
```c
198+
void c_zdscal( const CBLAS_INT N, const double alpha, stdlib_complex128_t *X, const CBLAS_INT strideX );
199+
```
200+
201+
#### c_zdscal_ndarray( N, alpha, \*X, strideX, offsetX )
202+
203+
Scales a double-precision complex floating-point vector by a double-precision floating-point constant using alternative indexing semantics.
204+
205+
```c
206+
stdlib_complex128_t x[] = { stdlib_complex128( 1.0, 2.0 ), stdlib_complex128( 3.0, 4.0 ), stdlib_complex128( 5.0, 6.0 ) }; // interleaved real and imaginary components
207+
208+
c_zdscal_ndarray( 3, 2.0, x, 1, 0 );
209+
```
210+
211+
The function accepts the following arguments:
212+
213+
- **N**: `[in] CBLAS_INT` number of indexed elements.
214+
- **alpha**: `[in] double` constant.
215+
- **x**: `[inout] void*` input array.
216+
- **strideX**: `[in] CBLAS_INT` index increment for `x`.
217+
- **offsetX**: `[in] CBLAS_INT` starting index for `x`.
218+
219+
```c
220+
void c_zdscal_ndarray( const CBLAS_INT N, const double alpha, stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
221+
```
222+
223+
</section>
224+
225+
<!-- /.usage -->
226+
227+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
228+
229+
<section class="notes">
230+
231+
</section>
232+
233+
<!-- /.notes -->
234+
235+
<!-- C API usage examples. -->
236+
237+
<section class="examples">
238+
239+
### Examples
240+
241+
```c
242+
#include "stdlib/blas/base/zdscal.h"
243+
#include "stdlib/complex/float64/ctor.h"
244+
#include "stdlib/complex/float64/real.h"
245+
#include "stdlib/complex/float64/imag.h"
246+
#include <stdio.h>
247+
248+
int main( void ) {
249+
// Create strided arrays:
250+
stdlib_complex128_t x[] = { stdlib_complex128( 1.0, 2.0 ), stdlib_complex128( 3.0, 4.0 ), stdlib_complex128( 5.0, 6.0 ), stdlib_complex128( 7.0, 8.0 ) };
251+
252+
// Specify the number of elements:
253+
const int N = 4;
254+
255+
// Specify stride lengths:
256+
const int strideX = 1;
257+
258+
c_zdscal( N, 2.0, (void *)x, strideX );
259+
260+
// Print the result:
261+
for ( int i = 0; i < N; i++ ) {
262+
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
263+
}
264+
265+
c_zdscal_ndarray( N, 2.0, (void *)x, strideX, 0 );
266+
267+
// Print the result:
268+
for ( int i = 0; i < N; i++ ) {
269+
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
270+
}
271+
}
272+
```
273+
274+
</section>
275+
276+
<!-- /.examples -->
277+
278+
</section>
279+
280+
<!-- /.c -->
281+
152282
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
153283
154284
<section class="related">
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 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;
56+
57+
x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );
58+
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var viewX;
69+
var i;
70+
71+
viewX = reinterpret( x, 0 );
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
zdscal( x.length, 2.0, x, 1 );
75+
if ( isnan( viewX[ i%(len*2) ] ) ) {
76+
b.fail( 'should not return NaN' );
77+
}
78+
}
79+
b.toc();
80+
if ( isnan( viewX[ i%(len*2) ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( pkg+'::native:len='+len, opts, f );
110+
}
111+
}
112+
113+
main();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 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;
56+
57+
x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );
58+
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var viewX;
69+
var i;
70+
71+
viewX = reinterpret( x, 0 );
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
zdscal( x.length, 2.0, x, 1, 0 );
75+
if ( isnan( viewX[ i%(len*2) ] ) ) {
76+
b.fail( 'should not return NaN' );
77+
}
78+
}
79+
b.toc();
80+
if ( isnan( viewX[ i%(len*2) ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( pkg+'::native:ndarray:len='+len, opts, f );
110+
}
111+
}
112+
113+
main();

0 commit comments

Comments
 (0)