(self, a, axis=None)
| 2159 | return torch.mean(a) |
| 2160 | |
| 2161 | def median(self, a, axis=None): |
| 2162 | from packaging import version |
| 2163 | |
| 2164 | # Since version 1.11.0, interpolation is available |
| 2165 | if version.parse(torch.__version__) >= version.parse("1.11.0"): |
| 2166 | if axis is not None: |
| 2167 | return torch.quantile(a, 0.5, interpolation="midpoint", dim=axis) |
| 2168 | else: |
| 2169 | return torch.quantile(a, 0.5, interpolation="midpoint") |
| 2170 | |
| 2171 | # Else, use numpy |
| 2172 | warnings.warn( |
| 2173 | "The median is being computed using numpy and the array has been detached " |
| 2174 | "in the Pytorch backend." |
| 2175 | ) |
| 2176 | a_ = self.to_numpy(a) |
| 2177 | a_median = np.median(a_, axis=axis) |
| 2178 | return self.from_numpy(a_median, type_as=a) |
| 2179 | |
| 2180 | def std(self, a, axis=None): |
| 2181 | if axis is not None: |
nothing calls this directly
no test coverage detected