Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

csscal

Scale a single-precision complex floating-point vector by a single-precision floating-point constant.

Usage

var csscal = require( '@stdlib/blas/base/csscal' );

csscal( N, alpha, x, strideX )

Scales a single-precision complex floating-point vector by a single-precision floating-point constant.

var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );

csscal( 3, 2.0, x, 1 );
// x => <Complex64Array>[ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ]

The function has the following parameters:

  • N: number of indexed elements.
  • alpha: scalar constant.
  • x: input Complex64Array.
  • strideX: stride length for x.

The N and stride parameters determine which elements in x are scaled by alpha. For example, to scale every other element in x by alpha,

var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );

csscal( 2, 2.0, x, 2 );
// x => <Complex64Array>[ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ]

Note that indexing is relative to the first index. To introduce an offset, use typed array views.

var Complex64Array = require( '@stdlib/array/complex64' );

// Initial array:
var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );

// Create an offset view:
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Scale every element in `x1`:
csscal( 3, 2.0, x1, 1 );
// x0 => <Complex64Array>[ 1.0, 2.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0 ]

csscal.ndarray( N, alpha, x, strideX, offsetX )

Scales a single-precision complex floating-point vector by a single-precision floating-point constant using alternative indexing semantics.

var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );

csscal.ndarray( 3, 2.0, x, 1, 0 );
// x => <Complex64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]

The function has the following additional parameters:

  • offsetX: starting index for x.

While 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 scale every other element in the input strided array starting from the second element,

var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );

csscal.ndarray( 2, 2.0, x, 2, 1 );
// x => <Complex64Array>[ 1.0, 2.0, 6.0, 8.0, 5.0, 6.0, 14.0, 16.0 ]

Notes

  • If N <= 0, both functions return x unchanged.
  • csscal() corresponds to the BLAS level 1 function csscal.

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var csscal = require( '@stdlib/blas/base/csscal' );

function rand() {
    return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.toString() );

csscal( x.length, 2.0, x, 1 );
console.log( x.toString() );