Skip to content

Commit 204c9d9

Browse files
LoayAhmed304kgrytestdlib-bot
authored
feat: add ndarray/base/full
PR-URL: #11017 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <noreply@stdlib.io>
1 parent 2832fab commit 204c9d9

23 files changed

Lines changed: 3145 additions & 0 deletions
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# full
22+
23+
> Create an [ndarray][@stdlib/ndarray/base/ctor] filled with a specified value and having a specified shape and [data type][@stdlib/ndarray/dtypes].
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 full = require( '@stdlib/ndarray/base/full' );
41+
```
42+
43+
#### full( value, dtype, shape, order )
44+
45+
Returns an [ndarray][@stdlib/ndarray/base/ctor] filled with a specified value and having a specified shape and [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
50+
51+
var arr = full( 10.0, 'float64', [ 2, 2 ], 'row-major' );
52+
// returns <ndarray>[ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ]
53+
54+
var sh = getShape( arr );
55+
// returns [ 2, 2 ]
56+
57+
var dt = String( getDType( arr ) );
58+
// returns 'float64'
59+
```
60+
61+
This function accepts the following arguments:
62+
63+
- **value**: scalar fill value.
64+
- **dtype**: underlying [data type][@stdlib/ndarray/dtypes].
65+
- **shape**: array shape.
66+
- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style).
67+
68+
</section>
69+
70+
<!-- /.usage -->
71+
72+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
73+
74+
<section class="notes">
75+
76+
## Notes
77+
78+
- If `value` is a number and `x` has a complex [data type][@stdlib/ndarray/dtypes], the function fills an output ndarray with a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero.
79+
- A `value` must be able to safely cast to the output ndarray [data type][@stdlib/ndarray/dtypes]. Scalar values having floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., a scalar double-precision floating-point number can be used to fill a `'float32'` output ndarray).
80+
81+
</section>
82+
83+
<!-- /.notes -->
84+
85+
<!-- Package usage examples. -->
86+
87+
<section class="examples">
88+
89+
## Examples
90+
91+
<!-- eslint no-undef: "error" -->
92+
93+
```javascript
94+
var dtypes = require( '@stdlib/ndarray/dtypes' );
95+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
96+
var full = require( '@stdlib/ndarray/base/full' );
97+
98+
// Get a list of data types:
99+
var dt = dtypes( 'integer_and_generic' );
100+
101+
// Generate initialized arrays...
102+
var arr;
103+
var i;
104+
for ( i = 0; i < dt.length; i++ ) {
105+
arr = full( 10, dt[ i ], [ 2, 2 ], 'row-major' );
106+
console.log( ndarray2array( arr ) );
107+
}
108+
```
109+
110+
</section>
111+
112+
<!-- /.examples -->
113+
114+
<!-- 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. -->
115+
116+
<section class="references">
117+
118+
</section>
119+
120+
<!-- /.references -->
121+
122+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
123+
124+
<section class="related">
125+
126+
</section>
127+
128+
<!-- /.related -->
129+
130+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
131+
132+
<section class="links">
133+
134+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor
135+
136+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
137+
138+
</section>
139+
140+
<!-- /.links -->

0 commit comments

Comments
 (0)