-
Notifications
You must be signed in to change notification settings - Fork 188
Addition of a subroutine to compute the median of array elements #426
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
Changes from 23 commits
8dddff4
dbc16af
5d38d82
935949e
d506f4a
2bc1a8b
ac1a2a2
fdfd150
b19c537
8ed99fe
0d46361
bad19f8
3342c6a
929d5c1
7e3111e
dfea79d
8f4a57f
4f43ce5
6644140
2ca833a
e0f68ed
3eb4e4a
de2c419
9bbcb74
f17b890
391c658
afc92a2
4d328dc
bdb47b7
227f021
9d38d9d
cbdc4ac
a13c700
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#:set RANKS = range(1, MAXRANK + 1) | ||
#:set REDRANKS = range(2, MAXRANK + 1) | ||
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES | ||
#:set IR_KINDS_TYPES_OUTPUT = list(zip(REAL_KINDS, REAL_TYPES, REAL_KINDS)) + list(zip(INT_KINDS,INT_TYPES, ['dp']*len(INT_KINDS))) | ||
jvdp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
module stdlib_stats | ||
!! Provides support for various statistical methods. This includes currently | ||
!! descriptive statistics | ||
|
@@ -11,14 +12,14 @@ module stdlib_stats | |
implicit none | ||
private | ||
! Public API | ||
public :: corr, cov, mean, moment, var | ||
public :: corr, cov, mean, median, moment, var | ||
|
||
|
||
interface corr | ||
!! version: experimental | ||
!! | ||
!! Pearson correlation of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#description)) | ||
!! ([Specification](../page/specs/stdlib_stats.html#corr-pearson-correlation-of-array-elements)) | ||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:set RName = rname("corr",1, t1, k1) | ||
module function ${RName}$(x, dim, mask) result(res) | ||
|
@@ -110,7 +111,7 @@ module stdlib_stats | |
!! version: experimental | ||
!! | ||
!! Covariance of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#description_1)) | ||
!! ([Specification](../page/specs/stdlib_stats.html#cov-covariance-of-array-elements)) | ||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:set RName = rname("cov",1, t1, k1) | ||
module function ${RName}$(x, dim, mask, corrected) result(res) | ||
|
@@ -209,7 +210,7 @@ module stdlib_stats | |
!! version: experimental | ||
!! | ||
!! Mean of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#description_2)) | ||
!! ([Specification](../page/specs/stdlib_stats.html#mean-mean-of-array-elements)) | ||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:for rank in RANKS | ||
#:set RName = rname("mean_all",rank, t1, k1) | ||
|
@@ -305,11 +306,65 @@ module stdlib_stats | |
end interface mean | ||
|
||
|
||
interface median | ||
!! version: experimental | ||
!! | ||
!! Median of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#median-median-of-array-elements)) | ||
#:for k1, t1, o1 in IR_KINDS_TYPES_OUTPUT | ||
#:for rank in RANKS | ||
#:set RName = rname("median_all",rank, t1, k1, o1) | ||
module function ${RName}$ (x, mask) result(res) | ||
jvdp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
${t1}$, intent(in) :: x${ranksuffix(rank)}$ | ||
logical, intent(in), optional :: mask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a question. I couldn't really grasp the purpose of median with the scalar optional mask? The false case will always give NaN, and the true case is the same as having no mask, right? Is the use case supposed to be something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, I'm confused about this as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to be in agreement with the API of the intrinsic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is indeed the case for SUM. It would be interesting to learn the output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The functions For |
||
real(${o1}$) :: res | ||
end function ${RName}$ | ||
#:endfor | ||
#:endfor | ||
|
||
#:for k1, t1, o1 in IR_KINDS_TYPES_OUTPUT | ||
#:for rank in RANKS | ||
#:set RName = rname("median",rank, t1, k1, o1) | ||
module function ${RName}$(x, dim, mask) result(res) | ||
${t1}$, intent(in) :: x${ranksuffix(rank)}$ | ||
integer, intent(in) :: dim | ||
logical, intent(in), optional :: mask | ||
real(${o1}$) :: res${reduced_shape('x', rank, 'dim')}$ | ||
end function ${RName}$ | ||
#:endfor | ||
#:endfor | ||
|
||
#:for k1, t1, o1 in IR_KINDS_TYPES_OUTPUT | ||
#:for rank in RANKS | ||
#:set RName = rname('median_mask_all',rank, t1, k1, o1) | ||
jvdp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
module function ${RName}$(x, mask) result(res) | ||
${t1}$, intent(in) :: x${ranksuffix(rank)}$ | ||
logical, intent(in) :: mask${ranksuffix(rank)}$ | ||
real(${o1}$) :: res | ||
end function ${RName}$ | ||
#:endfor | ||
#:endfor | ||
|
||
#:for k1, t1, o1 in IR_KINDS_TYPES_OUTPUT | ||
#:for rank in RANKS | ||
#:set RName = rname('median_mask',rank, t1, k1, o1) | ||
module function ${RName}$(x, dim, mask) result(res) | ||
${t1}$, intent(in) :: x${ranksuffix(rank)}$ | ||
integer, intent(in) :: dim | ||
logical, intent(in) :: mask${ranksuffix(rank)}$ | ||
real(${o1}$) :: res${reduced_shape('x', rank, 'dim')}$ | ||
end function ${RName}$ | ||
#:endfor | ||
#:endfor | ||
|
||
end interface | ||
|
||
|
||
interface var | ||
!! version: experimental | ||
!! | ||
!! Variance of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#description_4)) | ||
!! ([Specification](../page/specs/stdlib_stats.html#var-variance-of-array-elements)) | ||
|
||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:for rank in RANKS | ||
|
@@ -418,7 +473,7 @@ module stdlib_stats | |
!! version: experimental | ||
!! | ||
!! Central moment of array elements | ||
!! ([Specification](../page/specs/stdlib_stats.html#description_3)) | ||
!! ([Specification](../page/specs/stdlib_stats.html#moment-central-moments-of-array-elements)) | ||
#:for k1, t1 in RC_KINDS_TYPES | ||
#:for rank in RANKS | ||
#:set RName = rname("moment_all",rank, t1, k1) | ||
|
Uh oh!
There was an error while loading. Please reload this page.