Skip to content

Commit fc37688

Browse files
committed
Add array utility to create a filled array having the same length and data type as a provided array
1 parent 8463d11 commit fc37688

22 files changed

+3348
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2022 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+
# fullLike
22+
23+
> Create a filled 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 fullLike = require( '@stdlib/array/full-like' );
41+
```
42+
43+
#### fullLike( x, value\[, dtype] )
44+
45+
Creates a filled 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 = fullLike( x, 1 );
51+
// returns [ 1, 1, 1, 1, 1 ]
52+
```
53+
54+
The function supports 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 = fullLike( x, 1, 'int32' );
75+
// returns <Int32Array>[ 1, 1 ]
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+
- If provided a number and the output array data type is a complex number data type, the function returns a complex number array where each element has a real component whose value equals the provided fill value and where each element has an imaginary component equal to `0`.
89+
90+
</section>
91+
92+
<!-- /.notes -->
93+
94+
<!-- Package usage examples. -->
95+
96+
<section class="examples">
97+
98+
## Examples
99+
100+
<!-- eslint no-undef: "error" -->
101+
102+
```javascript
103+
var dtypes = require( '@stdlib/array/dtypes' );
104+
var zeros = require( '@stdlib/array/zeros' );
105+
var fullLike = require( '@stdlib/array/full-like' );
106+
107+
// Create a zero-filled array:
108+
var x = zeros( 4, 'complex128' );
109+
110+
// Get a list of array data types:
111+
var dt = dtypes();
112+
113+
// Generate filled arrays...
114+
var y;
115+
var i;
116+
for ( i = 0; i < dt.length; i++ ) {
117+
y = fullLike( x, dt[ i ] );
118+
console.log( y );
119+
}
120+
```
121+
122+
</section>
123+
124+
<!-- /.examples -->
125+
126+
<!-- 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. -->
127+
128+
<section class="references">
129+
130+
</section>
131+
132+
<!-- /.references -->
133+
134+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
135+
136+
<section class="related">
137+
138+
</section>
139+
140+
<!-- /.related -->
141+
142+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
143+
144+
<section class="links">
145+
146+
</section>
147+
148+
<!-- /.links -->

0 commit comments

Comments
 (0)