feat: add C implementation for stats/base/ndarray/dnanmidrange#10203
feat: add C implementation for stats/base/ndarray/dnanmidrange#10203bhargava-d16 wants to merge 12 commits intostdlib-js:developfrom
stats/base/ndarray/dnanmidrange#10203Conversation
Signed-off-by: Bhargav Dabhade <bhargava2005dabhade@gmail.com>
---
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: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- 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: missing_dependencies
- task: lint_c_examples
status: missing_dependencies
- task: lint_c_benchmarks
status: missing_dependencies
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
---
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: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: missing_dependencies
- 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: na
- task: lint_license_headers
status: passed
---
---
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: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: missing_dependencies
- 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: na
- task: lint_license_headers
status: passed
---
|
@Planeshifter Just a gentle follow-up on this PR. |
| #include "stdlib/stats/base/ndarray/dnanmidrange.h" | ||
| ``` | ||
|
|
||
| stdlib_stats_dnanmidrange( arrays ) |
There was a problem hiding this comment.
This needs to be formatted as a #### heading to match our convention for C function signatures. See, e.g., the dmax README for reference.
| stdlib_stats_dnanmidrange( arrays ) | |
| #### stdlib_stats_dnanmidrange( arrays ) |
| #include <stdint.h> | ||
|
|
||
| // Create an ndarray: | ||
| const double data[] = { 1.0, NaN, -2.0, 3.0, -4.0 }; |
There was a problem hiding this comment.
NaN isn't valid C -- the correct macro is NAN (from <math.h>). You'll also need to add #include <math.h> to this code block (similar to how you did it in the actual .c files).
| const double data[] = { 1.0, NaN, -2.0, 3.0, -4.0 }; | |
| const double data[] = { 1.0, NAN, -2.0, 3.0, -4.0 }; |
There was a problem hiding this comment.
Instead of using NAN, we should prefer the expression 0.0/0.0 and remove the math.h include, as Athan mentioned here: 5a64342#r179146895
|
|
||
| int main( void ) { | ||
| // Create a data buffer (includes NaN): | ||
| const double data[] = { 1.0, -2.0, 3.0, NaN, 5.0, -6.0, 7.0, -8.0 }; |
There was a problem hiding this comment.
Same thing here -- NaN should be NAN.
| const double data[] = { 1.0, -2.0, 3.0, NaN, 5.0, -6.0, 7.0, -8.0 }; | |
| const double data[] = { 1.0, -2.0, 3.0, NAN, 5.0, -6.0, 7.0, -8.0 }; |
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
| var opts = { | ||
| 'skip': ( dnanmidrange instanceof Error ) | ||
| }; |
There was a problem hiding this comment.
| var opts = { | |
| 'skip': ( dnanmidrange instanceof Error ) | |
| }; | |
| var opts = { | |
| 'skip': ( dnanmidrange instanceof Error ) | |
| }; | |
| var options = { | |
| 'dtype': 'float64' | |
| }; |
| var x; | ||
|
|
||
| xbuf = filledarrayBy( len, 'float64', rand ); | ||
| x = new ndarray( 'float64', xbuf, [ len ], [ 1 ], 0, 'row-major' ); |
There was a problem hiding this comment.
| x = new ndarray( 'float64', xbuf, [ len ], [ 1 ], 0, 'row-major' ); | |
| x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); |
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
|
|
||
| int main( void ) { | ||
| // Create a data buffer: | ||
| const double data[] = { 1.0, -2.0, 3.0, -4.0, NAN, 5.0, 0.0, 3.0 }; |
There was a problem hiding this comment.
| const double data[] = { 1.0, -2.0, 3.0, -4.0, NAN, 5.0, 0.0, 3.0 }; | |
| const double data[] = { 1.0, -2.0, 3.0, -4.0, 0.0/0.0, 5.0, 0.0, 3.0 }; |
We could do this.
| #include <stdint.h> | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <math.h> |
There was a problem hiding this comment.
| #include <math.h> |
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com>
|
|
||
| stdlib_stats_dnanmidrange( arrays ) | ||
|
|
||
| Computes the mid-range of a one-dimensional double-precision floating-point ndarray, ignoring NaN values. |
There was a problem hiding this comment.
| Computes the mid-range of a one-dimensional double-precision floating-point ndarray, ignoring NaN values. | |
| Computes the [mid-range][mid-range] of a one-dimensional double-precision floating-point ndarray, ignoring NaN values. |
| #include <stdio.h> | ||
|
|
||
| int main( void ) { | ||
| // Create a data buffer (includes NaN): |
There was a problem hiding this comment.
| // Create a data buffer (includes NaN): | |
| // Create a data buffer: |
| const int64_t nsubmodes = 1; | ||
|
|
||
| // Create an ndarray: | ||
| struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); |
There was a problem hiding this comment.
| struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); | |
| struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); |
| // Define a list of ndarrays: | ||
| const struct ndarray *arrays[] = { x }; | ||
|
|
||
| // Compute the NaN-ignoring midrange: |
There was a problem hiding this comment.
| // Compute the NaN-ignoring midrange: | |
| // Compute the mid-range: |
| double v = stdlib_stats_dnanmidrange( arrays ); | ||
|
|
||
| // Print the result: | ||
| printf( "midrange: %lf\n", v ); |
There was a problem hiding this comment.
| printf( "midrange: %lf\n", v ); | |
| printf( "mid-range: %lf\n", v ); |
|
/stdlib merge |
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves None
Description
This pull request:
Related Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
@stdlib-js/reviewers