Skip to content

Commit 52ceaaf

Browse files
committed
feat: add /blas/base/zdscal
1 parent 8785e54 commit 52ceaaf

File tree

11 files changed

+987
-0
lines changed

11 files changed

+987
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var pkg = require( './../package.json' ).name;
29+
var zdscal = require( './../lib/zdscal.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var zxbuf;
50+
var zx;
51+
52+
zxbuf = uniform( len*2, -100.0, 100.0, options );
53+
zx = new Complex128Array( zxbuf.buffer );
54+
return benchmark;
55+
56+
/**
57+
* Benchmark function.
58+
*
59+
* @private
60+
* @param {Benchmark} b - benchmark instance
61+
*/
62+
function benchmark( b ) {
63+
var i;
64+
65+
b.tic();
66+
for ( i = 0; i < b.iterations; i++ ) {
67+
zdscal( zx.length, 1.01, zx, 1 );
68+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
}
72+
b.toc();
73+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
b.pass( 'benchmark finished' );
77+
b.end();
78+
}
79+
}
80+
81+
82+
// MAIN //
83+
84+
/**
85+
* Main execution sequence.
86+
*
87+
* @private
88+
*/
89+
function main() {
90+
var len;
91+
var min;
92+
var max;
93+
var f;
94+
var i;
95+
96+
min = 1; // 10^min
97+
max = 6; // 10^max
98+
99+
for ( i = min; i <= max; i++ ) {
100+
len = pow( 10, i );
101+
f = createBenchmark( len );
102+
bench( pkg+':len='+len, f );
103+
}
104+
}
105+
106+
main();
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var pkg = require( './../package.json' ).name;
29+
var zdscal = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var zxbuf;
50+
var zx;
51+
52+
zxbuf = uniform( len*2, -100.0, 100.0, options );
53+
zx = new Complex128Array( zxbuf.buffer );
54+
return benchmark;
55+
56+
/**
57+
* Benchmark function.
58+
*
59+
* @private
60+
* @param {Benchmark} b - benchmark instance
61+
*/
62+
function benchmark( b ) {
63+
var i;
64+
65+
b.tic();
66+
for ( i = 0; i < b.iterations; i++ ) {
67+
zdscal( zx.length, 1.01, zx, 1, 0 );
68+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
}
72+
b.toc();
73+
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
b.pass( 'benchmark finished' );
77+
b.end();
78+
}
79+
}
80+
81+
82+
// MAIN //
83+
84+
/**
85+
* Main execution sequence.
86+
*
87+
* @private
88+
*/
89+
function main() {
90+
var len;
91+
var min;
92+
var max;
93+
var f;
94+
var i;
95+
96+
min = 1; // 10^min
97+
max = 6; // 10^max
98+
99+
for ( i = min; i <= max; i++ ) {
100+
len = pow( 10, i );
101+
f = createBenchmark( len );
102+
bench( pkg+':ndarray:len='+len, f );
103+
}
104+
}
105+
106+
main();
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
{{alias}}( N, alpha, zx, strideX )
3+
Scales a double-precision complex floating-point vector by a double-
4+
precision floating-point constant.
5+
6+
The `N` and stride parameters determine how values from `zx` are scaled by
7+
`alpha`.
8+
9+
Indexing is relative to the first index. To introduce an offset, use typed
10+
array views.
11+
12+
If `N` or `strideX` is less than or equal to `0`, the function returns `zx`
13+
unchanged.
14+
15+
16+
Parameters
17+
----------
18+
N: integer
19+
Number of indexed elements.
20+
21+
alpha: Float64
22+
Complex constant.
23+
24+
zx: Complex128Array
25+
Input array.
26+
27+
strideX: integer
28+
Index increment for `zx`.
29+
30+
Returns
31+
-------
32+
zx: Complex128Array
33+
Input array.
34+
35+
Examples
36+
--------
37+
// Standard usage:
38+
> var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
39+
> {{alias}}( 2, 5.0, zx, 1 );
40+
> var z = zx.get( 0 );
41+
> var re = {{alias:@stdlib/complex/float64/real}}( z )
42+
5.0
43+
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
44+
10.0
45+
46+
// Advanced indexing:
47+
> zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
48+
> {{alias}}( 2, 5.0, zx, 2 );
49+
> z = zx.get( 0 );
50+
> re = {{alias:@stdlib/complex/float64/real}}( z )
51+
5.0
52+
> im = {{alias:@stdlib/complex/float64/imag}}( z )
53+
10.0
54+
55+
// Using typed array views:
56+
> var zx0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
57+
> var zx1 = new {{alias:@stdlib/array/complex128}}( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 );
58+
> {{alias}}( 2, 5.0, zx1, 1 );
59+
> z = zx0.get( 1 );
60+
> re = {{alias:@stdlib/complex/float64/real}}( z )
61+
15.0
62+
> im = {{alias:@stdlib/complex/float64/imag}}( z )
63+
20.0
64+
65+
66+
{{alias}}.ndarray( N, za, zx, strideX, offsetX )
67+
Scales a double-precision complex floating-point vector by a double-
68+
precision floating-point constant using alternative indexing
69+
semantics.
70+
71+
While typed array views mandate a view offset based on the underlying
72+
buffer, the offset parameter supports indexing semantics based on a starting
73+
index.
74+
75+
Parameters
76+
----------
77+
N: integer
78+
Number of indexed elements.
79+
80+
alpha: Float64
81+
Float constant.
82+
83+
zx: Complex128Array
84+
Input array.
85+
86+
strideX: integer
87+
Index increment for `zx`.
88+
89+
offsetX: integer
90+
Starting index for `zx`.
91+
92+
Returns
93+
-------
94+
zx: Complex128Array
95+
Input array.
96+
97+
Examples
98+
--------
99+
// Standard usage:
100+
> var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
101+
> {{alias}}.ndarray( 2, 5.0, zx, 1, 0 );
102+
> var z = zx.get( 0 );
103+
> var re = {{alias:@stdlib/complex/float64/real}}( z )
104+
5.0
105+
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
106+
10.0
107+
108+
// Advanced indexing:
109+
> zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
110+
> {{alias}}.ndarray( 2, 2.0, zx, 1, 2 );
111+
> z = zx.get( 2 );
112+
> re = {{alias:@stdlib/complex/float64/real}}( z )
113+
10.0
114+
> im = {{alias:@stdlib/complex/float64/imag}}( z )
115+
12.0
116+
117+
See Also
118+
--------

0 commit comments

Comments
 (0)