Skip to content

Commit

Permalink
np.broadcast_shapes not available for Python 3.7 conda -min
Browse files Browse the repository at this point in the history
This reverts commit 7b39673.
  • Loading branch information
reepoi committed Aug 3, 2023
1 parent 7b39673 commit 5446267
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pvlib/pvsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ def v_from_i(current, photocurrent, saturation_current, resistance_series,
V = _singlediode.bishop88_v_from_i(*args, method=method.lower())
if all(map(np.isscalar, args)):
return V
shape = np.broadcast_shapes(*map(np.shape, args))
shape = _singlediode._shape_of_max_size(*args)
return np.broadcast_to(V, shape)


Expand Down Expand Up @@ -2744,7 +2744,7 @@ def i_from_v(voltage, photocurrent, saturation_current, resistance_series,
current = _singlediode.bishop88_i_from_v(*args, method=method.lower())
if all(map(np.isscalar, args)):
return current
shape = np.broadcast_shapes(*map(np.shape, args))
shape = _singlediode._shape_of_max_size(*args)
return np.broadcast_to(current, shape)


Expand Down
7 changes: 6 additions & 1 deletion pvlib/singlediode.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ def fmpp(x, *a):
return bishop88(vd, *args)


def _shape_of_max_size(*args):
return max(((np.size(a), np.shape(a)) for a in args),
key=lambda t: t[0])[1]


def _prepare_newton_inputs(x0, args, method_kwargs):
"""
Make inputs compatible with Scipy's newton by:
Expand All @@ -620,7 +625,7 @@ def _prepare_newton_inputs(x0, args, method_kwargs):
"""
if not (np.isscalar(x0) and all(map(np.isscalar, args))):
args = tuple(map(np.asarray, args))
x0 = np.broadcast_to(x0, np.broadcast_shapes(*map(np.shape, args)))
x0 = np.broadcast_to(x0, _shape_of_max_size(x0, *args))

# set abs tolerance and maxiter from method_kwargs if not provided
# apply defaults, but giving priority to user-specified values
Expand Down

0 comments on commit 5446267

Please sign in to comment.