Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Convert PyArray_Functions to generalized ufuncs #12514

Copy link
Copy link
Open
@teoliphant

Description

@teoliphant
Issue body actions

typedef struct {
/*
* Functions to cast to most other standard types
* Can have some NULL entries. The types
* DATETIME, TIMEDELTA, and HALF go into the castdict
* even though they are built-in.
*/
PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
/* The next four functions *cannot* be NULL */
/*
* Functions to get and set items with standard Python types
* -- not array scalars
*/
PyArray_GetItemFunc *getitem;
PyArray_SetItemFunc *setitem;
/*
* Copy and/or swap data. Memory areas may not overlap
* Use memmove first if they might
*/
PyArray_CopySwapNFunc *copyswapn;
PyArray_CopySwapFunc *copyswap;
/*
* Function to compare items
* Can be NULL
*/
PyArray_CompareFunc *compare;
/*
* Function to select largest
* Can be NULL
*/
PyArray_ArgFunc *argmax;
/*
* Function to compute dot product
* Can be NULL
*/
PyArray_DotFunc *dotfunc;
/*
* Function to scan an ASCII file and
* place a single value plus possible separator
* Can be NULL
*/
PyArray_ScanFunc *scanfunc;
/*
* Function to read a single value from a string
* and adjust the pointer; Can be NULL
*/
PyArray_FromStrFunc *fromstr;
/*
* Function to determine if data is zero or not
* If NULL a default version is
* used at Registration time.
*/
PyArray_NonzeroFunc *nonzero;
/*
* Used for arange. Should return 0 on success
* and -1 on failure.
* Can be NULL.
*/
PyArray_FillFunc *fill;
/*
* Function to fill arrays with scalar values
* Can be NULL
*/
PyArray_FillWithScalarFunc *fillwithscalar;
/*
* Sorting functions
* Can be NULL
*/
PyArray_SortFunc *sort[NPY_NSORTS];
PyArray_ArgSortFunc *argsort[NPY_NSORTS];
/*
* Dictionary of additional casting functions
* PyArray_VectorUnaryFuncs
* which can be populated to support casting
* to other registered types. Can be NULL
*/
PyObject *castdict;
/*
* Functions useful for generalizing
* the casting rules.
* Can be NULL;
*/
PyArray_ScalarKindFunc *scalarkind;
int **cancastscalarkindto;
int *cancastto;
PyArray_FastClipFunc *fastclip;
PyArray_FastPutmaskFunc *fastputmask;
PyArray_FastTakeFunc *fasttake;
/*
* Function to select smallest
* Can be NULL
*/
PyArray_ArgFunc *argmin;
} PyArray_ArrFuncs;

I believe that most of the functions in this list should be replaced by generalized ufuncs and this list of function pointers shrunk.

In theory, the PyArray_Descr structure could then become a meta-type in Python parlance ("inheriting" from PyHeapTypeObject ala https://stackoverflow.com/questions/1237266/how-can-inheritance-be-modelled-using-c) and adding remaining fields needed by NumPy. All dtypes would then be "real" Python types --- but we don't need these extra functions.

In particular, the following functions should be (generalized) ufuncs --- others can likely be as well with a bit more thought.

This kind of refactor would break the ABI and I would suggest including only in a major release. It would be facilitated by an improved ufunc dispatching system for NumPy as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.