@stdlib/strided
Version:
Strided.
177 lines (106 loc) • 4.77 kB
Markdown
<!--
@license Apache-2.0
Copyright (c) 2021 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 [`Complex128Array`][@stdlib/array/complex128] as a [`Float64Array`][@stdlib/array/float64].
<!-- 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-complex128' );
```
#### reinterpret( x, offset )
Returns a [`Float64Array`][@stdlib/array/float64] view of a [`Complex128Array`][@stdlib/array/complex128].
```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 [`Float64Array`][@stdlib/array/float64] view relative to the [`Complex128Array`][@stdlib/array/complex128].
```javascript
var Complex128Array = require( '@stdlib/array/complex128' );
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var view = reinterpret( x, 2 );
// returns <Float64Array>
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-complex128' );
// 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">
* * *
## See Also
- <span class="package-name">[`@stdlib/strided/base/reinterpret-complex`][@stdlib/strided/base/reinterpret-complex]</span><span class="delimiter">: </span><span class="description">reinterpret a complex-valued floating-point array as a real-valued floating-point array having the same precision.</span>
- <span class="package-name">[`@stdlib/strided/base/reinterpret-complex64`][@stdlib/strided/base/reinterpret-complex64]</span><span class="delimiter">: </span><span class="description">reinterpret a Complex64Array as a Float32Array.</span>
</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">
[@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/array-complex128
[@stdlib/array/float64]: https://www.npmjs.com/package/@stdlib/array-float64
<!-- <related-links> -->
[@stdlib/strided/base/reinterpret-complex]: https://github.com/stdlib-js/strided/tree/main/base/reinterpret-complex
[@stdlib/strided/base/reinterpret-complex64]: https://github.com/stdlib-js/strided/tree/main/base/reinterpret-complex64
<!-- </related-links> -->
</section>
<!-- /.links -->