@@ -74,12 +74,16 @@ def __str__(self):
7474 output += "Needed %g objective evaluations (at %g points)\n " % (self .nf , self .nx )
7575 if self .nruns > 1 :
7676 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 :
7878 output += "Approximate gradient = %s\n " % str (self .gradient )
79+ elif self .gradient is None :
80+ output += "No gradient available\n "
7981 else :
8082 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 :
8284 output += "Approximate Hessian = %s\n " % str (self .hessian )
85+ elif self .hessian is None :
86+ output += "No Hessian available\n "
8387 else :
8488 output += "Not showing approximate Hessian because it is too long; check self.hessian\n "
8589 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,
822826 exit_msg = exit_info .message (with_stem = True )
823827 # Un-scale gradient and Hessian
824828 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 ])
827833 results = OptimResults (remove_scaling (xmin , scaling_changes ), fmin , gradmin , hessmin , nf , nx , nruns , exit_flag , exit_msg )
828834 if params ("logging.save_diagnostic_info" ):
829835 df = diagnostic_info .to_dataframe (with_xk = params ("logging.save_xk" ))
0 commit comments