(self, val, num=1)
| 40 | self.update(tensor.item(), num=num) |
| 41 | |
| 42 | def update(self, val, num=1): |
| 43 | if self.length > 0: |
| 44 | # currently assert num==1 to avoid bad usage, refine when there are some explict requirements |
| 45 | assert num == 1 |
| 46 | self.history.append(val) |
| 47 | if len(self.history) > self.length: |
| 48 | del self.history[0] |
| 49 | |
| 50 | self.val = self.history[-1] |
| 51 | self.avg = np.mean(self.history) |
| 52 | else: |
| 53 | self.val = val |
| 54 | self.sum += val*num |
| 55 | self.count += num |
| 56 | self.avg = self.sum / self.count |
| 57 | |
| 58 | |
| 59 | def makedir(path): |
no outgoing calls
no test coverage detected