Skip to content

Commit 4df5253

Browse files
committed
feat: add ndarray/base/quinary
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent baaed47 commit 4df5253

56 files changed

Lines changed: 21170 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
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+
# Quinary
22+
23+
> Apply a quinary callback to elements in input ndarrays and assign results to elements in an output ndarray.
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 quinary = require( '@stdlib/ndarray/base/quinary' );
41+
```
42+
43+
#### quinary( arrays, fcn )
44+
45+
Applies a quinary callback to elements in input ndarrays and assigns results to elements in an output ndarray.
46+
47+
```javascript
48+
var Float64Array = require( '@stdlib/array/float64' );
49+
var add5 = require( '@stdlib/number/float64/base/add5' );
50+
51+
// Create data buffers:
52+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
53+
var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
54+
var zbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
55+
var wbuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
56+
var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
57+
var vbuf = new Float64Array( 6 );
58+
59+
// Define the shape of the input and output arrays:
60+
var shape = [ 3, 1, 2 ];
61+
62+
// Define the array strides:
63+
var sx = [ 2, 2, 1 ];
64+
var sy = [ 2, 2, 1 ];
65+
var sz = [ 2, 2, 1 ];
66+
var sw = [ 2, 2, 1 ];
67+
var su = [ 2, 2, 1 ];
68+
var sv = [ 2, 2, 1 ];
69+
70+
// Define the index offsets:
71+
var ox = 0;
72+
var oy = 0;
73+
var oz = 0;
74+
var ow = 0;
75+
var ou = 0;
76+
var ov = 0;
77+
78+
// Create the input and output ndarray-like objects:
79+
var x = {
80+
'dtype': 'float64',
81+
'data': xbuf,
82+
'shape': shape,
83+
'strides': sx,
84+
'offset': ox,
85+
'order': 'row-major'
86+
};
87+
var y = {
88+
'dtype': 'float64',
89+
'data': ybuf,
90+
'shape': shape,
91+
'strides': sy,
92+
'offset': oy,
93+
'order': 'row-major'
94+
};
95+
var z = {
96+
'dtype': 'float64',
97+
'data': zbuf,
98+
'shape': shape,
99+
'strides': sz,
100+
'offset': oz,
101+
'order': 'row-major'
102+
};
103+
var w = {
104+
'dtype': 'float64',
105+
'data': wbuf,
106+
'shape': shape,
107+
'strides': sw,
108+
'offset': ow,
109+
'order': 'row-major'
110+
};
111+
var u = {
112+
'dtype': 'float64',
113+
'data': ubuf,
114+
'shape': shape,
115+
'strides': su,
116+
'offset': ou,
117+
'order': 'row-major'
118+
};
119+
var v = {
120+
'dtype': 'float64',
121+
'data': vbuf,
122+
'shape': shape,
123+
'strides': sv,
124+
'offset': ov,
125+
'order': 'row-major'
126+
};
127+
128+
// Apply the quinary function:
129+
quinary( [ x, y, z, w, u, v ], add5 );
130+
131+
console.log( v.data );
132+
// => <Float64Array>[ 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]
133+
```
134+
135+
The function accepts the following arguments:
136+
137+
- **arrays**: array-like object containing five input ndarrays and one output ndarray.
138+
- **fcn**: quinary function to apply.
139+
140+
</section>
141+
142+
<!-- /.usage -->
143+
144+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145+
146+
<section class="notes">
147+
148+
## Notes
149+
150+
- Each provided ndarray should be an object with the following properties:
151+
152+
- **dtype**: data type.
153+
- **data**: data buffer.
154+
- **shape**: dimensions.
155+
- **strides**: stride lengths.
156+
- **offset**: index offset.
157+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
158+
159+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a quinary function in order to achieve better performance.
160+
161+
</section>
162+
163+
<!-- /.notes -->
164+
165+
<!-- Package usage examples. -->
166+
167+
<section class="examples">
168+
169+
## Examples
170+
171+
<!-- eslint no-undef: "error" -->
172+
173+
```javascript
174+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
175+
var filledarray = require( '@stdlib/array/filled' );
176+
var filledarrayBy = require( '@stdlib/array/filled-by' );
177+
var add5 = require( '@stdlib/number/float64/base/add5' );
178+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
179+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
180+
var quinary = require( '@stdlib/ndarray/base/quinary' );
181+
182+
var N = 10;
183+
var x = {
184+
'dtype': 'generic',
185+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
186+
'shape': [ 5, 2 ],
187+
'strides': [ 2, 1 ],
188+
'offset': 0,
189+
'order': 'row-major'
190+
};
191+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
192+
193+
var y = {
194+
'dtype': 'generic',
195+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
196+
'shape': x.shape.slice(),
197+
'strides': shape2strides( x.shape, 'column-major' ),
198+
'offset': 0,
199+
'order': 'column-major'
200+
};
201+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
202+
203+
var z = {
204+
'dtype': 'generic',
205+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
206+
'shape': x.shape.slice(),
207+
'strides': shape2strides( x.shape, 'row-major' ),
208+
'offset': 0,
209+
'order': 'row-major'
210+
};
211+
console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) );
212+
213+
var w = {
214+
'dtype': 'generic',
215+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
216+
'shape': x.shape.slice(),
217+
'strides': shape2strides( x.shape, 'row-major' ),
218+
'offset': 0,
219+
'order': 'row-major'
220+
};
221+
console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) );
222+
223+
var u = {
224+
'dtype': 'generic',
225+
'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ),
226+
'shape': x.shape.slice(),
227+
'strides': shape2strides( x.shape, 'row-major' ),
228+
'offset': 0,
229+
'order': 'row-major'
230+
};
231+
console.log( ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ) );
232+
233+
var v = {
234+
'dtype': 'generic',
235+
'data': filledarray( 0, N, 'generic' ),
236+
'shape': x.shape.slice(),
237+
'strides': shape2strides( x.shape, 'column-major' ),
238+
'offset': 0,
239+
'order': 'column-major'
240+
};
241+
242+
quinary( [ x, y, z, w, u, v ], add5 );
243+
console.log( ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ) );
244+
```
245+
246+
</section>
247+
248+
<!-- /.examples -->
249+
250+
<!-- 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. -->
251+
252+
<section class="references">
253+
254+
</section>
255+
256+
<!-- /.references -->
257+
258+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
259+
260+
<section class="related">
261+
262+
</section>
263+
264+
<!-- /.related -->
265+
266+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
267+
268+
<section class="links">
269+
270+
</section>
271+
272+
<!-- /.links -->

0 commit comments

Comments
 (0)