{ } Raw JSON

bundles / scipy 1.17.1 / scipy / _lib / _elementwise_iterative_method / _loop

function

scipy._lib._elementwise_iterative_method:_loop

source: /scipy/_lib/_elementwise_iterative_method.py :128

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 : _RichResult

All variables that need to be retained between iterations. Must contain attributes nit, nfev, and success. All arrays are subject to being "compressed" if preserve_shape is False; nest arrays that should not be compressed inside another object (e.g. dict or _RichResult).

callback : callable

User-specified callback function

shape : tuple of ints

The shape of all output arrays

maxiter

Maximum number of iterations of the algorithm

func : callable

The user-specified callable that is being optimized or solved

args : tuple

Additional positional arguments to be passed to func.

dtype : NumPy dtype

The common dtype of all abscissae and function values

pre_func_eval : callable

A function that accepts work and returns x, the active elements of x at which func will be evaluated. May modify attributes of work with any algorithmic steps that need to happen at the beginning of an iteration, before func is evaluated,

post_func_eval : callable

A function that accepts x, func(x), and work. May modify attributes of work with any algorithmic steps that need to happen in the middle of an iteration, after func is evaluated but before the termination check.

check_termination : callable

A function that accepts work and returns stop, a boolean array indicating which of the active elements have met a termination condition.

post_termination_check : callable

A function that accepts work. May modify work with any algorithmic steps that need to happen after the termination check and before the end of the iteration.

customize_result : callable

A function that accepts res and shape and returns shape. May modify res (in-place) according to preferences (e.g. rearrange elements between attributes) and modify shape if needed.

res_work_pairs : list of (str, str)

Identifies correspondence between attributes of res and attributes of work; i.e., attributes of active elements of work will 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: False

Whether to compress the attributes of work (to avoid unnecessary computation on elements that have already converged).

Returns

res : _RichResult

The 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 work to eliminate unnecessary computation on elements that have already converged.

Aliases

  • scipy.differentiate.eim._loop