|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2023 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# empty |
| 22 | + |
| 23 | +> Create an uninitialized array having a specified length. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var empty = require( '@stdlib/array/empty' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### empty( length\[, dtype] ) |
| 44 | + |
| 45 | +Creates an uninitialized array having a specified length. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var arr = empty( 2 ); |
| 49 | +// returns <Float64Array> |
| 50 | +``` |
| 51 | + |
| 52 | +The function recognizes the following data types: |
| 53 | + |
| 54 | +- `float64`: double-precision floating-point numbers (IEEE 754) |
| 55 | +- `float32`: single-precision floating-point numbers (IEEE 754) |
| 56 | +- `complex128`: double-precision complex floating-point numbers |
| 57 | +- `complex64`: single-precision complex floating-point numbers |
| 58 | +- `int32`: 32-bit two's complement signed integers |
| 59 | +- `uint32`: 32-bit unsigned integers |
| 60 | +- `int16`: 16-bit two's complement signed integers |
| 61 | +- `uint16`: 16-bit unsigned integers |
| 62 | +- `int8`: 8-bit two's complement signed integers |
| 63 | +- `uint8`: 8-bit unsigned integers |
| 64 | +- `uint8c`: 8-bit unsigned integers clamped to `0-255` |
| 65 | +- `generic`: generic JavaScript values |
| 66 | + |
| 67 | +By default, the output array data type is `float64` (i.e., a [typed array][mdn-typed-array]). To specify an alternative data type, provide a `dtype` argument. |
| 68 | + |
| 69 | +```javascript |
| 70 | +var arr = empty( 2, 'int32' ); |
| 71 | +// returns <Int32Array> |
| 72 | +``` |
| 73 | + |
| 74 | +</section> |
| 75 | + |
| 76 | +<!-- /.usage --> |
| 77 | + |
| 78 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 79 | + |
| 80 | +<section class="notes"> |
| 81 | + |
| 82 | +## Notes |
| 83 | + |
| 84 | +- In browser environments, the function always returns zero-filled arrays. |
| 85 | +- If `dtype` is `'generic'`, the function always returns a zero-filled array. |
| 86 | +- 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. |
| 87 | + |
| 88 | +</section> |
| 89 | + |
| 90 | +<!-- /.notes --> |
| 91 | + |
| 92 | +<!-- Package usage examples. --> |
| 93 | + |
| 94 | +<section class="examples"> |
| 95 | + |
| 96 | +## Examples |
| 97 | + |
| 98 | +<!-- eslint no-undef: "error" --> |
| 99 | + |
| 100 | +```javascript |
| 101 | +var dtypes = require( '@stdlib/array/dtypes' ); |
| 102 | +var empty = require( '@stdlib/array/empty' ); |
| 103 | + |
| 104 | +// Get a list of array data types: |
| 105 | +var dt = dtypes(); |
| 106 | + |
| 107 | +// Generate empty arrays... |
| 108 | +var arr; |
| 109 | +var i; |
| 110 | +for ( i = 0; i < dt.length; i++ ) { |
| 111 | + arr = empty( 4, dt[ i ] ); |
| 112 | + console.log( arr ); |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.examples --> |
| 119 | + |
| 120 | +<!-- 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. --> |
| 121 | + |
| 122 | +<section class="references"> |
| 123 | + |
| 124 | +</section> |
| 125 | + |
| 126 | +<!-- /.references --> |
| 127 | + |
| 128 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 129 | + |
| 130 | +<section class="related"> |
| 131 | + |
| 132 | +</section> |
| 133 | + |
| 134 | +<!-- /.related --> |
| 135 | + |
| 136 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 137 | + |
| 138 | +<section class="links"> |
| 139 | + |
| 140 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.links --> |
0 commit comments