@@ -74,12 +74,16 @@ def __str__(self):
74
74
output += "Needed %g objective evaluations (at %g points)\n " % (self .nf , self .nx )
75
75
if self .nruns > 1 :
76
76
output += "Did a total of %g runs\n " % self .nruns
77
- if np .size (self .gradient ) < 100 :
77
+ if self . gradient is not None and np .size (self .gradient ) < 100 :
78
78
output += "Approximate gradient = %s\n " % str (self .gradient )
79
+ elif self .gradient is None :
80
+ output += "No gradient available\n "
79
81
else :
80
82
output += "Not showing approximate gradient because it is too long; check self.gradient\n "
81
- if np .size (self .hessian ) < 200 :
83
+ if self . hessian is not None and np .size (self .hessian ) < 200 :
82
84
output += "Approximate Hessian = %s\n " % str (self .hessian )
85
+ elif self .hessian is None :
86
+ output += "No Hessian available\n "
83
87
else :
84
88
output += "Not showing approximate Hessian because it is too long; check self.hessian\n "
85
89
if self .diagnostic_info is not None :
@@ -822,8 +826,10 @@ def solve(objfun, x0, args=(), bounds=None, npt=None, rhobeg=None, rhoend=1e-8,
822
826
exit_msg = exit_info .message (with_stem = True )
823
827
# Un-scale gradient and Hessian
824
828
if scaling_changes is not None :
825
- gradmin = gradmin / scaling_changes [1 ]
826
- hessmin = hessmin / np .outer (scaling_changes [1 ], scaling_changes [1 ])
829
+ if gradmin is not None :
830
+ gradmin = gradmin / scaling_changes [1 ]
831
+ if hessmin is not None :
832
+ hessmin = hessmin / np .outer (scaling_changes [1 ], scaling_changes [1 ])
827
833
results = OptimResults (remove_scaling (xmin , scaling_changes ), fmin , gradmin , hessmin , nf , nx , nruns , exit_flag , exit_msg )
828
834
if params ("logging.save_diagnostic_info" ):
829
835
df = diagnostic_info .to_dataframe (with_xk = params ("logging.save_xk" ))
0 commit comments