Reinterpret a complex-valued floating-point ndarray as a real-valued floating-point ndarray having the same precision.
var reinterpretComplex = require( '@stdlib/ndarray/base/reinterpret-complex' );Reinterprets a complex-valued floating-point ndarray as a real-valued floating-point ndarray having the same precision.
var zeroTo = require( '@stdlib/blas/ext/zero-to' );
var x = zeroTo( [ 2, 2 ], {
'dtype': 'complex128'
});
// returns <ndarray>[ [ <Complex128>[ 0.0, 0.0 ], <Complex128>[ 1.0, 0.0 ] ], [ <Complex128>[ 0.0, 0.0 ], <Complex128>[ 1.0, 0.0 ] ] ]
var out = reinterpretComplex( x );
// returns <ndarray>[ [ [ 0.0, 0.0 ], [ 1.0, 0.0 ] ], [ [ 0.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 zeroTo = require( '@stdlib/blas/ext/zero-to' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var reinterpretComplex = require( '@stdlib/ndarray/base/reinterpret-complex' );
// Create a double-precision complex floating-point ndarray:
var x = zeroTo( [ 2, 2 ], {
'dtype': 'complex128'
});
// Reinterpret as a double-precision floating-point ndarray:
var out = reinterpretComplex( x );
console.log( ndarray2array( out ) );