Skip to content

Commit 545d7f1

Browse files
honnokgryte
andauthored
Special case when NaNs present in statistical functions (#335)
* Special case NaNs in all statistical functions * Update notes This commit brings the formatting and language in-line with element-wise and array object methods. * Capitalize similar to element-wise and array object docs Co-authored-by: Athan <kgryte@gmail.com>
1 parent 11a3d2c commit 545d7f1

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

spec/API_specification/statistical_functions.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Calculates the maximum value of the input array `x`.
2424
When the number of elements over which to compute the maximum value is zero, the maximum value is implementation-defined. Specification-compliant libraries may choose to error, return a sentinel value (e.g., if `x` is a floating-point input array, return `NaN`), or return the minimum possible value for the input array `x` data type (e.g., if `x` is a floating-point array, return `-infinity`).
2525
```
2626

27+
#### Special Cases
28+
29+
For floating-point operands,
30+
31+
- If `x_i` is `NaN`, the maximum value is `NaN` (i.e., `NaN` values propagate).
32+
2733
#### Parameters
2834

2935
- **x**: _&lt;array&gt;_
@@ -51,9 +57,10 @@ Calculates the arithmetic mean of the input array `x`.
5157

5258
#### Special Cases
5359

54-
For a floating-point input array `x`, let `N` equal the number of elements over which to compute the arithmetic mean and
60+
Let `N` equal the number of elements over which to compute the arithmetic mean.
5561

56-
- if `N` is `0`, the arithmetic mean is `NaN`.
62+
- If `N` is `0`, the arithmetic mean is `NaN`.
63+
- If `x_i` is `NaN`, the arithmetic mean is `NaN` (i.e., `NaN` values propagate).
5764

5865
#### Parameters
5966

@@ -88,6 +95,12 @@ Calculates the minimum value of the input array `x`.
8895
When the number of elements over which to compute the minimum value is zero, the minimum value is implementation-defined. Specification-compliant libraries may choose to error, return a sentinel value (e.g., if `x` is a floating-point input array, return `NaN`), or return the maximum possible value for the input array `x` data type (e.g., if `x` is a floating-point array, return `+infinity`).
8996
```
9097

98+
#### Special Cases
99+
100+
For floating-point operands,
101+
102+
- If `x_i` is `NaN`, the minimum value is `NaN` (i.e., `NaN` values propagate).
103+
91104
#### Parameters
92105

93106
- **x**: _&lt;array&gt;_
@@ -115,9 +128,13 @@ Calculates the product of input array `x` elements.
115128

116129
#### Special Cases
117130

118-
For an input array `x`, let `N` equal the number of elements over which to compute the product and
131+
Let `N` equal the number of elements over which to compute the product.
132+
133+
- If `N` is `0`, the product is `1` (i.e., the empty product).
119134

120-
- if `N` is `0`, the product is `1` (i.e., the empty product).
135+
For floating-point operands,
136+
137+
- If `x_i` is `NaN`, the product is `NaN` (i.e., `NaN` values propagate).
121138

122139
#### Parameters
123140

@@ -161,9 +178,10 @@ Calculates the standard deviation of the input array `x`.
161178
162179
#### Special Cases
163180
164-
For a floating-point input array `x`, let `N` equal the number of elements over which to compute the standard deviation and
181+
Let `N` equal the number of elements over which to compute the standard deviation.
165182
166-
- if `N - correction` is less than or equal to `0`, the standard deviation is `NaN`.
183+
- If `N - correction` is less than or equal to `0`, the standard deviation is `NaN`.
184+
- If `x_i` is `NaN`, the standard deviation is `NaN` (i.e., `NaN` values propagate).
167185
168186
#### Parameters
169187
@@ -200,9 +218,13 @@ Calculates the sum of the input array `x`.
200218
201219
#### Special Cases
202220
203-
For an input array `x`, let `N` equal the number of elements over which to compute the sum and
221+
Let `N` equal the number of elements over which to compute the sum.
222+
223+
- If `N` is `0`, the sum is `0` (i.e., the empty sum).
224+
225+
For floating-point operands,
204226
205-
- if `N` is `0`, the sum is `0` (i.e., the empty sum).
227+
- If `x_i` is `NaN`, the sum is `NaN` (i.e., `NaN` values propagate).
206228
207229
#### Parameters
208230
@@ -246,9 +268,10 @@ Calculates the variance of the input array `x`.
246268
247269
#### Special Cases
248270
249-
For a floating-point input array `x`, let `N` equal the number of elements over which to compute the variance and
271+
Let `N` equal the number of elements over which to compute the variance.
250272
251-
- if `N - correction` is less than or equal to `0`, the variance is `NaN`.
273+
- If `N - correction` is less than or equal to `0`, the variance is `NaN`.
274+
- If `x_i` is `NaN`, the variance is `NaN` (i.e., `NaN` values propagate).
252275
253276
#### Parameters
254277

0 commit comments

Comments
 (0)