Skip to content

Commit c97212e

Browse files
committed
refactor: avoid complex number instantiation
--- 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: na - task: lint_package_json status: na - 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: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 305beea commit c97212e

File tree

7 files changed

+187
-178
lines changed

7 files changed

+187
-178
lines changed

lib/node_modules/@stdlib/blas/base/zscal/lib/index.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,24 @@
2626
* @example
2727
* var Complex128Array = require( '@stdlib/array/complex128' );
2828
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
29-
* var real = require( '@stdlib/complex/float64/real' );
30-
* var imag = require( '@stdlib/complex/float64/imag' );
3129
* var zscal = require( '@stdlib/blas/base/zscal' );
3230
*
3331
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
3432
* var za = new Complex128( 2.0, 2.0 );
3533
*
3634
* zscal( 3, za, zx, 1 );
37-
*
38-
* var z = zx.get( 0 );
39-
* // returns <Complex128>
40-
*
41-
* var re = real( z );
42-
* // returns -2.0
43-
*
44-
* var im = imag( z );
45-
* // returns 6.0
35+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
4636
*
4737
* @example
4838
* var Complex128Array = require( '@stdlib/array/complex128' );
4939
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
50-
* var real = require( '@stdlib/complex/float64/real' );
51-
* var imag = require( '@stdlib/complex/float64/imag' );
5240
* var zscal = require( '@stdlib/blas/base/zscal' );
5341
*
5442
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
5543
* var za = new Complex128( 2.0, 2.0 );
5644
*
57-
* zscal.ndarray( 3, za zx, 1, 0 );
58-
*
59-
* var z = zx.get( 0 );
60-
* // returns <Complex128>
61-
*
62-
* var re = real( z );
63-
* // returns -2.0
64-
*
65-
* var im = imag( z );
66-
* // returns 6.0
45+
* zscal.ndarray( 3, za, zx, 1 );
46+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
6747
*/
6848

6949
// MODULES //

lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
// MODULES //
2222

23-
var cmul = require( '@stdlib/complex/float64/base/mul' );
23+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
24+
var cmul = require( '@stdlib/complex/float64/base/mul' ).assign;
25+
var real = require( '@stdlib/complex/float64/real' );
26+
var imag = require( '@stdlib/complex/float64/imag' );
2427

2528

