This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / special / _ufunc_tools / _UFuncWrapper / resolve_dtypes

function

scipy.special._ufunc_tools:_UFuncWrapper.resolve_dtypes

source: build-install/usr/lib/python3.14/site-packages/scipy/special/_ufunc_tools.py:377

Signature

def resolve_dtypes(dtypes, *, signature = None, casting = None, reduction = False)

Summary

Find the dtypes NumPy will use for the operation. Both input and output dtypes are returned and may differ from those provided.

Extended Summary

Parameters

dtypes : tuple of dtypes, None, or literal int, float, complex

The input dtypes for each operand. Output operands can be None, indicating that the dtype must be found.

signature : tuple of DTypes or None, optional

If given, enforces exact DType (classes) of the specific operand. The ufunc dtype argument is equivalent to passing a tuple with only output dtypes set.

casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional

The casting mode when casting is necessary. This is identical to the ufunc call casting modes.

reduction : boolean

If given, the resolution assumes a reduce operation is happening which slightly changes the promotion and type resolution rules. dtypes is usually something like (None, np.dtype("i2"), None) for reductions (first input is also the output).

Returns

dtypes : tuple of dtypes

The dtypes which NumPy would use for the calculation. Note that dtypes may not match the passed in ones (casting is necessary).

Examples

This API requires passing dtypes, define them for convenience:
import numpy as np
int32 = np.dtype(np.int32)
float32 = np.dtype(np.float32)
✓
The typical ufunc call does not pass an output dtype. `numpy.add` has two inputs and one output, so leave the output as ``None`` (not provided):
np.add.resolve_dtypes((int32, float32, None))
✓
(dtype('float64'), dtype('float64'), dtype('float64'))
The loop found uses "float64" for all operands (including the output), the first input would be cast. ``resolve_dtypes`` supports "weak" handling for Python scalars by passing ``int``, ``float``, or ``complex``:
np.add.resolve_dtypes((float32, float, None))
✓
(dtype('float32'), dtype('float32'), dtype('float32'))
Where the Python ``float`` behaves similar to a Python value ``0.0`` in a ufunc call. (See :ref:`NEP 50 <NEP50>` for details.)

Aliases

  • scipy.special._ufunc_tools._UFuncWrapper.resolve_dtypes