-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add stats/incr/nanmmaxabs
#8716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sagar7162
wants to merge
2
commits into
stdlib-js:develop
Choose a base branch
from
sagar7162:nanmmaxabs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
lib/node_modules/@stdlib/stats/incr/nanmmaxabs/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| <!-- | ||
|
|
||
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2026 The Stdlib Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| --> | ||
|
|
||
| # incrnanmmaxabs | ||
|
|
||
| > Compute a moving maximum absolute value incrementally ignoring `NaN` values. | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var incrnanmmaxabs = require( '@stdlib/stats/incr/nanmmaxabs' ); | ||
| ``` | ||
|
|
||
| #### incrnanmmaxabs( window ) | ||
|
|
||
| Returns an accumulator `function` which incrementally computes a moving maximum absolute value. The `window` parameter defines the number of values over which to compute the moving maximum absolute value. | ||
|
|
||
| ```javascript | ||
| var accumulator = incrnanmmaxabs( 3 ); | ||
| ``` | ||
|
|
||
| #### accumulator( \[x] ) | ||
|
|
||
| If provided an input value `x`, the accumulator function returns an updated maximum absolute value. If not provided an input value `x`, the accumulator function returns the current maximum absolute value. | ||
|
|
||
| ```javascript | ||
| var accumulator = incrnanmmaxabs( 3 ); | ||
|
|
||
| var m = accumulator(); | ||
| // returns null | ||
|
|
||
| // Fill the window... | ||
| m = accumulator( 2.0 ); // [2.0] | ||
| // returns 2.0 | ||
|
|
||
| m = accumulator( NaN ); // [2.0] | ||
| // returns 2.0 | ||
|
|
||
| m = accumulator( -5.0 ); // [2.0, -5.0] | ||
| // returns 5.0 | ||
|
|
||
| m = accumulator( -7.0 ); // [2.0, -5.0, -7.0] | ||
| // returns 7.0 | ||
|
|
||
| m = accumulator( NaN ); // [2.0, -5.0, -7.0] | ||
| // returns 7.0 | ||
|
|
||
| m = accumulator(); | ||
| // returns 7.0 | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| ```javascript | ||
| var randu = require( '@stdlib/random/base/randu' ); | ||
| var incrnanmmaxabs = require( '@stdlib/stats/incr/nanmmaxabs' ); | ||
|
|
||
| var accumulator; | ||
| var m; | ||
| var v; | ||
| var i; | ||
|
|
||
| // Initialize an accumulator that *ignores NaNs* | ||
| accumulator = incrnanmmaxabs( 5 ); | ||
|
|
||
| console.log( '\nValue\tMaxAbs\n' ); | ||
|
|
||
| // Generate random values and insert some NaNs | ||
| for ( i = 0; i < 100; i++ ) { | ||
| // Randomly insert NaN values | ||
| if ( randu() < 0.1 ) { | ||
| v = NaN; | ||
| } else { | ||
| v = ( randu()*100.0 ) - 50.0; | ||
| } | ||
|
|
||
| m = accumulator( v ); | ||
| console.log( '%s\t%s', ( ( isNaN(v) ) ? 'NaN' : v.toFixed(3)), ( ( m === null ) ? 'null' : m.toFixed(3))); | ||
| } | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
82 changes: 82 additions & 0 deletions
82
lib/node_modules/@stdlib/stats/incr/nanmmaxabs/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var uniform = require( '@stdlib/random/base/uniform' ); | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var incrnanmmaxabs = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var f; | ||
| var i; | ||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| f = incrnanmmaxabs( ( i % 5 ) + 1 ); | ||
| if ( typeof f !== 'function' ) { | ||
| b.fail( 'should return a function' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( typeof f !== 'function' ) { | ||
| b.fail( 'should return a function' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
|
|
||
| bench( format( '%s::accumulator', pkg ), function benchmark( b ) { | ||
| var acc; | ||
| var v; | ||
| var x; | ||
| var i; | ||
|
|
||
| acc = incrnanmmaxabs( 5 ); | ||
|
|
||
| x = new Float64Array( b.iterations ); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| if ( ( i & 7 ) === 0 ) { | ||
| x[ i ] = NaN; | ||
| } else { | ||
| x[ i ] = uniform( -100.0, 100.0 ); | ||
| } | ||
| } | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| v = acc( x[ i ] ); | ||
| if ( isnan( v ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( v ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
47 changes: 47 additions & 0 deletions
47
lib/node_modules/@stdlib/stats/incr/nanmmaxabs/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
|
|
||
| {{alias}}( W ) | ||
| Returns an accumulator function which incrementally computes a moving | ||
| maximum absolute value while ignoring `NaN` values. | ||
|
|
||
| The `W` parameter defines the number of values over which to compute the | ||
| moving maximum absolute value. | ||
|
|
||
| If provided a value, the accumulator function returns an updated moving | ||
| maximum absolute value. If not provided a value, the accumulator function | ||
| returns the current moving maximum absolute value. | ||
|
|
||
| Any `NaN` values provided to the accumulator are ignored, and do not | ||
| affect the accumulated result. | ||
|
|
||
| As `W` values are needed to fill the window buffer, the first `W-1` returned | ||
| values are calculated from smaller sample sizes. Until the window is full, | ||
| each returned value is calculated from all provided non-NaN values. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| W: integer | ||
| Window size. | ||
|
|
||
| Returns | ||
| ------- | ||
| acc: Function | ||
| Accumulator function. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var accumulator = {{alias}}( 3 ); | ||
| > var m = accumulator() | ||
| null | ||
| > m = accumulator( 2.0 ) | ||
| 2.0 | ||
| > m = accumulator( NaN ) | ||
| 2.0 | ||
| > m = accumulator( -5.0 ) | ||
| 5.0 | ||
| > m = accumulator( 3.0 ) | ||
| 5.0 | ||
| > m = accumulator() | ||
| 5.0 | ||
|
|
||
| See Also | ||
| -------- |
67 changes: 67 additions & 0 deletions
67
lib/node_modules/@stdlib/stats/incr/nanmmaxabs/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| /** | ||
| * If provided a value, returns an updated moving maximum absolute value; otherwise, returns the current maximum absolute value. | ||
| * | ||
| * | ||
| * @param x - value | ||
| * @returns moving maximum absolute value | ||
| */ | ||
| type accumulator = ( x?: number ) => number | null; | ||
|
|
||
| /** | ||
| * Returns an accumulator function which incrementally computes a moving maximum absolute value while ignoring `NaN` values. | ||
| * | ||
| * ## Notes | ||
| * | ||
| * - The `W` parameter defines the number of values over which to compute the moving maximum absolute value. | ||
| * - Until the window is full, each returned value is calculated from all non-NaN values received so far. `NaN` values are skipped and do not enter the moving window. | ||
| * | ||
| * @param W - window size | ||
| * @throws must provide a positive integer | ||
| * @returns accumulator function | ||
| * | ||
| * @example | ||
| * var accumulator = incrnanmmaxabs( 3 ); | ||
| * | ||
| * var m = accumulator(); | ||
| * // returns null | ||
| * | ||
| * m = accumulator( 2.0 ); | ||
| * // returns 2.0 | ||
| * | ||
| * m = accumulator( NaN ); | ||
| * // returns 2.0 | ||
| * | ||
| * m = accumulator( -5.0 ); | ||
| * // returns 5.0 | ||
| * | ||
| * m = accumulator( NaN ); | ||
| * // returns 5.0 | ||
| */ | ||
| declare function incrnanmmaxabs( W: number ): accumulator; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = incrnanmmaxabs; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.