Skip to content
165 changes: 165 additions & 0 deletions lib/node_modules/@stdlib/strided/base/reinterpret-uint64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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 [`Uint64Array`][@stdlib/array/uint64] as a [`Uint32Array`][@stdlib/array/uint32].

<!-- 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-uint64' );
```

#### reinterpret( x, offset )

Returns a [`Uint32Array`][@stdlib/array/uint32] view of a [`Uint64Array`][@stdlib/array/uint64].

```javascript
var Uint64Array = require( '@stdlib/array/uint64' );

var x = new Uint64Array( 10 );

var view = reinterpret( x, 0 );
// returns <Uint32Array>

var bool = ( view.buffer === x.buffer );
// returns true

var len = view.length;
// returns 20
```

The `offset` argument specifies the starting index of the returned [`Uint32Array`][@stdlib/array/uint32] view relative to the [`Uint64Array`][@stdlib/array/uint64].

```javascript
var Uint64Array = require( '@stdlib/array/uint64' );

var x = new Uint64Array( [ 1, 2, 3, 4, 0, 5, 6, 7 ] );

var view = reinterpret( x, 4 );
// returns <Uint32Array>

var len = view.length;
// returns 8

var hi = view[ 0 ];
// returns 0

var lo = view[ 1 ];
// returns 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 Uint64Array = require( '@stdlib/array/uint64' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-uint64' );

// Define a complex number array:
var x = new Uint64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
// returns <Uint64Array>

// Reinterpret as a `uint32` array:
var view = reinterpret( x, 0 );
// returns <Uint32Array>

// Set view elements:
view[ 0 ] = 0;
view[ 1 ] = 0;
// x => <Uint64Array>[ 0n, 2n, 3n, 4n, 5n, 6n, 7n, 8n ]
```

</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/uint64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/uint64

[@stdlib/array/uint32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/uint32

<!-- <related-links> -->

[@stdlib/strided/base/reinterpret-complex]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/strided/base/reinterpret-complex

[@stdlib/strided/base/reinterpret-complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/strided/base/reinterpret-complex64

<!-- </related-links> -->

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isUint32Array = require( '@stdlib/assert/is-uint32array' );
var Uint64Array = require( '@stdlib/array/uint64' );
var pkg = require( './../package.json' ).name;
var reinterpret = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var i;

values = [
new Uint64Array( 10 ),
new Uint64Array( 5 ),
new Uint64Array( 20 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = reinterpret( values[ i%values.length ], 1 );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isUint32Array( out ) ) {
b.fail( 'should return a Uint32Array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( x, offset )
Returns a Uint32Array view of a Uint64Array.

Parameters
----------
x: Uint64Array
Input array.

offset: integer
Starting index of the view relative to the Uint64Array.

Returns
-------
out: Uint32Array
Uint32Array view.

Examples
--------
> var x = new {{alias:@stdlib/array/uint64}}( 10 );
> var out = {{alias}}( x, 0 )
<Uint32Array>
> var bool = ( out.buffer === x.buffer )
true

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { Uint64Array } from '@stdlib/types/array';

/**
* Reinterprets a `Uint64Array` as a `Uint32Array`.
*
* @param x - input array
* @param offset - starting index
* @returns `Uint32Array` view
*
* @example
* var Uint64Array = require( '@stdlib/array/complex128' );
*
* var x = new Uint64Array( 10 );
*
* var out = reinterpret( x, 0 );
* // returns <Uint32Array>
*
* var bool = ( out.buffer === x.buffer );
*/
declare function reinterpret( x: Uint64Array, offset: number ): Uint32Array;


// EXPORTS //

export = reinterpret;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

import Uint64Array = require( '@stdlib/array/uint64' );
import reinterpret = require( './index' );


// TESTS //

// The function returns a Uint32Array...
{
reinterpret( new Uint64Array( 10 ), 0 ); // $ExpectType Uint32Array
}

// The compiler throws an error if not provided a first argument which is a Uint64Array...
{
reinterpret( '10', 0 ); // $ExpectError
reinterpret( 10, 0 ); // $ExpectError
reinterpret( true, 0 ); // $ExpectError
reinterpret( false, 0 ); // $ExpectError
reinterpret( null, 0 ); // $ExpectError
reinterpret( undefined, 0 ); // $ExpectError
reinterpret( [], 0 ); // $ExpectError
reinterpret( {}, 0 ); // $ExpectError
reinterpret( ( x: number ): number => x, 0 ); // $ExpectError
}

// The compiler throws an error if not provided a second argument which is a number...
{
const x = new Uint64Array( 10 );

reinterpret( x, '10' ); // $ExpectError
reinterpret( x, true ); // $ExpectError
reinterpret( x, false ); // $ExpectError
reinterpret( x, null ); // $ExpectError
reinterpret( x, undefined ); // $ExpectError
reinterpret( x, [] ); // $ExpectError
reinterpret( x, {} ); // $ExpectError
reinterpret( x, ( x: number ): number => x ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

'use strict';

var Uint64Array = require( '@stdlib/array/uint64' );
var reinterpret = require( './../lib' );

// Define a 64-bit unsigned integer array:
var x = new Uint64Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
// returns <Uint64Array>

// Reinterpret as a `uint32` array:
var view = reinterpret( x, 0 );
// returns <Uint32Array>

// Set view elements:
view[ 0 ] = 0;
view[ 1 ] = 0;

// Get the first element of the 64-bit unsigned integer array:
var u = x.get( 0 );
// returns <Uint64>[ 0n ]

console.log( u.toString() );
Loading