| 2664 | return cp.unique(a, return_inverse=return_inverse) |
| 2665 | |
| 2666 | def logsumexp(self, a, axis=None): |
| 2667 | # Taken from |
| 2668 | # https://github.com/scipy/scipy/blob/v1.7.1/scipy/special/_logsumexp.py#L7-L127 |
| 2669 | a_max = cp.amax(a, axis=axis, keepdims=True) |
| 2670 | |
| 2671 | if a_max.ndim > 0: |
| 2672 | a_max[~cp.isfinite(a_max)] = 0 |
| 2673 | elif not cp.isfinite(a_max): |
| 2674 | a_max = 0 |
| 2675 | |
| 2676 | tmp = cp.exp(a - a_max) |
| 2677 | s = cp.sum(tmp, axis=axis) |
| 2678 | out = cp.log(s) |
| 2679 | a_max = cp.squeeze(a_max, axis=axis) |
| 2680 | out += a_max |
| 2681 | return out |
| 2682 | |
| 2683 | def stack(self, arrays, axis=0): |
| 2684 | return cp.stack(arrays, axis) |