Convert values into a histogram proto using logic from histogram.cc.
(values)
| 60 | |
| 61 | |
| 62 | def _MakeHistogram(values): |
| 63 | """Convert values into a histogram proto using logic from histogram.cc.""" |
| 64 | limits = _MakeHistogramBuckets() |
| 65 | counts = [0] * len(limits) |
| 66 | for v in values: |
| 67 | idx = bisect.bisect_left(limits, v) |
| 68 | counts[idx] += 1 |
| 69 | |
| 70 | limit_counts = [ |
| 71 | (limits[i], counts[i]) for i in range(len(limits)) if counts[i] |
| 72 | ] |
| 73 | bucket_limit = [lc[0] for lc in limit_counts] |
| 74 | bucket = [lc[1] for lc in limit_counts] |
| 75 | sum_sq = sum(v * v for v in values) |
| 76 | return tf.compat.v1.HistogramProto( |
| 77 | min=min(values), |
| 78 | max=max(values), |
| 79 | num=len(values), |
| 80 | sum=sum(values), |
| 81 | sum_squares=sum_sq, |
| 82 | bucket_limit=bucket_limit, |
| 83 | bucket=bucket, |
| 84 | ) |
| 85 | |
| 86 | |
| 87 | def WriteScalarSeries(writer, tag, f, n=5): |
no test coverage detected
searching dependent graphs…