Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Replace find_common_types #16398

Merged
merged 1 commit into from Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion scipy/linalg/_special_matrices.py
Expand Up @@ -538,7 +538,7 @@ def block_diag(*arrs):
"greater than 2: %s" % bad_args)

shapes = np.array([a.shape for a in arrs])
out_dtype = np.find_common_type([arr.dtype for arr in arrs], [])
out_dtype = np.result_type(*[arr.dtype for arr in arrs])
out = np.zeros(np.sum(shapes, axis=0), dtype=out_dtype)

r, c = 0, 0
Expand Down
6 changes: 3 additions & 3 deletions scipy/signal/_ltisys.py
Expand Up @@ -1414,7 +1414,7 @@ def __mul__(self, other):
c = self.C
d = np.dot(self.D, other)

common_dtype = np.find_common_type((a.dtype, b.dtype, c.dtype, d.dtype), ())
common_dtype = np.result_type(a.dtype, b.dtype, c.dtype, d.dtype)
return StateSpace(np.asarray(a, dtype=common_dtype),
np.asarray(b, dtype=common_dtype),
np.asarray(c, dtype=common_dtype),
Expand All @@ -1432,7 +1432,7 @@ def __rmul__(self, other):
c = np.dot(other, self.C)
d = np.dot(other, self.D)

common_dtype = np.find_common_type((a.dtype, b.dtype, c.dtype, d.dtype), ())
common_dtype = np.result_type(a.dtype, b.dtype, c.dtype, d.dtype)
return StateSpace(np.asarray(a, dtype=common_dtype),
np.asarray(b, dtype=common_dtype),
np.asarray(c, dtype=common_dtype),
Expand Down Expand Up @@ -1487,7 +1487,7 @@ def __add__(self, other):
"dimensions ({} and {})"
.format(self.D.shape, other.shape))

common_dtype = np.find_common_type((a.dtype, b.dtype, c.dtype, d.dtype), ())
common_dtype = np.result_type(a.dtype, b.dtype, c.dtype, d.dtype)
return StateSpace(np.asarray(a, dtype=common_dtype),
np.asarray(b, dtype=common_dtype),
np.asarray(c, dtype=common_dtype),
Expand Down
2 changes: 1 addition & 1 deletion scipy/sparse/_sputils.py
Expand Up @@ -40,7 +40,7 @@ def upcast(*args):
if t is not None:
return t

upcast = np.find_common_type(args, [])
upcast = np.result_type(*args)

for t in supported_dtypes:
if np.can_cast(upcast, t):
Expand Down
2 changes: 1 addition & 1 deletion scipy/sparse/linalg/_interface.py
Expand Up @@ -598,7 +598,7 @@ def _get_dtype(operators, dtypes=None):
for obj in operators:
if obj is not None and hasattr(obj, 'dtype'):
dtypes.append(obj.dtype)
return np.find_common_type(dtypes, [])
return np.result_type(*dtypes)


class _SumLinearOperator(LinearOperator):
Expand Down
2 changes: 1 addition & 1 deletion scipy/sparse/linalg/_matfuncs.py
Expand Up @@ -225,7 +225,7 @@ def __init__(self, *args, **kwargs):
'must all have the same shape.')
self.shape = (n, n)
self.ndim = len(self.shape)
self.dtype = np.find_common_type([x.dtype for x in args], [])
self.dtype = np.result_type(*[x.dtype for x in args])
self._operator_sequence = args

def _matvec(self, x):
Expand Down
6 changes: 3 additions & 3 deletions scipy/spatial/distance.py
Expand Up @@ -155,7 +155,7 @@ def _nbool_correspond_all(u, v, w=None):
ntf = (u & not_v).sum()
ntt = (u & v).sum()
else:
dtype = np.find_common_type([int], [u.dtype, v.dtype])
dtype = np.result_type(int, u.dtype, v.dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this can change the result in some cases, but in practice I can't think of a way to make it fail when the first part is [int]...
(in that case u.dtype == longdouble is honored. A change would happen there if the first part was a float/complex, where the longdouble would then be ignored.)

u = u.astype(dtype)
v = v.astype(dtype)
not_u = 1.0 - u
Expand All @@ -177,7 +177,7 @@ def _nbool_correspond_ft_tf(u, v, w=None):
nft = (not_u & v).sum()
ntf = (u & not_v).sum()
else:
dtype = np.find_common_type([int], [u.dtype, v.dtype])
dtype = np.result_type(int, u.dtype, v.dtype)
u = u.astype(dtype)
v = v.astype(dtype)
not_u = 1.0 - u
Expand Down Expand Up @@ -1395,7 +1395,7 @@ def dice(u, v, w=None):
if u.dtype == v.dtype == bool and w is None:
ntt = (u & v).sum()
else:
dtype = np.find_common_type([int], [u.dtype, v.dtype])
dtype = np.result_type(int, u.dtype, v.dtype)
u = u.astype(dtype)
v = v.astype(dtype)
if w is None:
Expand Down
12 changes: 6 additions & 6 deletions scipy/stats/_distn_infrastructure.py
Expand Up @@ -2095,7 +2095,7 @@ def pdf(self, x, *args, **kwds):
args, loc, scale = self._parse_args(*args, **kwds)
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._support_mask(x, *args) & (scale > 0)
Expand Down Expand Up @@ -2136,7 +2136,7 @@ def logpdf(self, x, *args, **kwds):
args, loc, scale = self._parse_args(*args, **kwds)
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._support_mask(x, *args) & (scale > 0)
Expand Down Expand Up @@ -2178,7 +2178,7 @@ def cdf(self, x, *args, **kwds):
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
_a, _b = self._get_support(*args)
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._open_support_mask(x, *args) & (scale > 0)
Expand Down Expand Up @@ -2219,7 +2219,7 @@ def logcdf(self, x, *args, **kwds):
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
_a, _b = self._get_support(*args)
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._open_support_mask(x, *args) & (scale > 0)
Expand Down Expand Up @@ -2261,7 +2261,7 @@ def sf(self, x, *args, **kwds):
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
_a, _b = self._get_support(*args)
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._open_support_mask(x, *args) & (scale > 0)
Expand Down Expand Up @@ -2305,7 +2305,7 @@ def logsf(self, x, *args, **kwds):
x, loc, scale = map(asarray, (x, loc, scale))
args = tuple(map(asarray, args))
_a, _b = self._get_support(*args)
dtyp = np.find_common_type([x.dtype, np.float64], [])
dtyp = np.promote_types(x.dtype, np.float64)
x = np.asarray((x - loc)/scale, dtype=dtyp)
cond0 = self._argcheck(*args) & (scale > 0)
cond1 = self._open_support_mask(x, *args) & (scale > 0)
Expand Down