bundles / scipy 1.17.1 / scipy / _lib / _elementwise_iterative_method / _loop
function
scipy._lib._elementwise_iterative_method:_loop
Signature
def _loop ( work , callback , shape , maxiter , func , args , dtype , pre_func_eval , post_func_eval , check_termination , post_termination_check , customize_result , res_work_pairs , xp , preserve_shape = False ) Summary
Main loop of a vectorized scalar optimization algorithm
Parameters
work: _RichResultAll variables that need to be retained between iterations. Must contain attributes
nit,nfev, andsuccess. All arrays are subject to being "compressed" ifpreserve_shape is False; nest arrays that should not be compressed inside another object (e.g.dictor _RichResult).callback: callableUser-specified callback function
shape: tuple of intsThe shape of all output arrays
maxiterMaximum number of iterations of the algorithm
func: callableThe user-specified callable that is being optimized or solved
args: tupleAdditional positional arguments to be passed to
func.dtype: NumPy dtypeThe common dtype of all abscissae and function values
pre_func_eval: callableA function that accepts
workand returnsx, the active elements ofxat whichfuncwill be evaluated. May modify attributes ofworkwith any algorithmic steps that need to happen at the beginning of an iteration, beforefuncis evaluated,post_func_eval: callableA function that accepts
x,func(x), andwork. May modify attributes ofworkwith any algorithmic steps that need to happen in the middle of an iteration, afterfuncis evaluated but before the termination check.check_termination: callableA function that accepts
workand returnsstop, a boolean array indicating which of the active elements have met a termination condition.post_termination_check: callableA function that accepts
work. May modifyworkwith any algorithmic steps that need to happen after the termination check and before the end of the iteration.customize_result: callableA function that accepts res and
shapeand returnsshape. May modify res (in-place) according to preferences (e.g. rearrange elements between attributes) and modifyshapeif needed.res_work_pairs: list of (str, str)Identifies correspondence between attributes of res and attributes of
work; i.e., attributes of active elements ofworkwill be copied to the appropriate indices of res when appropriate. The order determines the order in which _RichResult attributes will be pretty-printed.preserve_shape: bool, default: FalseWhether to compress the attributes of
work(to avoid unnecessary computation on elements that have already converged).
Returns
res: _RichResultThe final result object
Notes
Besides providing structure, this framework provides several important services for a vectorized optimization algorithm.
It handles common tasks involving iteration count, function evaluation count, a user-specified callback, and associated termination conditions.
It compresses the attributes of
workto eliminate unnecessary computation on elements that have already converged.
Aliases
-
scipy.differentiate.eim._loop