Reinterpret a double-precision complex floating-point ndarray as a real-valued double-precision floating-point ndarray containing interleaved real and imaginary components.
var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' );Reinterprets a double-precision complex floating-point ndarray as a real-valued double-precision floating-point ndarray containing interleaved real and imaginary components.
var ones = require( '@stdlib/ndarray/base/ones' );
var x = ones( 'complex128', [ 2, 2 ], 'row-major' );
// returns <ndarray>[ [ <Complex128>[ 1.0, 0.0 ], <Complex128>[ 1.0, 0.0 ] ], [ <Complex128>[ 1.0, 0.0 ], <Complex128>[ 1.0, 0.0 ] ] ]
var out = reinterpretComplex128( x );
// returns <ndarray>[ [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 1.0, 0.0 ], [ 1.0, 0.0 ] ] ]- The returned ndarray is a view on the input ndarray data buffer.
- The returned ndarray has an additional trailing dimension of size two whose elements correspond to the real and imaginary components, respectively, of each complex-valued element in the input ndarray.
- The returned ndarray is a "base" ndarray, and, thus, the returned ndarray does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to reinterpret an ndarray-like object within internal implementations and to do so with minimal overhead.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Complex128Array = require( '@stdlib/array/complex128' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var reinterpretComplex128 = require( '@stdlib/ndarray/base/reinterpret-complex128' );
// Create a double-precision complex floating-point ndarray:
var buf = new Complex128Array( discreteUniform( 8, -5, 5 ) );
var x = ndarray( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
// Reinterpret as a double-precision floating-point ndarray:
var out = reinterpretComplex128( x );
console.log( ndarray2array( out ) );