Skip to content

Commit 06a5afb

Browse files
committed
feat: add stats/base/ndarray/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 8ce04f0 commit 06a5afb

File tree

10 files changed

+892
-0
lines changed

10 files changed

+892
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
> Compute the cumulative maximum value of a one-dimensional double-precision floating-point ndarray.
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/base/ndarray/dcumax' );
37+
```
38+
39+
#### dcumax( arrays )
40+
41+
Computes the cumulative maximum value of a one-dimensional double-precision floating-point ndarray.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
46+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
47+
48+
var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] );
49+
var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
50+
51+
var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] );
52+
var y = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
53+
54+
var v = dcumax( [ x, y ] );
55+
// returns <ndarray>
56+
57+
var bool = ( v === y );
58+
// returns true
59+
60+
var arr = ndarray2array( v );
61+
// returns [ 1.0, 3.0, 4.0, 4.0 ]
62+
```
63+
64+
The function has the following parameters:
65+
66+
- **arrays**: array-like object containing a one-dimensional input ndarray and a one-dimensional output ndarray.
67+
68+
</section>
69+
70+
<!-- /.usage -->
71+
72+
<section class="notes">
73+
74+
## Notes
75+
76+
- If provided an empty one-dimensional input ndarray, the function returns the output ndarray unchanged.
77+
78+
</section>
79+
80+
<!-- /.notes -->
81+
82+
<section class="examples">
83+
84+
## Examples
85+
86+
<!-- eslint no-undef: "error" -->
87+
88+
```javascript
89+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
90+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
91+
var zerosLike = require( '@stdlib/ndarray/zeros-like' );
92+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
93+
var dcumax = require( '@stdlib/stats/base/ndarray/dcumax' );
94+
95+
var xbuf = discreteUniform( 10, -50, 50, {
96+
'dtype': 'float64'
97+
});
98+
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
99+
console.log( ndarray2array( x ) );
100+
101+
var y = zerosLike( x );
102+
console.log( ndarray2array( y ) );
103+
104+
var v = dcumax( [ x, y ] );
105+
console.log( ndarray2array( v ) );
106+
```
107+
108+
</section>
109+
110+
<!-- /.examples -->
111+
112+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
113+
114+
<section class="related">
115+
116+
</section>
117+
118+
<!-- /.related -->
119+
120+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="links">
123+
124+
</section>
125+
126+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var zeros = require( '@stdlib/array/zeros' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
29+
var pkg = require( './../package.json' ).name;
30+
var dcumax = require( './../lib' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float64'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} len - array length
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( len ) {
50+
var xbuf;
51+
var ybuf;
52+
var x;
53+
var y;
54+
55+
xbuf = uniform( len, -10.0, 10.0, options );
56+
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
57+
58+
ybuf = zeros( len, options.dtype );
59+
y = new ndarray( options.dtype, ybuf, [ len ], [ 1 ], 0, 'row-major' );
60+
61+
return benchmark;
62+
63+
function benchmark( b ) {
64+
var v;
65+
var i;
66+
67+
b.tic();
68+
for ( i = 0; i < b.iterations; i++ ) {
69+
v = dcumax( [ x, y ] );
70+
if ( typeof v !== 'object' ) {
71+
b.fail( 'should return an ndarray' );
72+
}
73+
}
74+
b.toc();
75+
if ( isnan( v.get( i%len ) ) ) {
76+
b.fail( 'should not return NaN' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
}
81+
}
82+
83+
84+
// MAIN //
85+
86+
/**
87+
* Main execution sequence.
88+
*
89+
* @private
90+
*/
91+
function main() {
92+
var len;
93+
var min;
94+
var max;
95+
var f;
96+
var i;
97+
98+
min = 1; // 10^min
99+
max = 6; // 10^max
100+
101+
for ( i = min; i <= max; i++ ) {
102+
len = pow( 10, i );
103+
f = createBenchmark( len );
104+
bench( pkg+':len='+len, f );
105+
}
106+
}
107+
108+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
{{alias}}( arrays )
3+
Computes the cumulative maximum value of a one-dimensional double-precision
4+
floating-point ndarray.
5+
6+
If provided an empty input ndarray, the function returns the output ndarray
7+
unchanged.
8+
9+
Parameters
10+
----------
11+
arrays: ArrayLikeObject<ndarray>
12+
Array-like object containing a one-dimensional input ndarray and a one-
13+
dimensional output ndarray.
14+
15+
Returns
16+
-------
17+
out: ndarray
18+
Output ndarray.
19+
20+
Examples
21+
--------
22+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] );
23+
> var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0 ] );
24+
> var dt = 'float64';
25+
> var sh = [ xbuf.length ];
26+
> var st = [ 1 ];
27+
> var oo = 0;
28+
> var ord = 'row-major';
29+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord );
30+
> var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, st, oo, ord );
31+
> {{alias}}( [ x, y ] );
32+
> {{alias:@stdlib/ndarray/to-array}}( y )
33+
[ 1.0, 1.0, 2.0 ]
34+
35+
See Also
36+
--------
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { float64ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Computes the cumulative maximum value of a one-dimensional double-precision floating-point ndarray.
27+
*
28+
* @param arrays - array-like object containing an input ndarray and an output ndarray
29+
* @returns output ndarray
30+
*
31+
* @example
32+
* var Float64Array = require( '@stdlib/array/float64' );
33+
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
34+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
35+
*
36+
* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] );
37+
* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
38+
*
39+
* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] );
40+
* var y = new ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' );
41+
*
42+
* var v = dcumax( [ x, y ] );
43+
* // returns <ndarray>
44+
*
45+
* var bool = ( v === y );
46+
* // returns true
47+
*
48+
* var arr = ndarray2array( v );
49+
* // returns [ 1.0, 3.0, 4.0, 4.0 ]
50+
*/
51+
declare function dcumax( arrays: [ float64ndarray, float64ndarray ] ): float64ndarray;
52+
53+
54+
// EXPORTS //
55+
56+
export = dcumax;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable space-in-parens */
20+
21+
import zeros = require( '@stdlib/ndarray/zeros' );
22+
import dcumax = require( './index' );
23+
24+
25+
// TESTS //
26+
27+
// The function returns an ndarray...
28+
{
29+
const x = zeros( [ 10 ], {
30+
'dtype': 'float64'
31+
});
32+
const y = zeros( [ 10 ], {
33+
'dtype': 'float64'
34+
});
35+
36+
dcumax( [ x, y ] ); // $ExpectType float64ndarray
37+
}
38+
39+
// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays...
40+
{
41+
dcumax( '10' ); // $ExpectError
42+
dcumax( 10 ); // $ExpectError
43+
dcumax( true ); // $ExpectError
44+
dcumax( false ); // $ExpectError
45+
dcumax( null ); // $ExpectError
46+
dcumax( undefined ); // $ExpectError
47+
dcumax( [] ); // $ExpectError
48+
dcumax( {} ); // $ExpectError
49+
dcumax( ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The compiler throws an error if the function is provided an unsupported number of arguments...
53+
{
54+
const x = zeros( [ 10 ], {
55+
'dtype': 'float64'
56+
});
57+
const y = zeros( [ 10 ], {
58+
'dtype': 'float64'
59+
});
60+
61+
dcumax(); // $ExpectError
62+
dcumax( [ x, y ], {} ); // $ExpectError
63+
}

0 commit comments

Comments
 (0)