2629
// MAIN //
@@ -31,41 +34,49 @@ var cmul = require( '@stdlib/complex/float64/base/mul' );
3134
* @param {PositiveInteger} N - number of indexed elements
3235
* @param {Complex128} za - constant
3336
* @param {Complex128Array} zx - input array
34-
* @param {integer} strideX - `zx` stride length
35-
* @param {NonNegativeInteger} offsetX - starting `zx` index
37+
* @param {integer} strideZX - `zx` stride length
38+
* @param {NonNegativeInteger} offsetZX - starting `zx` index
3639
* @returns {Complex128Array} input array
3740
*
3841
* @example
3942
* var Complex128Array = require( '@stdlib/array/complex128' );
4043
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
41-
* var real = require( '@stdlib/complex/float64/real' );
42-
* var imag = require( '@stdlib/complex/float64/imag' );
4344
*
4445
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4546
* var za = new Complex128( 2.0, 2.0 );
4647
*
4748
* zscal( 3, za, zx, 1, 0 );
48-
*
49-
* var z = zx.get( 0 );
50-
* // returns <Complex128>
51-
*
52-
* var re = real( z );
53-
* // returns -2.0
54-
*
55-
* var im = imag( z );
56-
* // returns 6.0
49+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
5750
*/
58-
function zscal( N, za, zx, strideX, offsetX ) {
51+
function zscal( N, za, zx, strideZX, offsetZX ) {
52+
var view;
53+
var re1;
54+
var im1;
55+
var re2;
56+
var im2;
57+
var sx;
5958
var ix;
6059
var i;
6160

62-
if ( N <= 0 || strideX <= 0 ) {
61+
if ( N <= 0 ) {
6362
return zx;
6463
}
65-
ix = offsetX;
64+
// Reinterpret the input array as a real-valued array of interleaved real and imaginary components:
65+
view = reinterpret( zx, 0 );
66+
67+
// Adjust the stride and offset:
68+
sx = strideZX * 2;
69+
ix = offsetZX * 2;
70+
71+
// Decompose the input scalar to real and imaginary components:
72+
re1 = real( za );
73+
im1 = imag( za );
74+
6675
for ( i = 0; i < N; i++ ) {
67-
zx.set( cmul( za, zx.get( ix ) ), ix );
68-
ix += strideX;
76+
re2 = view[ ix ];
77+
im2 = view[ ix+1 ];
78+
cmul( re1, im1, re2, im2, view, 1, ix );
79+
ix += sx;
6980
}
7081
return zx;
7182
}

lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.native.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,25 @@ var addon = require( './../src/addon.node' );
3333
* @param {PositiveInteger} N - number of indexed elements
3434
* @param {Complex128} za - scalar constant
3535
* @param {Complex128Array} zx - input array
36-
* @param {integer} strideX - `zx` stride length
37-
* @param {NonNegativeInteger} offsetX - starting `zx` index
36+
* @param {integer} strideZX - `zx` stride length
37+
* @param {NonNegativeInteger} offsetZX - starting `zx` index
3838
* @returns {Complex128Array} input array
3939
*
4040
* @example
4141
* var Complex128Array = require( '@stdlib/array/complex128' );
4242
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
43-
* var real = require( '@stdlib/complex/float64/real' );
44-
* var imag = require( '@stdlib/complex/float64/imag' );
4543
*
4644
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4745
* var za = new Complex128( 2.0, 2.0 );
4846
*
49-
* zscal( zx.length, za, zx, 1, 0 );
50-
*
51-
* var z = zx.get( 0 );
52-
* // returns <Complex128>
53-
*
54-
* var re = real( z );
55-
* // returns -2.0
56-
*
57-
* var im = imag( z );
58-
* // returns 6.0
47+
* zscal( 3, za, zx, 1, 0 );
48+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
5949
*/
60-
function zscal( N, za, zx, strideX, offsetX ) {
50+
function zscal( N, za, zx, strideZX, offsetZX ) {
6151
var viewZX;
62-
offsetX = minViewBufferIndex( N, strideX, offsetX );
63-
viewZX = reinterpret( zx, offsetX );
64-
addon( N, za, viewZX, strideX );
52+
offsetZX = minViewBufferIndex( N, strideZX, offsetZX );
53+
viewZX = reinterpret( zx, offsetZX );
54+
addon( N, za, viewZX, strideZX );
6555
return zx;
6656
}
6757

lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.js

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// MODULES //
2222

23-
var cmul = require( '@stdlib/complex/float64/base/mul' );
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
24+
var ndarray = require( './ndarray.js' );
2425

2526

2627
// MAIN //
@@ -31,50 +32,21 @@ var cmul = require( '@stdlib/complex/float64/base/mul' );
3132
* @param {PositiveInteger} N - number of indexed elements
3233
* @param {Complex128} za - constant
3334
* @param {Complex128Array} zx - input array
34-
* @param {integer} strideX - `zx` stride length
35+
* @param {integer} strideZX - `zx` stride length
3536
* @returns {Complex128Array} input array
3637
*
3738
* @example
3839
* var Complex128Array = require( '@stdlib/array/complex128' );
3940
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
40-
* var real = require( '@stdlib/complex/float64/real' );
41-
* var imag = require( '@stdlib/complex/float64/imag' );
4241
*
4342
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4443
* var za = new Complex128( 2.0, 2.0 );
4544
*
4645
* zscal( 3, za, zx, 1 );
47-
*
48-
* var z = zx.get( 0 );
49-
* // returns <Complex128>
50-
*
51-
* var re = real( z );
52-
* // returns -2.0
53-
*
54-
* var im = imag( z );
55-
* // returns 6.0
46+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
5647
*/
57-
function zscal( N, za, zx, strideX ) {
58-
var ix;
59-
var i;
60-
61-
if ( N <= 0 || strideX <= 0 ) {
62-
return zx;
63-
}
64-
if ( strideX === 1 ) {
65-
// Code for stride equal to `1`...
66-
for ( i = 0; i < N; i++ ) {
67-
zx.set( cmul( za, zx.get( i ) ), i );
68-
}
69-
return zx;
70-
}
71-
// Code for stride not equal to `1`...
72-
ix = 0;
73-
for ( i = 0; i < N; i++ ) {
74-
zx.set( cmul( za, zx.get( ix ) ), ix );
75-
ix += strideX;
76-
}
77-
return zx;
48+
function zscal( N, za, zx, strideZX ) {
49+
return ndarray( N, za, zx, strideZX, stride2offset( N, strideZX ) );
7850
}
7951

8052

lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.native.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,22 @@ var addon = require( './../src/addon.node' );
3232
* @param {PositiveInteger} N - number of indexed elements
3333
* @param {Complex128} za - scalar constant
3434
* @param {Complex128Array} zx - input array
35-
* @param {integer} strideX - `zx` stride length
35+
* @param {integer} strideZX - `zx` stride length
3636
* @returns {Complex128Array} input array
3737
*
3838
* @example
3939
* var Complex128Array = require( '@stdlib/array/complex128' );
4040
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
41-
* var real = require( '@stdlib/complex/float64/real' );
42-
* var imag = require( '@stdlib/complex/float64/imag' );
4341
*
4442
* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4543
* var za = new Complex128( 2.0, 2.0 );
4644
*
47-
* zscal( zx.length, za, zx, 1 );
48-
*
49-
* var z = zx.get( 0 );
50-
* // returns <Complex128>
51-
*
52-
* var re = real( z );
53-
* // returns -2.0
54-
*
55-
* var im = imag( z );
56-
* // returns 6.0
45+
* zscal( 3, za, zx, 1 );
46+
* // zx => <Complex128Array>[ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ]
5747
*/
58-
function zscal( N, za, zx, strideX ) {
48+
function zscal( N, za, zx, strideZX ) {
5949
var viewZX = reinterpret( zx, 0 );
60-
addon( N, za, viewZX, strideX );
50+
addon( N, za, viewZX, strideZX );
6151
return zx;
6252
}
6353

0 commit comments

Comments
 (0)