1 | #Region "Microsoft.VisualBasic::c1a1f76f654366fd8bcf170990abd897, Microsoft.VisualBasic.Core\Extensions\Math\StatisticsMathExtensions\Linq\EnumerableStatsRange.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module EnumerableStatsRange |
35 | ' |
36 | ' Function: (+20 Overloads) Range |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Imports System.Runtime.CompilerServices |
44 | |
45 | Namespace Math.Statistics.Linq |
46 | |
47 | Public Module EnumerableStatsRange |
48 | ' ' Summary: |
49 | ' Computes the Range of a sequence of nullable System.Decimal values. |
50 | ' ' Parameters: |
51 | ' source: |
52 | ' A sequence of nullable System.Decimal values to calculate the Range of. |
53 | ' ' Returns: |
54 | ' The Range of the sequence of values, or null if the source sequence is |
55 | ' empty or contains only values that are null. |
56 | ' ' Exceptions: |
57 | ' System.ArgumentNullException: |
58 | ' source is null. |
59 | ' ' System.OverflowException: |
60 | ' The sum of the elements in the sequence is larger than System.Decimal.MaxValue. |
61 | <Extension> |
62 | Public Function Range(source As IEnumerable(Of Decimal?)) As Decimal |
63 | Dim values As IEnumerable(Of Decimal) = source.Coalesce() |
64 | If values.Any() Then |
65 | Return values.Range() |
66 | End If |
67 | |
68 | Return Nothing |
69 | End Function |
70 | ' ' Summary: |
71 | ' Computes the Range of a sequence of System.Decimal values. |
72 | ' ' Parameters: |
73 | ' source: |
74 | ' A sequence of System.Decimal values to calculate the Range of. |
75 | ' ' Returns: |
76 | ' The Range of the sequence of values. |
77 | ' ' Exceptions: |
78 | ' System.ArgumentNullException: |
79 | ' source is null. |
80 | ' ' System.InvalidOperationException: |
81 | ' source contains no elements. |
82 | ' ' System.OverflowException: |
83 | ' The sum of the elements in the sequence is larger than System.Decimal.MaxValue. |
84 | <Extension> |
85 | Public Function Range(source As IEnumerable(Of Decimal)) As Decimal |
86 | Return source.Max() - source.Min() |
87 | End Function |
88 | ' ' Summary: |
89 | ' Computes the Range of a sequence of nullable System.Double values. |
90 | ' ' Parameters: |
91 | ' source: |
92 | ' A sequence of nullable System.Double values to calculate the Range of. |
93 | ' ' Returns: |
94 | ' The Range of the sequence of values, or null if the source sequence is |
95 | ' empty or contains only values that are null. |
96 | ' ' Exceptions: |
97 | ' System.ArgumentNullException: |
98 | ' source is null. |
99 | <Extension> |
100 | Public Function Range(source As IEnumerable(Of Double?)) As Double |
101 | Dim values As IEnumerable(Of Double) = source.Coalesce() |
102 | If values.Any() Then |
103 | Return values.Range() |
104 | End If |
105 | |
106 | Return Nothing |
107 | End Function |
108 | ' ' Summary: |
109 | ' Computes the Range of a sequence of System.Double values. |
110 | ' ' Parameters: |
111 | ' source: |
112 | ' A sequence of System.Double values to calculate the Range of. |
113 | ' ' Returns: |
114 | ' The Range of the sequence of values. |
115 | ' ' Exceptions: |
116 | ' System.ArgumentNullException: |
117 | ' source is null. |
118 | ' ' System.InvalidOperationException: |
119 | ' source contains no elements. |
120 | <Extension> |
121 | Public Function Range(source As IEnumerable(Of Double)) As Double |
122 | Return source.Max() - source.Min() |
123 | End Function |
124 | ' ' Summary: |
125 | ' Computes the Range of a sequence of nullable System.Single values. |
126 | ' ' Parameters: |
127 | ' source: |
128 | ' A sequence of nullable System.Single values to calculate the Range of. |
129 | ' ' Returns: |
130 | ' The Range of the sequence of values, or null if the source sequence is |
131 | ' empty or contains only values that are null. |
132 | ' ' Exceptions: |
133 | ' System.ArgumentNullException: |
134 | ' source is null. |
135 | <Extension> |
136 | Public Function Range(source As IEnumerable(Of Single?)) As Single |
137 | Dim values As IEnumerable(Of Single) = source.Coalesce() |
138 | If values.Any() Then |
139 | Return values.Range() |
140 | End If |
141 | |
142 | Return Nothing |
143 | End Function |
144 | ' ' Summary: |
145 | ' Computes the Range of a sequence of System.Single values. |
146 | ' ' Parameters: |
147 | ' source: |
148 | ' A sequence of System.Single values to calculate the Range of. |
149 | ' ' Returns: |
150 | ' The Range of the sequence of values. |
151 | ' ' Exceptions: |
152 | ' System.ArgumentNullException: |
153 | ' source is null. |
154 | ' ' System.InvalidOperationException: |
155 | ' source contains no elements. |
156 | <Extension> |
157 | Public Function Range(source As IEnumerable(Of Single)) As Single |
158 | Return source.Max() - source.Min() |
159 | End Function |
160 | ' ' Summary: |
161 | ' Computes the Range of a sequence of nullable System.Int32 values. |
162 | ' ' Parameters: |
163 | ' source: |
164 | ' A sequence of nullable System.Int32values to calculate the Range of. |
165 | ' ' Returns: |
166 | ' The Range of the sequence of values, or null if the source sequence is |
167 | ' empty or contains only values that are null. |
168 | ' ' Exceptions: |
169 | ' System.ArgumentNullException: |
170 | ' source is null. |
171 | ' ' System.OverflowException: |
172 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
173 | <Extension> |
174 | Public Function Range(source As IEnumerable(Of Integer?)) As Integer |
175 | Dim values As IEnumerable(Of Integer) = source.Coalesce() |
176 | If values.Any() Then |
177 | Return values.Range() |
178 | End If |
179 | |
180 | Return Nothing |
181 | End Function |
182 | ' ' Summary: |
183 | ' Computes the Range of a sequence of System.Int32 values. |
184 | ' ' Parameters: |
185 | ' source: |
186 | ' A sequence of System.Int32 values to calculate the Range of. |
187 | ' ' Returns: |
188 | ' The Range of the sequence of values. |
189 | ' ' Exceptions: |
190 | ' System.ArgumentNullException: |
191 | ' source is null. |
192 | ' ' System.InvalidOperationException: |
193 | ' source contains no elements. |
194 | ' ' System.OverflowException: |
195 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
196 | <Extension> |
197 | Public Function Range(source As IEnumerable(Of Integer)) As Integer |
198 | Return source.Max() - source.Min() |
199 | End Function |
200 | ' ' Summary: |
201 | ' Computes the Range of a sequence of nullable System.Int64 values. |
202 | ' ' Parameters: |
203 | ' source: |
204 | ' A sequence of nullable System.Int64 values to calculate the Range of. |
205 | ' ' Returns: |
206 | ' The Range of the sequence of values, or null if the source sequence is |
207 | ' empty or contains only values that are null. |
208 | ' ' Exceptions: |
209 | ' System.ArgumentNullException: |
210 | ' source is null. |
211 | ' ' System.OverflowException: |
212 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
213 | <Extension> |
214 | Public Function Range(source As IEnumerable(Of Long?)) As Long |
215 | Dim values As IEnumerable(Of Long) = source.Coalesce() |
216 | If values.Any() Then |
217 | Return values.Range() |
218 | End If |
219 | |
220 | Return Nothing |
221 | End Function |
222 | ' ' Summary: |
223 | ' Computes the Range of a sequence of System.Int64 values. |
224 | ' ' Parameters: |
225 | ' source: |
226 | ' A sequence of System.Int64 values to calculate the Range of. |
227 | ' ' Returns: |
228 | ' The Range of the sequence of values. |
229 | ' ' Exceptions: |
230 | ' System.ArgumentNullException: |
231 | ' source is null. |
232 | ' ' System.InvalidOperationException: |
233 | ' source contains no elements. |
234 | ' ' System.OverflowException: |
235 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
236 | <Extension> |
237 | Public Function Range(source As IEnumerable(Of Long)) As Long |
238 | Return source.Max() - source.Min() |
239 | End Function |
240 | ' ' Summary: |
241 | ' Computes the Range of a sequence of nullable System.Decimal values that |
242 | ' are obtained by invoking a transform function on each element of the input |
243 | ' sequence. |
244 | ' ' Parameters: |
245 | ' source: |
246 | ' A sequence of values to calculate the Range of. |
247 | ' ' selector: |
248 | ' A transform function to apply to each element. |
249 | ' ' Type parameters: |
250 | ' TSource: |
251 | ' The type of the elements of source. |
252 | ' ' Returns: |
253 | ' The Range of the sequence of values, or null if the source sequence is |
254 | ' empty or contains only values that are null. |
255 | ' ' Exceptions: |
256 | ' System.ArgumentNullException: |
257 | ' source or selector is null. |
258 | ' ' System.OverflowException: |
259 | ' The sum of the elements in the sequence is larger than System.Decimal.MaxValue. |
260 | <Extension> |
261 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal?)) As Decimal |
262 | Return source.[Select](selector).Range() |
263 | End Function |
264 | ' ' Summary: |
265 | ' Computes the Range of a sequence of System.Decimal values that are obtained |
266 | ' by invoking a transform function on each element of the input sequence. |
267 | ' ' Parameters: |
268 | ' source: |
269 | ' A sequence of values that are used to calculate an Range. |
270 | ' ' selector: |
271 | ' A transform function to apply to each element. |
272 | ' ' Type parameters: |
273 | ' TSource: |
274 | ' The type of the elements of source. |
275 | ' ' Returns: |
276 | ' The Range of the sequence of values. |
277 | ' ' Exceptions: |
278 | ' System.ArgumentNullException: |
279 | ' source or selector is null. |
280 | ' ' System.InvalidOperationException: |
281 | ' source contains no elements. |
282 | ' ' System.OverflowException: |
283 | ' The sum of the elements in the sequence is larger than System.Decimal.MaxValue. |
284 | <Extension> |
285 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal)) As Decimal |
286 | Return source.[Select](selector).Range() |
287 | End Function |
288 | ' ' Summary: |
289 | ' Computes the Range of a sequence of nullable System.Double values that |
290 | ' are obtained by invoking a transform function on each element of the input |
291 | ' sequence. |
292 | ' ' Parameters: |
293 | ' source: |
294 | ' A sequence of values to calculate the Range of. |
295 | ' ' selector: |
296 | ' A transform function to apply to each element. |
297 | ' ' Type parameters: |
298 | ' TSource: |
299 | ' The type of the elements of source. |
300 | ' ' Returns: |
301 | ' The Range of the sequence of values, or null if the source sequence is |
302 | ' empty or contains only values that are null. |
303 | ' ' Exceptions: |
304 | ' System.ArgumentNullException: |
305 | ' source or selector is null. |
306 | <Extension> |
307 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Double?)) As Double |
308 | Return source.[Select](selector).Range() |
309 | End Function |
310 | ' ' Summary: |
311 | ' Computes the Range of a sequence of System.Double values that are obtained |
312 | ' by invoking a transform function on each element of the input sequence. |
313 | ' ' Parameters: |
314 | ' source: |
315 | ' A sequence of values to calculate the Range of. |
316 | ' ' selector: |
317 | ' A transform function to apply to each element. |
318 | ' ' Type parameters: |
319 | ' TSource: |
320 | ' The type of the elements of source. |
321 | ' ' Returns: |
322 | ' The Range of the sequence of values. |
323 | ' ' Exceptions: |
324 | ' System.ArgumentNullException: |
325 | ' source or selector is null. |
326 | ' ' System.InvalidOperationException: |
327 | ' source contains no elements. |
328 | <Extension> |
329 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Double)) As Double |
330 | Return source.[Select](selector).Range() |
331 | End Function |
332 | ' ' Summary: |
333 | ' Computes the Range of a sequence of nullable System.Single values that |
334 | ' are obtained by invoking a transform function on each element of the input |
335 | ' sequence. |
336 | ' ' Parameters: |
337 | ' source: |
338 | ' A sequence of values to calculate the Range of. |
339 | ' ' selector: |
340 | ' A transform function to apply to each element. |
341 | ' ' Type parameters: |
342 | ' TSource: |
343 | ' The type of the elements of source. |
344 | ' ' Returns: |
345 | ' The Range of the sequence of values, or null if the source sequence is |
346 | ' empty or contains only values that are null. |
347 | ' ' Exceptions: |
348 | ' System.ArgumentNullException: |
349 | ' source or selector is null. |
350 | <Extension> |
351 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Single?)) As Single |
352 | Return source.[Select](selector).Range() |
353 | End Function |
354 | ' ' Summary: |
355 | ' Computes the Range of a sequence of System.Single values that are obtained |
356 | ' by invoking a transform function on each element of the input sequence. |
357 | ' ' Parameters: |
358 | ' source: |
359 | ' A sequence of values to calculate the Range of. |
360 | ' ' selector: |
361 | ' A transform function to apply to each element. |
362 | ' ' Type parameters: |
363 | ' TSource: |
364 | ' The type of the elements of source. |
365 | ' ' Returns: |
366 | ' The Range of the sequence of values. |
367 | ' ' Exceptions: |
368 | ' System.ArgumentNullException: |
369 | ' source or selector is null. |
370 | ' ' System.InvalidOperationException: |
371 | ' source contains no elements. |
372 | <Extension> |
373 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Single)) As Single |
374 | Return source.[Select](selector).Range() |
375 | End Function |
376 | ' ' Summary: |
377 | ' Computes the Range of a sequence of nullable System.Int32 values that are |
378 | ' obtained by invoking a transform function on each element of the input sequence. |
379 | ' ' Parameters: |
380 | ' source: |
381 | ' A sequence of values to calculate the Range of. |
382 | ' ' selector: |
383 | ' A transform function to apply to each element. |
384 | ' ' Type parameters: |
385 | ' TSource: |
386 | ' The type of the elements of source. |
387 | ' ' Returns: |
388 | ' The Range of the sequence of values, or null if the source sequence is |
389 | ' empty or contains only values that are null. |
390 | ' ' Exceptions: |
391 | ' System.ArgumentNullException: |
392 | ' source or selector is null. |
393 | ' ' System.OverflowException: |
394 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
395 | <Extension> |
396 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer?)) As Double |
397 | Return source.[Select](selector).Range() |
398 | End Function |
399 | ' ' Summary: |
400 | ' Computes the Range of a sequence of System.Int32 values that are obtained |
401 | ' by invoking a transform function on each element of the input sequence. |
402 | ' ' Parameters: |
403 | ' source: |
404 | ' A sequence of values to calculate the Range of. |
405 | ' ' selector: |
406 | ' A transform function to apply to each element. |
407 | ' ' Type parameters: |
408 | ' TSource: |
409 | ' The type of the elements of source. |
410 | ' ' Returns: |
411 | ' The Range of the sequence of values. |
412 | ' ' Exceptions: |
413 | ' System.ArgumentNullException: |
414 | ' source or selector is null. |
415 | ' ' System.InvalidOperationException: |
416 | ' source contains no elements. |
417 | ' ' System.OverflowException: |
418 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
419 | <Extension> |
420 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Double |
421 | Return source.[Select](selector).Range() |
422 | End Function |
423 | ' ' Summary: |
424 | ' Computes the Range of a sequence of nullable System.Int64 values that are |
425 | ' obtained by invoking a transform function on each element of the input sequence. |
426 | ' ' Parameters: |
427 | ' source: |
428 | ' A sequence of values to calculate the Range of. |
429 | ' ' selector: |
430 | ' A transform function to apply to each element. |
431 | ' ' Type parameters: |
432 | ' TSource: |
433 | ' The type of the elements of source. |
434 | ' ' Returns: |
435 | ' The Range of the sequence of values, or null if the source sequence is |
436 | ' empty or contains only values that are null. |
437 | <Extension> |
438 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Long?)) As Double |
439 | Return source.[Select](selector).Range() |
440 | End Function |
441 | ' ' Summary: |
442 | ' Computes the Range of a sequence of System.Int64 values that are obtained |
443 | ' by invoking a transform function on each element of the input sequence. |
444 | ' ' Parameters: |
445 | ' source: |
446 | ' A sequence of values to calculate the Range of. |
447 | ' ' selector: |
448 | ' A transform function to apply to each element. |
449 | ' ' Type parameters: |
450 | ' TSource: |
451 | ' The type of the elements of source. |
452 | ' ' Returns: |
453 | ' The Range of the sequence of values. |
454 | ' ' Exceptions: |
455 | ' System.ArgumentNullException: |
456 | ' source or selector is null. |
457 | ' ' System.InvalidOperationException: |
458 | ' source contains no elements. |
459 | ' ' System.OverflowException: |
460 | ' The sum of the elements in the sequence is larger than System.Int64.MaxValue. |
461 | <Extension> |
462 | Public Function Range(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Long)) As Double |
463 | Return source.[Select](selector).Range() |
464 | End Function |
465 | End Module |
466 | End Namespace |