@@ -287,10 +287,9 @@ def bishop88_i_from_v(voltage, photocurrent, saturation_current,
287
287
... method_kwargs={'full_output': True})
288
288
"""
289
289
# collect args
290
- args_numeric = (photocurrent , saturation_current , resistance_series ,
291
- resistance_shunt , nNsVth , d2mutau , NsVbi )
292
- args_scalar = (breakdown_factor , breakdown_voltage , breakdown_exp )
293
- args = args_numeric + args_scalar
290
+ args = (photocurrent , saturation_current ,
291
+ resistance_series , resistance_shunt , nNsVth , d2mutau , NsVbi ,
292
+ breakdown_factor , breakdown_voltage , breakdown_exp )
294
293
method = method .lower ()
295
294
296
295
# method_kwargs create dict if not provided
@@ -320,10 +319,8 @@ def vd_from_brent(voc, v, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
320
319
vd_from_brent_vectorized = np .vectorize (vd_from_brent )
321
320
vd = vd_from_brent_vectorized (voc_est , voltage , * args )
322
321
elif method == 'newton' :
323
- x0 , (voltage , * args_numeric ), method_kwargs = \
324
- _prepare_newton_inputs (voltage , [voltage , * args_numeric ],
325
- method_kwargs )
326
- args = tuple (args_numeric ) + args_scalar
322
+ x0 , (voltage , * args ), method_kwargs = \
323
+ _prepare_newton_inputs (voltage , (voltage , * args ), method_kwargs )
327
324
vd = newton (func = lambda x , * a : fv (x , voltage , * a ), x0 = x0 ,
328
325
fprime = lambda x , * a : bishop88 (x , * a , gradients = True )[4 ],
329
326
args = args , ** method_kwargs )
@@ -422,10 +419,9 @@ def bishop88_v_from_i(current, photocurrent, saturation_current,
422
419
... method_kwargs={'full_output': True})
423
420
"""
424
421
# collect args
425
- args_numeric = (photocurrent , saturation_current , resistance_series ,
426
- resistance_shunt , nNsVth , d2mutau , NsVbi )
427
- args_scalar = (breakdown_factor , breakdown_voltage , breakdown_exp )
428
- args = args_numeric + args_scalar
422
+ args = (photocurrent , saturation_current ,
423
+ resistance_series , resistance_shunt , nNsVth , d2mutau , NsVbi ,
424
+ breakdown_factor , breakdown_voltage , breakdown_exp )
429
425
method = method .lower ()
430
426
431
427
# method_kwargs create dict if not provided
@@ -455,10 +451,8 @@ def vd_from_brent(voc, i, iph, isat, rs, rsh, gamma, d2mutau, NsVbi,
455
451
vd_from_brent_vectorized = np .vectorize (vd_from_brent )
456
452
vd = vd_from_brent_vectorized (voc_est , current , * args )
457
453
elif method == 'newton' :
458
- x0 , (current , * args_numeric ), method_kwargs = \
459
- _prepare_newton_inputs (voc_est , [current , * args_numeric ],
460
- method_kwargs )
461
- args = tuple (args_numeric ) + args_scalar
454
+ x0 , (current , * args ), method_kwargs = \
455
+ _prepare_newton_inputs (voc_est , (current , * args ), method_kwargs )
462
456
vd = newton (func = lambda x , * a : fi (x , current , * a ), x0 = x0 ,
463
457
fprime = lambda x , * a : bishop88 (x , * a , gradients = True )[3 ],
464
458
args = args , ** method_kwargs )
@@ -555,10 +549,9 @@ def bishop88_mpp(photocurrent, saturation_current, resistance_series,
555
549
... method='newton', method_kwargs={'full_output': True})
556
550
"""
557
551
# collect args
558
- args_numeric = (photocurrent , saturation_current , resistance_series ,
559
- resistance_shunt , nNsVth , d2mutau , NsVbi )
560
- args_scalar = (breakdown_factor , breakdown_voltage , breakdown_exp )
561
- args = args_numeric + args_scalar
552
+ args = (photocurrent , saturation_current ,
553
+ resistance_series , resistance_shunt , nNsVth , d2mutau , NsVbi ,
554
+ breakdown_factor , breakdown_voltage , breakdown_exp )
562
555
method = method .lower ()
563
556
564
557
# method_kwargs create dict if not provided
@@ -585,9 +578,8 @@ def fmpp(x, *a):
585
578
elif method == 'newton' :
586
579
# make sure all args are numpy arrays if max size > 1
587
580
# if voc_est is an array, then make a copy to use for initial guess, v0
588
- x0 , args_numeric , method_kwargs = \
589
- _prepare_newton_inputs (voc_est , args_numeric , method_kwargs )
590
- args = tuple (args_numeric ) + args_scalar
581
+ x0 , args , method_kwargs = \
582
+ _prepare_newton_inputs (voc_est , args , method_kwargs )
591
583
vd = newton (func = fmpp , x0 = x0 ,
592
584
fprime = lambda x , * a : bishop88 (x , * a , gradients = True )[7 ],
593
585
args = args , ** method_kwargs )
@@ -604,28 +596,9 @@ def fmpp(x, *a):
604
596
return bishop88 (vd , * args )
605
597
606
598
607
- def _get_size_and_shape (args ):
608
- # find the right size and shape for returns
609
- size , shape = 0 , None # 0 or None both mean scalar
610
- for arg in args :
611
- try :
612
- this_shape = arg .shape # try to get shape
613
- except AttributeError :
614
- this_shape = None
615
- try :
616
- this_size = len (arg ) # try to get the size
617
- except TypeError :
618
- this_size = 0
619
- else :
620
- this_size = arg .size # if it has shape then it also has size
621
- if shape is None :
622
- shape = this_shape # set the shape if None
623
- # update size and shape
624
- if this_size > size :
625
- size = this_size
626
- if this_shape is not None :
627
- shape = this_shape
628
- return size , shape
599
+ def _shape_of_max_size (* args ):
600
+ return max (((np .size (a ), np .shape (a )) for a in args ),
601
+ key = lambda t : t [0 ])[1 ]
629
602
630
603
631
604
def _prepare_newton_inputs (x0 , args , method_kwargs ):
@@ -651,7 +624,8 @@ def _prepare_newton_inputs(x0, args, method_kwargs):
651
624
The updated initial guess, arguments, and options for newton.
652
625
"""
653
626
if not (np .isscalar (x0 ) and all (map (np .isscalar , args ))):
654
- x0 , * args = np .broadcast_arrays (x0 , * args )
627
+ args = tuple (map (np .asarray , args ))
628
+ x0 = np .broadcast_to (x0 , _shape_of_max_size (x0 , * args ))
655
629
656
630
# set abs tolerance and maxiter from method_kwargs if not provided
657
631
# apply defaults, but giving priority to user-specified values
0 commit comments