Skip to content

Commit 793dbc1

Browse files
committed
feat: add ndarray/base/full-by
1 parent 74f9832 commit 793dbc1

23 files changed

+3565
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
# fullBy
22+
23+
> Create an [ndarray][@stdlib/ndarray/base/ctor] filled according to a callback function 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 fullBy = require( '@stdlib/ndarray/base/full-by' );
41+
```
42+
43+
#### fullBy( dtype, shape, order, clbk\[, thisArg] )
44+
45+
Returns an [ndarray][@stdlib/ndarray/base/ctor] filled according to a callback function and having a specified shape and [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getDType = require( '@stdlib/ndarray/dtype' );
49+
50+
function clbk() {
51+
return 10.0;
52+
}
53+
54+
var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk );
55+
// returns <ndarray>[ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ]
56+
57+
var dt = String( getDType( arr ) );
58+
// returns 'float64'
59+
```
60+
61+
This function accepts the following arguments:
62+
63+
- **dtype**: underlying [data type][@stdlib/ndarray/dtypes].
64+
- **shape**: array shape.
65+
- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style).
66+
- **clbk**: callback function.
67+
- **thisArg**: callback function execution context (_optional_).
68+
69+
The callback function is provided the following arguments:
70+
71+
- **indices**: current array element indices.
72+
73+
To set the callback function execution context, provide a `thisArg`.
74+
75+
```javascript
76+
var getDType = require( '@stdlib/ndarray/dtype' );
77+
78+
function clbk( indices ) {
79+
return this.value * ( indices[ 0 ] + indices[ 1 ] ); // eslint-disable-line no-invalid-this
80+
}
81+
82+
var ctx = {
83+
'value': 10.0
84+
};
85+
86+
var arr = fullBy( 'float64', [ 2, 2 ], 'row-major', clbk, ctx );
87+
// returns <ndarray>[ [ 0.0, 10.0 ], [ 10.0, 20.0 ] ]
88+
89+
var dt = String( getDType( arr ) );
90+
// returns 'float64'
91+
```
92+
93+
</section>
94+
95+
<!-- /.usage -->
96+
97+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
98+
99+
<section class="notes">
100+
101+
</section>
102+
103+
<!-- /.notes -->
104+
105+
<!-- Package usage examples. -->
106+
107+
<section class="examples">
108+
109+
## Examples
110+
111+
<!-- eslint no-undef: "error" -->
112+
113+
```javascript
114+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
115+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
116+
var dtypes = require( '@stdlib/ndarray/dtypes' );
117+
var fullBy = require( '@stdlib/ndarray/base/full-by' );
118+
119+
// Get a list of data types:
120+
var dt = dtypes( 'integer_and_generic' );
121+
122+
// Generate filled arrays...
123+
var arr;
124+
var i;
125+
for ( i = 0; i < dt.length; i++ ) {
126+
arr = fullBy( dt[ i ], [ 2, 2 ], 'row-major', discreteUniform( -100, 100 ) );
127+
console.log( ndarray2array( arr ) );
128+
}
129+
```
130+
131+
</section>
132+
133+
<!-- /.examples -->
134+
135+
<!-- 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. -->
136+
137+
<section class="references">
138+
139+
</section>
140+
141+
<!-- /.references -->
142+
143+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
144+
145+
<section class="related">
146+
147+
</section>
148+
149+
<!-- /.related -->
150+
151+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
152+
153+
<section class="links">
154+
155+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor
156+
157+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
158+
159+
</section>
160+
161+
<!-- /.links -->

0 commit comments

Comments
 (0)