@@ -221,17 +221,19 @@ def evaluate(expr, parameters={}, rng=None, array_format=FORMAT_NUMPY, verbose=F
221
221
if array_format == FORMAT_TENSORFLOW :
222
222
import tensorflow as tf
223
223
224
- print_ (
225
- " > Evaluating: [%s] which is a: %s, vs parameters: %s (using %s arrays)..."
226
- % (expr , type (expr ).__name__ , _params_info (parameters ), array_format ),
227
- verbose ,
228
- )
224
+ if verbose :
225
+ print_ (
226
+ " > Evaluating: [%s] which is a: %s, vs parameters: %s (using %s arrays)..."
227
+ % (expr , type (expr ).__name__ , _params_info (parameters ), array_format ),
228
+ verbose ,
229
+ )
229
230
try :
230
231
if type (expr ) == str and expr in parameters :
231
232
expr = parameters [
232
233
expr
233
234
] # replace with the value in parameters & check whether it's float/int...
234
- print_ ("Using for that param: %s" % _val_info (expr ), verbose )
235
+ if verbose :
236
+ print_ ("Using for that param: %s" % _val_info (expr ), verbose )
235
237
236
238
if type (expr ) == str :
237
239
try :
@@ -250,33 +252,39 @@ def evaluate(expr, parameters={}, rng=None, array_format=FORMAT_NUMPY, verbose=F
250
252
pass
251
253
252
254
if type (expr ) == list :
253
- print_ ("Returning a list in format: %s" % array_format , verbose )
255
+ if verbose :
256
+ print_ ("Returning a list in format: %s" % array_format , verbose )
254
257
if array_format == FORMAT_TENSORFLOW :
255
258
return tf .constant (expr , dtype = tf .float64 )
256
259
else :
257
260
return np .array (expr )
258
261
259
262
if type (expr ) == np .ndarray :
260
- print_ ("Returning a numpy array in format: %s" % array_format , verbose )
263
+ if verbose :
264
+ print_ ("Returning a numpy array in format: %s" % array_format , verbose )
261
265
if array_format == FORMAT_TENSORFLOW :
262
266
return tf .convert_to_tensor (expr , dtype = tf .float64 )
263
267
else :
264
268
return np .array (expr )
265
269
266
270
if "Tensor" in type (expr ).__name__ :
267
- print_ (
268
- "Returning a tensorflow Tensor in format: %s" % array_format , verbose
269
- )
271
+ if verbose :
272
+ print_ (
273
+ "Returning a tensorflow Tensor in format: %s" % array_format ,
274
+ verbose ,
275
+ )
270
276
if array_format == FORMAT_NUMPY :
271
277
return expr .numpy ()
272
278
else :
273
279
return expr
274
280
275
281
if int (expr ) == expr :
276
- print_ ("Returning int: %s" % int (expr ), verbose )
282
+ if verbose :
283
+ print_ ("Returning int: %s" % int (expr ), verbose )
277
284
return int (expr )
278
285
else : # will have failed if not number
279
- print_ ("Returning float: %s" % expr , verbose )
286
+ if verbose :
287
+ print_ ("Returning float: %s" % expr , verbose )
280
288
return float (expr )
281
289
except :
282
290
try :
@@ -289,24 +297,33 @@ def evaluate(expr, parameters={}, rng=None, array_format=FORMAT_NUMPY, verbose=F
289
297
if type (expr ) == str and "numpy." in expr :
290
298
parameters ["numpy" ] = np
291
299
292
- print_ (
293
- "Trying to eval [%s] with Python using %s..."
294
- % (expr , parameters .keys ()),
295
- verbose ,
296
- )
300
+ if verbose :
301
+ print_ (
302
+ "Trying to eval [%s] with Python using %s..."
303
+ % (expr , parameters .keys ()),
304
+ verbose ,
305
+ )
297
306
298
307
v = eval (expr , parameters )
299
- print_ ("Evaluated with Python: {} = {}" .format (expr , _val_info (v )), verbose )
308
+
309
+ if verbose :
310
+ print_ (
311
+ "Evaluated with Python: {} = {}" .format (expr , _val_info (v )), verbose
312
+ )
313
+
300
314
if (type (v ) == float or type (v ) == str ) and int (v ) == v :
301
- print_ ("Returning int: %s" % int (v ), verbose )
315
+
316
+ if verbose :
317
+ print_ ("Returning int: %s" % int (v ), verbose )
302
318
303
319
if array_format == FORMAT_TENSORFLOW :
304
320
return tf .constant (int (v ))
305
321
else :
306
322
return int (v )
307
323
return v
308
324
except Exception as e :
309
- print_ (f"Returning without altering: { expr } (error: { e } )" , verbose )
325
+ if verbose :
326
+ print_ (f"Returning without altering: { expr } (error: { e } )" , verbose )
310
327
return expr
311
328
312
329
0 commit comments