{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "dev:api-dev:special_ufuncs",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Many of the functions in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "special"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are vectorized versions of scalar functions. The scalar functions are written by hand and the necessary loops for vectorization are generated automatically. This section discusses the steps necessary to add a new vectorized special function."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The first step in adding a new vectorized function is writing the corresponding scalar function. This is done in the "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "xsf repository"
                }
              ],
              "url": "https://github.com/scipy/xsf",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", see "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "here"
                }
              ],
              "url": "https://github.com/scipy/xsf/blob/main/CONTRIBUTING.md",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for further details."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "After implementing the scalar function, create the ufunc in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_special_ufuncs.cpp"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xsf::numpy::ufunc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Add the ufunc's docstring to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_special_ufuncs_docs.cpp"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and add its name to the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "special_ufuncs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " list in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "_generate_pyx.py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". For a public function, also add wrappers to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cython_special_wrappers.cpp"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cython_special_wrappers.h"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and add the function to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cython_special.pyx"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Look in these files for examples."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When writing the parameters section of the documentation for ufuncs, the type of an argument should be "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "array_like"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Discussion of whether an argument can be e.g. real or complex-valued should be saved for the description. So for example, if we were to document the parameters for the Gamma function then it should look like this    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "Parameters\n----------\nz : array_like\n    Real or complex valued argument",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When documenting the returns section, the type of the returned value should be "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scalar or ndarray"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " since ufuncs return scalars when given scalars as arguments. Also keep in mind that providing a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "name"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for the return value is optional, and indeed is often not helpful for special functions. So for the Gamma function we might have something like this    "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "Returns\n-------\nscalar or ndarray\n    Values of the Gamma function",
          "execution_status": null,
          "out": ""
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Adding vectorized ufuncs in "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "scipy.special"
        }
      ],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}