Skip to content

Commit fa8d850

Browse files
committed
closes #339
1 parent 4a29349 commit fa8d850

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/FSharp.Stats/Array.fs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ module Array =
260260
/// </code>
261261
/// </example>
262262
let inline weightedMean (weights:array<'T>) (items:array<'T>) =
263+
// throws an exception if the collection is empty and the file type is not float (returns nan if float collection)
264+
if items.Length = 0 && not (box items :? float[]) then
265+
failwithf "Array.weightedMean is undefined for an empty non float sequence!"
263266
// DimensionMismatchException
264267
if (items.Length <> weights.Length) then
265268
failwithf "The items and weights must have the same length"
@@ -305,6 +308,10 @@ module Array =
305308
/// </code>
306309
/// </example>
307310
let inline weightedVariance mean (weights:array<'T>) (items:array<'T>) =
311+
// throws an exception if the collection is empty and the file type is not float (returns nan if float collection)
312+
if items.Length = 0 && not (box items :? float[]) then
313+
failwithf "Array.weightedVariance is undefined for an empty non float sequence!"
314+
308315
// DimensionMismatchException
309316
if (items.Length <> weights.Length) then
310317
failwithf "The items and weights must have the same length"
@@ -334,7 +341,10 @@ module Array =
334341
/// <code>
335342
/// </code>
336343
/// </example>
337-
let inline median (items:array<'T>) =
344+
let inline median (items: array<'T>) =
345+
// throws an exception if the collection is empty and the file type is not float (returns nan if float collection)
346+
if items.Length = 0 && not (box items :? float[]) then
347+
failwithf "Array.median is undefined for an empty non float sequence!"
338348

339349
let zero = LanguagePrimitives.GenericZero< 'T >
340350
let one = LanguagePrimitives.GenericOne< 'T >

0 commit comments

Comments
 (0)