Return the corresponding reduction function.
(method)
| 42 | return mask |
| 43 | |
| 44 | def reduce_func(method): |
| 45 | """Return the corresponding reduction function.""" |
| 46 | if method == 'sum': |
| 47 | return torch.sum |
| 48 | elif method == 'mean': |
| 49 | return torch.mean |
| 50 | elif method == 'count': |
| 51 | return lambda x: sum(x.size()) |
| 52 | else: |
| 53 | raise NotImplementedError() |
| 54 | |
| 55 | def attr_grad(tensor, reduce='sum'): |
| 56 | """Calculate attribute gradient.""" |
no outgoing calls
no test coverage detected