-
-
Notifications
You must be signed in to change notification settings - Fork 906
feat: add accessor protocol support and refactor stats/base/nanmin
#6211
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8c3522e
feat: add accessor protocol and refactor stats/base/nanmin
rahulptl165 d428349
test: ensure to include existing assertions
rahulptl165 8a1008f
docs: update description
kgryte 8d43719
docs: fix grammar
kgryte 6adf7e1
docs: fix grammar
kgryte 57fb8a2
docs: update note
kgryte ed96a58
refactor: addressed requested changes
rahulptl165 eb2f8a4
Merge branch 'develop' into feat/accessor-nanmin
kgryte 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
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 |
---|---|---|
|
@@ -36,33 +36,29 @@ limitations under the License. | |
var nanmin = require( '@stdlib/stats/base/nanmin' ); | ||
``` | ||
|
||
#### nanmin( N, x, stride ) | ||
#### nanmin( N, x, strideX ) | ||
|
||
Computes the minimum value of a strided array `x`, ignoring `NaN` values. | ||
|
||
```javascript | ||
var x = [ 1.0, -2.0, NaN, 2.0 ]; | ||
var N = x.length; | ||
|
||
var v = nanmin( N, x, 1 ); | ||
var v = nanmin( 4, x, 1 ); | ||
// returns -2.0 | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **N**: number of indexed elements. | ||
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. | ||
- **stride**: index increment for `x`. | ||
- **strideX**: stride length for `x`. | ||
|
||
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the minimum value of every other element in `x`, | ||
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the minimum value of every other element in `x`, | ||
|
||
```javascript | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
|
||
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ]; | ||
var N = floor( x.length / 2 ); | ||
|
||
var v = nanmin( N, x, 2 ); | ||
var v = nanmin( 5, x, 2 ); | ||
// returns -2.0 | ||
``` | ||
|
||
|
@@ -72,42 +68,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [ | |
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
|
||
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, NaN, NaN, 4.0 ] ); | ||
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
|
||
var N = floor( x0.length / 2 ); | ||
|
||
var v = nanmin( N, x1, 2 ); | ||
var v = nanmin( 4, x1, 2 ); | ||
// returns -2.0 | ||
``` | ||
|
||
#### nanmin.ndarray( N, x, stride, offset ) | ||
#### nanmin.ndarray( N, x, strideX, offsetX ) | ||
|
||
Computes the minimum value of a strided array, ignoring `NaN` values and using alternative indexing semantics. | ||
|
||
```javascript | ||
var x = [ 1.0, -2.0, NaN, 2.0 ]; | ||
var N = x.length; | ||
|
||
var v = nanmin.ndarray( N, x, 1, 0 ); | ||
var v = nanmin.ndarray( 4, x, 1, 0 ); | ||
// returns -2.0 | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **offset**: starting index for `x`. | ||
- **offsetX**: starting index for `x`. | ||
|
||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the minimum value for every other value in `x` starting from the second value | ||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on a starting indices. For example, to calculate the minimum value for every other value in `x` starting from the second value | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
|
||
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, NaN, NaN, 2.0, 3.0, 4.0 ]; | ||
var N = floor( x.length / 2 ); | ||
|
||
var v = nanmin.ndarray( N, x, 2, 1 ); | ||
var v = nanmin.ndarray( 5, x, 2, 1 ); | ||
// returns -2.0 | ||
``` | ||
|
||
|
@@ -120,6 +109,7 @@ var v = nanmin.ndarray( N, x, 2, 1 ); | |
## Notes | ||
|
||
- If `N <= 0`, both functions return `NaN`. | ||
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). | ||
- Depending on the environment, the typed versions ([`dnanmin`][@stdlib/stats/base/dnanmin], [`snanmin`][@stdlib/stats/base/snanmin], etc.) are likely to be significantly more performant. | ||
|
||
</section> | ||
|
@@ -133,22 +123,12 @@ var v = nanmin.ndarray( N, x, 2, 1 ); | |
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var randu = require( '@stdlib/random/base/randu' ); | ||
var round = require( '@stdlib/math/base/special/round' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
var nanmin = require( '@stdlib/stats/base/nanmin' ); | ||
|
||
var x; | ||
var i; | ||
|
||
x = new Float64Array( 10 ); | ||
for ( i = 0; i < x.length; i++ ) { | ||
if ( randu() < 0.2 ) { | ||
x[ i ] = NaN; | ||
} else { | ||
x[ i ] = round( (randu()*100.0) - 50.0 ); | ||
} | ||
} | ||
var x = discreteUniform( 10, -50, 50, { | ||
|
||
'dtype': 'float64' | ||
}); | ||
console.log( x ); | ||
|
||
var v = nanmin( x.length, x, 1 ); | ||
|
@@ -194,6 +174,8 @@ console.log( v ); | |
|
||
[@stdlib/stats/base/snanmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanmin | ||
|
||
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
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
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
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
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
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
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.