Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 7, 2023
1 parent 86fc789 commit 7cbf632
Show file tree
Hide file tree
Showing 22 changed files with 3,250 additions and 0 deletions.
150 changes: 150 additions & 0 deletions empty-like/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<!--
@license Apache-2.0
Copyright (c) 2023 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.
-->

# emptyLike

> Create an uninitialized array having the same length and data type as a provided array.
<!-- 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 emptyLike = require( '@stdlib/array/empty-like' );
```

#### emptyLike( x\[, dtype] )

Creates an uninitialized array having the same length and data type as a provided array `x`.

```javascript
var x = [ 1, 2, 3, 4, 5 ];

var arr = emptyLike( x );
// returns [ 0, 0, 0, 0, 0 ];
```

The function recognizes the following data types:

- `float64`: double-precision floating-point numbers (IEEE 754)
- `float32`: single-precision floating-point numbers (IEEE 754)
- `complex128`: double-precision complex floating-point numbers
- `complex64`: single-precision complex floating-point numbers
- `int32`: 32-bit two's complement signed integers
- `uint32`: 32-bit unsigned integers
- `int16`: 16-bit two's complement signed integers
- `uint16`: 16-bit unsigned integers
- `int8`: 8-bit two's complement signed integers
- `uint8`: 8-bit unsigned integers
- `uint8c`: 8-bit unsigned integers clamped to `0-255`
- `generic`: generic JavaScript values

By default, the output array data type is inferred from the provided array `x`. To return an array having a different data type, provide a `dtype` argument.

```javascript
var x = [ 1, 1 ];

var arr = emptyLike( x, 'int32' );
// returns <Int32Array>
```

</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">

## Notes

- In browser environments, the function always returns zero-filled arrays.
- If `dtype` is `'generic'`, the function always returns a zero-filled array.
- In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var dtypes = require( '@stdlib/array/dtypes' );
var zeros = require( '@stdlib/array/zeros' );
var emptyLike = require( '@stdlib/array/empty-like' );

// Create a zero-filled array:
var x = zeros( 4, 'complex128' );

// Get a list of array data types:
var dt = dtypes();

// Generate empty arrays...
var arr;
var i;
for ( i = 0; i < dt.length; i++ ) {
arr = emptyLike( x, dt[ i ] );
console.log( arr );
}
```

</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 -->
Loading

0 comments on commit 7cbf632

Please sign in to comment.