{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "rel_step"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is not provided, it assigned as "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "EPS**(1/s)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where EPS is determined from the smallest floating point dtype of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "fun(x0)",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "np.finfo(x0.dtype).eps"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", s=2 for '2-point' method and s=3 for '3-point' method. Such relative step approximately minimizes a sum of truncation and round-off errors, see "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Relative steps are used by default. However, absolute steps are used when "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "abs_step is not None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". If any of the absolute or relative steps produces an indistinguishable difference from the original "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "(x0 + dx) - x0 == 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", then a automatic step size is substituted for that particular entry."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A finite difference scheme for '3-point' method is selected automatically. The well-known central difference scheme is used for points sufficiently far from the boundary, and 3-point forward or backward scheme is used for points near the boundary. Both schemes have the second-order accuracy in terms of Taylor expansion. Refer to "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for the formulas of 3-point forward and backward difference schemes."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For dense differencing when m=1 Jacobian is returned with a shape (n,), on the other hand when n=1 Jacobian is returned with a shape (m, 1). Our motivation is the following: a) It handles a case of gradient computation (m=1) in a conventional way. b) It clearly separates these two different cases. b) In all cases np.atleast_2d can be called to get 2-D Jacobian with correct dimensions."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "J",
              "annotation": "{ndarray, sparse array, LinearOperator}",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Finite difference approximation of the Jacobian matrix. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "as_linear_operator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True returns a LinearOperator with shape (m, n). Otherwise it returns a dense array or sparse array depending on how "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "sparsity"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is defined. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "sparsity"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None then a ndarray with shape (m, n) is returned. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "sparsity"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not None returns a csr_array or csr_matrix with shape (m, n) following the array/matrix type of the incoming structure. For sparse arrays and linear operators it is always returned as a 2-D structure. For ndarrays, if m=1 it is returned as a 1-D gradient array with shape (n,)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "info_dict",
              "annotation": "dict",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Dictionary containing extra information about the calculation. The keys include:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "DefList",
                          "__tag": 4033,
                          "children": [
                            {
                              "__type": "DefListItem",
                              "__tag": 4037,
                              "dt": {
                                "__type": "Paragraph",
                                "__tag": 4045,
                                "children": [
                                  {
                                    "__type": "InlineRole",
                                    "__tag": 4003,
                                    "value": "nfev",
                                    "domain": null,
                                    "role": null,
                                    "inventory": null
                                  },
                                  {
                                    "__type": "Text",
                                    "__tag": 4046,
                                    "value": ", number of function evaluations. If "
                                  },
                                  {
                                    "__type": "ParamRef",
                                    "__tag": 4071,
                                    "name": "as_linear_operator"
                                  },
                                  {
                                    "__type": "Text",
                                    "__tag": 4046,
                                    "value": " is True"
                                  }
                                ]
                              },
                              "dd": [
                                {
                                  "__type": "Paragraph",
                                  "__tag": 4045,
                                  "children": [
                                    {
                                      "__type": "Text",
                                      "__tag": 4046,
                                      "value": "then "
                                    },
                                    {
                                      "__type": "ParamRef",
                                      "__tag": 4071,
                                      "name": "fun"
                                    },
                                    {
                                      "__type": "Text",
                                      "__tag": 4046,
                                      "value": " is expected to track the number of evaluations itself.    This is because multiple calls may be made to the linear operator which    are not trackable here."
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute finite difference approximation of the derivatives of a vector-valued function."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "fun",
              "annotation": "callable",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Function of which to estimate the derivatives. The argument x passed to this function is ndarray of shape (n,) (never a scalar even if n=1). It must return 1-D array_like of shape (m,) or a scalar."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x0",
              "annotation": "array_like of shape (n,) or float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Point at which to estimate the derivatives. Float will be converted to a 1-D array."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "method",
              "annotation": "{'3-point', '2-point', 'cs'}, optional",
              "desc": [
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "Finite difference method to use:"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "BulletList",
                          "__tag": 4053,
                          "ordered": false,
                          "start": 1,
                          "children": [
                            {
                              "__type": "ListItem",
                              "__tag": 4054,
                              "children": [
                                {
                                  "__type": "DefList",
                                  "__tag": 4033,
                                  "children": [
                                    {
                                      "__type": "DefListItem",
                                      "__tag": 4037,
                                      "dt": {
                                        "__type": "Paragraph",
                                        "__tag": 4045,
                                        "children": [
                                          {
                                            "__type": "Text",
                                            "__tag": 4046,
                                            "value": "'2-point' - use the first order accuracy forward or backward"
                                          }
                                        ]
                                      },
                                      "dd": [
                                        {
                                          "__type": "Paragraph",
                                          "__tag": 4045,
                                          "children": [
                                            {
                                              "__type": "Text",
                                              "__tag": 4046,
                                              "value": "difference."
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "__type": "ListItem",
                              "__tag": 4054,
                              "children": [
                                {
                                  "__type": "DefList",
                                  "__tag": 4033,
                                  "children": [
                                    {
                                      "__type": "DefListItem",
                                      "__tag": 4037,
                                      "dt": {
                                        "__type": "Paragraph",
                                        "__tag": 4045,
                                        "children": [
                                          {
                                            "__type": "Text",
                                            "__tag": 4046,
                                            "value": "'3-point' - use central difference in interior points and the"
                                          }
                                        ]
                                      },
                                      "dd": [
                                        {
                                          "__type": "Paragraph",
                                          "__tag": 4045,
                                          "children": [
                                            {
                                              "__type": "Text",
                                              "__tag": 4046,
                                              "value": "second order accuracy forward or backward difference                   near the boundary."
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "__type": "ListItem",
                              "__tag": 4054,
                              "children": [
                                {
                                  "__type": "DefList",
                                  "__tag": 4033,
                                  "children": [
                                    {
                                      "__type": "DefListItem",
                                      "__tag": 4037,
                                      "dt": {
                                        "__type": "Paragraph",
                                        "__tag": 4045,
                                        "children": [
                                          {
                                            "__type": "Text",
                                            "__tag": 4046,
                                            "value": "'cs' - use a complex-step finite difference scheme. This assumes"
                                          }
                                        ]
                                      },
                                      "dd": [
                                        {
                                          "__type": "Paragraph",
                                          "__tag": 4045,
                                          "children": [
                                            {
                                              "__type": "Text",
                                              "__tag": 4046,
                                              "value": "that the user function is real-valued and can be              analytically continued to the complex plane. Otherwise,              produces bogus results."
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rel_step",
              "annotation": "None or array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Relative step size to use. If None (default) the absolute step size is computed as "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "h = rel_step * sign(x0) * max(1, abs(x0))"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rel_step"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " being selected automatically, see Notes. Otherwise "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "h = rel_step * sign(x0) * abs(x0)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". For "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "method='3-point'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " the sign of "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "h",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is ignored. The calculated step size is possibly adjusted to fit into the bounds."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "abs_step",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Absolute step size to use, possibly adjusted to fit into the bounds. For "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "method='3-point'"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " the sign of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "abs_step"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is ignored. By default relative steps are used, only if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "abs_step is not None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are absolute steps used."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "f0",
              "annotation": "None or array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If not None it is assumed to be equal to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fun(x0)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", in this case the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fun(x0)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not called. Default is None."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "bounds",
              "annotation": "tuple of array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Lower and upper bounds on independent variables. Defaults to no bounds. Each bound must match the size of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or be a scalar, in the latter case the bound will be the same for all variables. Use it to limit the range of function evaluation. Bounds checking is not implemented when "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "as_linear_operator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "sparsity",
              "annotation": "{None, array_like, sparse array, 2-tuple}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Defines a sparsity structure of the Jacobian matrix. If the Jacobian matrix is known to have only few non-zero elements in each row, then it's possible to estimate its several columns by a single function evaluation "
                    },
                    {
                      "__type": "FootnoteReference",
                      "__tag": 4066,
                      "label": "3"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". To perform such economic computations two ingredients are required:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "structurearray_like or sparse array of shape (m, n). A zero   element means that a corresponding element of the Jacobian   identically equals to zero."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "groupsarray_like of shape (n,). A column grouping for a given   sparsity structure, use "
                            },
                            {
                              "__type": "CrossRef",
                              "__tag": 4002,
                              "value": "group_columns",
                              "reference": {
                                "__type": "LocalRef",
                                "__tag": 4022,
                                "kind": "module",
                                "path": "scipy.optimize._numdiff:group_columns"
                              },
                              "kind": "module"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " to obtain it."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A single array or a sparse array is interpreted as a sparsity structure, and groups are computed inside the function. A tuple is interpreted as (structure, groups). If None (default), a standard dense differencing will be used."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Note, that sparse differencing makes sense only for large Jacobian matrices where each row contains few non-zero elements."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "as_linear_operator",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "When True the function returns an "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.sparse.linalg.LinearOperator",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.sparse.linalg._interface:LinearOperator"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Otherwise it returns a dense array or a sparse array depending on "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "sparsity"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". The linear operator provides an efficient way of computing "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "J.dot(p)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for any vector "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "p"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " of shape (n,), but does not allow direct access to individual elements of the matrix. By default "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "as_linear_operator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "args, kwargs",
              "annotation": "tuple and dict, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Additional arguments passed to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fun"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Both empty by default. The calling signature is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "fun(x, *args, **kwargs)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "full_output",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True then the function also returns a dictionary with extra information about the calculation."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "workers",
              "annotation": "int or map-like callable, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Supply a map-like callable, such as "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "multiprocessing.Pool.map",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for evaluating the population in parallel. This evaluation is carried out as "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "workers(fun, iterable)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Alternatively, if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "workers"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is an int the task is subdivided into "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "workers"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " sections and the fun evaluated in parallel (uses "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "multiprocessing.Pool <multiprocessing>",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "). Supply -1 to use all available CPU cores. It is recommended that a map-like be used instead of int, as repeated calls to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "approx_derivative",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.optimize._numdiff:approx_derivative"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " will incur large overhead from setting up new processes."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If a function maps from R^n to R^m, its derivatives form m-by-n matrix called the Jacobian, where an element (i, j) is a partial derivative of f[i] with respect to x[j]."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/optimize/_numdiff.py",
  "item_line": 278,
  "item_type": "function",
  "aliases": [
    "scipy.optimize._differentiable_functions.approx_derivative"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.optimize._numdiff import approx_derivative\ndef f(x, c1, c2):\n    return np.array([x[0] * np.sin(c1 * x[1]),\n                     x[0] * np.cos(c2 * x[1])])\nx0 = np.array([1.0, 0.5 * np.pi])\napprox_derivative(f, x0, args=(1, 2))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nBounds can be used to limit the region of function evaluation.\nIn the example below we compute left and right derivative at point 1.0.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def g(x):\n    return x**2 if x >= 1 else x\nx0 = 1.0\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "approx_derivative(g, x0, bounds=(-np.inf, 1.0))\napprox_derivative(g, x0, bounds=(1.0, np.inf))\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWe can also parallelize the derivative calculation using the workers\nkeyword.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from multiprocessing import Pool\nimport time\ndef fun2(x):       # import from an external file for use with multiprocessing\n    time.sleep(0.002)\n    return rosen(x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "rng = np.random.default_rng()\nx0 = rng.uniform(high=10, size=(2000,))\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "f0 = rosen(x0)\n",
        "execution_status": "unexpected_exception"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "%timeit approx_derivative(fun2, x0, f0=f0)     # may vary\n",
        "execution_status": "unexpected_exception"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "elapsed = []\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "with Pool() as workers:\n    for i in range(10):\n        t = time.perf_counter()\n        approx_derivative(fun2, x0, workers=workers.map, f0=f0)\n        et = time.perf_counter()\n        elapsed.append(et - t)\n",
        "execution_status": "unexpected_exception"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "np.mean(elapsed)    # may vary\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nCreate a map-like vectorized version. `x` is a generator, so first of all\na 2-D array, `xx`, is reconstituted. Here `xx` has shape `(Y, N)` where `Y`\nis the number of function evaluations to perform and `N` is the dimensionality\nof the objective function. The underlying objective function is `rosen`, which\nrequires `xx` to have shape `(N, Y)`, so a transpose is required.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def fun(f, x, *args, **kwds):\n    xx = np.r_[[xs for xs in x]]\n    return f(xx.T)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "%timeit approx_derivative(fun2, x0, workers=fun, f0=f0)    # may vary\n",
        "execution_status": "unexpected_exception"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "check_derivative",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.optimize._numdiff:check_derivative"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Check correctness of a function computing derivatives."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "fun",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x0",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "method",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "3-point"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rel_step",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "abs_step",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "f0",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "bounds",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "(-inf, inf)"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "sparsity",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "as_linear_operator",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "args",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "()"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "kwargs",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "full_output",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "workers",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "approx_derivative"
  },
  "references": [
    ".. [1] W. H. Press et. al. \"Numerical Recipes. The Art of Scientific",
    "       Computing. 3rd edition\", sec. 5.7.",
    "",
    ".. [2] A. Curtis, M. J. D. Powell, and J. Reid, \"On the estimation of",
    "       sparse Jacobian matrices\", Journal of the Institute of Mathematics",
    "       and its Applications, 13 (1974), pp. 117-120.",
    "",
    ".. [3] B. Fornberg, \"Generation of Finite Difference Formulas on",
    "       Arbitrarily Spaced Grids\", Mathematics of Computation 51, 1988."
  ],
  "qa": "scipy.optimize._numdiff:approx_derivative",
  "arbitrary": [],
  "local_refs": [
    "J",
    "abs_step",
    "args",
    "as_linear_operator",
    "bounds",
    "f0",
    "full_output",
    "fun",
    "info_dict",
    "kwargs",
    "method",
    "rel_step",
    "sparsity",
    "workers",
    "x0"
  ]
}