@@ -2100,35 +2100,35 @@ def v_from_i(resistance_shunt, resistance_series, nNsVth, current,
2100
2100
# wrap it so it returns nan
2101
2101
v_from_i_fun = singlediode_methods .returns_nan ()(v_from_i_fun )
2102
2102
# find the right size and shape for returns
2103
- args = (current , photocurrent , resistance_shunt )
2104
- size = 0
2105
- shape = None
2106
- for n , arg in enumerate ( args ) :
2103
+ args = (current , photocurrent , saturation_current ,
2104
+ resistance_series , resistance_shunt , nNsVth )
2105
+ size , shape = 0 , None # 0 or None both mean scalar
2106
+ for arg in args :
2107
2107
try :
2108
- this_shape = arg .shape
2108
+ this_shape = arg .shape # try to get shape
2109
2109
except AttributeError :
2110
2110
this_shape = None
2111
2111
try :
2112
- this_size = len (arg )
2112
+ this_size = len (arg ) # try to get the size
2113
2113
except TypeError :
2114
2114
this_size = 0
2115
2115
else :
2116
- this_size = sum (this_shape )
2116
+ this_size = sum (this_shape ) # calc size from shape
2117
2117
if shape is None :
2118
- shape = this_shape
2119
- if this_size > size and size <= 1 :
2118
+ shape = this_shape # set the shape if None
2119
+ # update size and shape
2120
+ if this_size > size :
2120
2121
size = this_size
2121
2122
if this_shape is not None :
2122
2123
shape = this_shape
2123
2124
if size <= 1 :
2124
- V = v_from_i_fun (current , photocurrent , saturation_current ,
2125
- resistance_series , resistance_shunt , nNsVth )
2125
+ V = v_from_i_fun (* args )
2126
2126
if shape is not None :
2127
2127
V = np .tile (V , shape )
2128
2128
else :
2129
+ # np.vectorize handles broadcasting, raises ValueError
2129
2130
vecfun = np .vectorize (v_from_i_fun )
2130
- V = vecfun (current , photocurrent , saturation_current ,
2131
- resistance_series , resistance_shunt , nNsVth )
2131
+ V = vecfun (* args )
2132
2132
if np .isnan (V ).any () and size <= 1 :
2133
2133
V = np .repeat (V , size )
2134
2134
if shape is not None :
@@ -2270,35 +2270,31 @@ def i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
2270
2270
# find the right size and shape for returns
2271
2271
args = (voltage , photocurrent , saturation_current , resistance_series ,
2272
2272
resistance_shunt , nNsVth )
2273
- size = 0
2274
- shape = None
2275
- for n , arg in enumerate (args ):
2273
+ size , shape = 0 , None # 0 or None both mean scalar
2274
+ for arg in args :
2276
2275
try :
2277
- this_shape = arg .shape
2276
+ this_shape = arg .shape # try to get shape
2278
2277
except AttributeError :
2279
2278
this_shape = None
2280
2279
try :
2281
- this_size = len (arg )
2280
+ this_size = len (arg ) # try to get the size
2282
2281
except TypeError :
2283
2282
this_size = 0
2284
2283
else :
2285
- this_size = sum (this_shape )
2284
+ this_size = sum (this_shape ) # calc size from shape
2286
2285
if shape is None :
2287
- shape = this_shape
2288
- if this_size > size and size <= 1 :
2286
+ shape = this_shape # set the shape if None
2287
+ # update size and shape
2288
+ if this_size > size :
2289
2289
size = this_size
2290
2290
if this_shape is not None :
2291
2291
shape = this_shape
2292
- else :
2293
- msg = ('Argument: "%s" is different size from other arguments'
2294
- ' (%d > %d). All arguments must be the same size or'
2295
- ' scalar.' ) % (arg , this_size , size )
2296
- raise ValueError (msg )
2297
2292
if size <= 1 :
2298
2293
I = i_from_v_fun (* args )
2299
2294
if shape is not None :
2300
2295
I = np .tile (I , shape )
2301
2296
else :
2297
+ # np.vectorize handles broadcasting, raises ValueError
2302
2298
vecfun = np .vectorize (i_from_v_fun )
2303
2299
I = vecfun (* args )
2304
2300
if np .isnan (I ).any () and size <= 1 :
0 commit comments