clenspy.utils.scalar_array_output

clenspy.utils.scalar_array_output(method)[source]

Decorator: return a Python scalar if the method’s first positional argument was scalar-like and the result really is a single number; otherwise return the array unchanged.

NOTE: the size check is not belt-and-braces, it is required. A scalar first argument does not imply a scalar result: NfwProfile.fourier with an array m200 and a scalar k legitimately returns one value per halo. The earlier version keyed only on the argument and called .item() unconditionally, which raised ValueError: can only convert an array of size 1 for exactly that call – a real combination, just one no test happened to make.

Parameters:

method (callable) – Method with signature (self, x, ...) returning an array-like.

Returns:

callable – Wrapped method with the same signature.