Skip to content

Commit 81b8f6c

Browse files
steff456kgryte
andauthored
feat: add array/empty-like
PR-URL: #1041 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent ab8801a commit 81b8f6c

22 files changed

+3250
-0
lines changed

Diff for: lib/node_modules/@stdlib/array/empty-like/README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
# emptyLike
22+
23+
> Create an uninitialized array having the same length and data type as a provided array.
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 emptyLike = require( '@stdlib/array/empty-like' );
41+
```
42+
43+
#### emptyLike( x\[, dtype] )
44+
45+
Creates an uninitialized array having the same length and data type as a provided array `x`.
46+
47+
```javascript
48+
var x = [ 1, 2, 3, 4, 5 ];
49+
50+
var arr = emptyLike( x );
51+
// returns [ 0, 0, 0, 0, 0 ];
52+
```
53+
54+
The function recognizes the following data types:
55+
56+
- `float64`: double-precision floating-point numbers (IEEE 754)
57+
- `float32`: single-precision floating-point numbers (IEEE 754)
58+
- `complex128`: double-precision complex floating-point numbers
59+
- `complex64`: single-precision complex floating-point numbers
60+
- `int32`: 32-bit two's complement signed integers
61+
- `uint32`: 32-bit unsigned integers
62+
- `int16`: 16-bit two's complement signed integers
63+
- `uint16`: 16-bit unsigned integers
64+
- `int8`: 8-bit two's complement signed integers
65+
- `uint8`: 8-bit unsigned integers
66+
- `uint8c`: 8-bit unsigned integers clamped to `0-255`
67+
- `generic`: generic JavaScript values
68+
69+
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.
70+
71+
```javascript
72+
var x = [ 1, 1 ];
73+
74+
var arr = emptyLike( x, 'int32' );
75+
// returns <Int32Array>
76+
```
77+
78+
</section>
79+
80+
<!-- /.usage -->
81+
82+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
83+
84+
<section class="notes">
85+
86+
## Notes
87+
88+
- In browser environments, the function always returns zero-filled arrays.
89+
- If `dtype` is `'generic'`, the function always returns a zero-filled array.
90+
- 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.
91+
92+
</section>
93+
94+
<!-- /.notes -->
95+
96+
<!-- Package usage examples. -->
97+
98+
<section class="examples">
99+
100+
## Examples
101+
102+
<!-- eslint no-undef: "error" -->
103+
104+
```javascript
105+
var dtypes = require( '@stdlib/array/dtypes' );
106+
var zeros = require( '@stdlib/array/zeros' );
107+
var emptyLike = require( '@stdlib/array/empty-like' );
108+
109+
// Create a zero-filled array:
110+
var x = zeros( 4, 'complex128' );
111+
112+
// Get a list of array data types:
113+
var dt = dtypes();
114+
115+
// Generate empty arrays...
116+
var arr;
117+
var i;
118+
for ( i = 0; i < dt.length; i++ ) {
119+
arr = emptyLike( x, dt[ i ] );
120+
console.log( arr );
121+
}
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- 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. -->
129+
130+
<section class="references">
131+
132+
</section>
133+
134+
<!-- /.references -->
135+
136+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137+
138+
<section class="related">
139+
140+
</section>
141+
142+
<!-- /.related -->
143+
144+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145+
146+
<section class="links">
147+
148+
</section>
149+
150+
<!-- /.links -->

0 commit comments

Comments
 (0)