Skip to content

Commit 0735bb4

Browse files
committed
feat: add stats/strided/wasm/dcumax
--- 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 27ace7d commit 0735bb4

34 files changed

+5692
-1
lines changed

lib/node_modules/@stdlib/stats/strided/dcumax/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
]
8686
},
8787
{
88-
"task": "",
88+
"task": "build",
8989
"wasm": true,
9090
"src": [
9191
"./src/main.c"
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# dcumax
22+
23+
> Calculate the cumulative maximum of double-precision floating-point strided array elements.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var dcumax = require( '@stdlib/stats/strided/wasm/dcumax' );
37+
```
38+
39+
#### dcumax.main( N, x, strideX, y, strideY )
40+
41+
Computes the cumulative maximum of double-precision floating-point strided array elements.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
46+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
47+
var y = new Float64Array( x.length );
48+
49+
dcumax.main( x.length, x, 1, y, 1 );
50+
// y => <Float64Array>[ 1.0, 1.0, 2.0 ]
51+
```
52+
53+
The function has the following parameters:
54+
55+
- **N**: number of indexed elements.
56+
- **x**: input [`Float64Array`][@stdlib/array/float64].
57+
- **strideX**: stride length for `x`.
58+
- **y**: output [`Float64Array`][@stdlib/array/float64].
59+
- **strideY**: stride length for `y`.
60+
61+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative maximum of every other element in `x`,
62+
63+
```javascript
64+
var Float64Array = require( '@stdlib/array/float64' );
65+
66+
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
67+
var y = new Float64Array( x.length );
68+
69+
dcumax.main( 4, x, 2, y, 1 );
70+
// y => <Float64Array>[ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
71+
```
72+
73+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
74+
75+
<!-- eslint-disable stdlib/capitalized-comments -->
76+
77+
```javascript
78+
var Float64Array = require( '@stdlib/array/float64' );
79+
80+
// Initial arrays...
81+
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
82+
var y0 = new Float64Array( x0.length );
83+
84+
// Create offset views...
85+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
86+
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
87+
88+
dcumax.main( 4, x1, -2, y1, 1 );
89+
// y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0, 0.0 ]
90+
```
91+
92+
#### dcumax.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
93+
94+
Computes the cumulative maximum of double-precision floating-point strided array elements using alternative indexing semantics.
95+
96+
```javascript
97+
var Float64Array = require( '@stdlib/array/float64' );
98+
99+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
100+
var y = new Float64Array( x.length );
101+
102+
dcumax.ndarray( x.length, x, 1, 0, y, 1, 0 );
103+
// y => <Float64Array>[ 1.0, 1.0, 2.0 ]
104+
```
105+
106+
The function has the following additional parameters:
107+
108+
- **offsetX**: starting index for `x`.
109+
- **offsetY**: starting index for `y`.
110+
111+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative maximum of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element
112+
113+
```javascript
114+
var Float64Array = require( '@stdlib/array/float64' );
115+
116+
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
117+
var y = new Float64Array( x.length );
118+
119+
dcumax.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
120+
// y => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 4.0, 2.0, 1.0, 1.0 ]
121+
```
122+
123+
* * *
124+
125+
### Module
126+
127+
#### dcumax.Module( memory )
128+
129+
Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory.
130+
131+
<!-- eslint-disable node/no-sync -->
132+
133+
```javascript
134+
var Memory = require( '@stdlib/wasm/memory' );
135+
136+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
137+
var mem = new Memory({
138+
'initial': 10,
139+
'maximum': 100
140+
});
141+
142+
// Create a STATS routine:
143+
var mod = new dcumax.Module( mem );
144+
// returns <Module>
145+
146+
// Initialize the routine:
147+
mod.initializeSync();
148+
```
149+
150+
#### dcumax.Module.prototype.main( N, xp, sx, yp, sy )
151+
152+
Computes the cumulative maximum of double-precision floating-point strided array elements.
153+
154+
<!-- eslint-disable node/no-sync -->
155+
156+
```javascript
157+
var Memory = require( '@stdlib/wasm/memory' );
158+
var zeros = require( '@stdlib/array/zeros' );
159+
var Float64Array = require( '@stdlib/array/float64' );
160+
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );
161+
162+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
163+
var mem = new Memory({
164+
'initial': 10,
165+
'maximum': 100
166+
});
167+
168+
// Create a STATS routine:
169+
var mod = new dcumax.Module( mem );
170+
// returns <Module>
171+
172+
// Initialize the routine:
173+
mod.initializeSync();
174+
175+
// Define a vector data type:
176+
var dtype = 'float64';
177+
178+
// Specify a vector length:
179+
var N = 5;
180+
181+
// Define pointers (i.e., byte offsets) for storing two vectors:
182+
var xptr = 0;
183+
var yptr = N * bytesPerElement( dtype );
184+
185+
// Define strided array:
186+
var arr = new Float64Array( [ 1.0, -2.0, 2.0, -3.0, 3.0 ] );
187+
188+
// Write vector values to module memory:
189+
mod.write( xptr, arr );
190+
mod.write( yptr, zeros( N, dtype ) );
191+
192+
// Perform computation:
193+
mod.main( N, xptr, 1, yptr, 1 );
194+
195+
// Read out the results:
196+
var view = zeros( N, dtype );
197+
mod.read( yptr, view );
198+
199+
console.log( view );
200+
// => <Float64Array>[ 1.0, 1.0, 2.0, 2.0, 3.0 ]
201+
```
202+
203+
The function has the following parameters:
204+
205+
- **N**: number of indexed elements.
206+
- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset).
207+
- **sx**: index increment for `x`.
208+
- **yp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset).
209+
- **sy**: index increment for `y`.
210+
211+
#### dcumax.Module.prototype.ndarray( N, xp, sx, ox, yp, sy, oy )
212+
213+
Computes the cumulative maximum of double-precision floating-point strided array elements using alternative indexing semantics.
214+
215+
<!-- eslint-disable node/no-sync -->
216+
217+
```javascript
218+
var Memory = require( '@stdlib/wasm/memory' );
219+
var zeros = require( '@stdlib/array/zeros' );
220+
var Float64Array = require( '@stdlib/array/float64' );
221+
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );
222+
223+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
224+
var mem = new Memory({
225+
'initial': 10,
226+
'maximum': 100
227+
});
228+
229+
// Create a STATS routine:
230+
var mod = new dcumax.Module( mem );
231+
// returns <Module>
232+
233+
// Initialize the routine:
234+
mod.initializeSync();
235+
236+
// Define a vector data type:
237+
var dtype = 'float64';
238+
239+
// Specify a vector length:
240+
var N = 5;
241+
242+
// Define pointers (i.e., byte offsets) for storing two vectors:
243+
var xptr = 0;
244+
var yptr = N * bytesPerElement( dtype );
245+
246+
// Define strided array:
247+
var arr = new Float64Array( [ 1.0, -2.0, 2.0, -3.0, 3.0 ] );
248+
249+
// Write vector values to module memory:
250+
mod.write( xptr, arr );
251+
mod.write( yptr, zeros( N, dtype ) );
252+
253+
// Perform computation:
254+
mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 );
255+
256+
// Read out the results:
257+
var view = zeros( N, dtype );
258+
mod.read( yptr, view );
259+
260+
console.log( view );
261+
// => <Float64Array>[ 1.0, 1.0, 2.0, 2.0, 3.0 ]
262+
```
263+
264+
The function has the following additional parameters:
265+
266+
- **ox**: starting index for `x`.
267+
- **oy**: starting index for `y`.
268+
269+
</section>
270+
271+
<!-- /.usage -->
272+
273+
<section class="notes">
274+
275+
* * *
276+
277+
## Notes
278+
279+
- If `N <= 0`, both functions return `y` unchanged.
280+
- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dcumax` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/stats/strided/dcumax`][@stdlib/stats/strided/dcumax]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/stats/strided/dcumax`][@stdlib/stats/strided/dcumax]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other.
281+
282+
</section>
283+
284+
<!-- /.notes -->
285+
286+
<section class="examples">
287+
288+
## Examples
289+
290+
<!-- eslint no-undef: "error" -->
291+
292+
```javascript
293+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
294+
var Float64Array = require( '@stdlib/array/float64' );
295+
var dcumax = require( '@stdlib/stats/strided/wasm/dcumax' );
296+
297+
var x = discreteUniform( 10, -50, 50, {
298+
'dtype': 'float64'
299+
});
300+
console.log( x );
301+
302+
var y = new Float64Array( x.length );
303+
console.log( y );
304+
305+
dcumax.ndarray( x.length, x, 1, y, -1 );
306+
console.log( y );
307+
```
308+
309+
</section>
310+
311+
<!-- /.examples -->
312+
313+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
314+
315+
<section class="related">
316+
317+
</section>
318+
319+
<!-- /.related -->
320+
321+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
322+
323+
<section class="links">
324+
325+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
326+
327+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
328+
329+
[@stdlib/wasm/memory]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/memory
330+
331+
[@stdlib/stats/strided/dcumax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dcumax
332+
333+
[@stdlib/wasm/module-wrapper]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/module-wrapper
334+
335+
</section>
336+
337+
<!-- /.links -->

0 commit comments

Comments
 (0)