UNPKG

@stdlib/strided

Version:
158 lines (96 loc) 3.69 kB
<!-- @license Apache-2.0 Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> # reinterpret > Reinterpret a complex-valued floating-point array as a real-valued floating-point array having the same precision. <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> <section class="intro"> </section> <!-- /.intro --> <!-- Package usage documentation. --> <section class="usage"> ## Usage ```javascript var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' ); ``` #### reinterpret( x, offset ) Returns a real-valued floating-point array view of a complex-valued floating-point array. ```javascript var Complex128Array = require( '@stdlib/array/complex128' ); var x = new Complex128Array( 10 ); var view = reinterpret( x, 0 ); // returns <Float64Array> var bool = ( view.buffer === x.buffer ); // returns true var len = view.length; // returns 20 ``` The `offset` argument specifies the starting index of the returned real-valued floating-point array view relative to the input array. ```javascript 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 ] ); var view = reinterpret( x, 2 ); // returns <Float32Array> var len = view.length; // returns 4 var re = view[ 0 ]; // returns 5.0 var im = view[ 1 ]; // returns 6.0 ``` </section> <!-- /.usage --> <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> <section class="notes"> </section> <!-- /.notes --> <!-- Package usage examples. --> <section class="examples"> ## Examples <!-- eslint no-undef: "error" --> ```javascript var Complex128Array = require( '@stdlib/array/complex128' ); var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); var reinterpret = require( '@stdlib/strided/base/reinterpret-complex' ); // Define a complex number array: var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); // returns <Complex128Array> // Reinterpret as a `float64` array: var view = reinterpret( x, 0 ); // returns <Float64Array> // Set view elements: view[ 0 ] = 9.0; view[ 1 ] = 10.0; // Get the first element of the complex number array: var z = x.get( 0 ); // returns <Complex128> var re = real( z ); // returns 9.0 var im = imag( z ); // returns 10.0 ``` </section> <!-- /.examples --> <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> <section class="references"> </section> <!-- /.references --> <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> <section class="related"> </section> <!-- /.related --> <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> <section class="links"> </section> <!-- /.links -->