MCPcopy
hub / github.com/tensorflow/tfjs / arrayStats

Function arrayStats

tfjs-vis/src/util/math.ts:29–90  ·  view source on GitHub ↗
(input: number[])

Source from the content-addressed store, hash-verified

27 * @param input
28 */
29export function arrayStats(input: number[]): HistogramStats {
30 if (!Array.isArray(input)) {
31 throw new Error('input must be an array');
32 }
33 if (input.length === 0) {
34 return {
35 numVals: 0,
36 numNans: 0,
37 numZeros: 0,
38 max: undefined,
39 min: undefined,
40 };
41 }
42
43 const numVals = input.length;
44 let max = -Infinity;
45 let min = Infinity;
46 let numZeros = 0;
47 let numNans = 0;
48 let numInfs = 0;
49
50 for (let i = 0; i < numVals; i++) {
51 const curr = input[i];
52 if (curr > max) {
53 max = curr;
54 }
55
56 if (curr < min) {
57 min = curr;
58 }
59
60 if (curr === 0) {
61 numZeros += 1;
62 }
63
64 if (isNaN(curr)) {
65 numNans += 1;
66 } else if (!isFinite(curr)) {
67 // Make sure NaNs are not double counted as Infs
68 numInfs += 1;
69 }
70 }
71
72 const result = {
73 numVals,
74 numZeros,
75 numNans,
76 max,
77 min,
78 numInfs,
79 };
80
81 // Handle all NaN input
82 if (result.max === -Infinity) {
83 result.max = NaN;
84 }
85 if (result.min === Infinity) {
86 result.min = NaN;

Callers 2

histogramFunction · 0.90
math_test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…