A zeros_like implementation based on calloc instead of copyto

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

A zeros_like implementation based on calloc instead of copyto

hmaarrfk
Hello,

Currently, `zeros_like` is based `copyto` as opposed to `calloc`.
This causes inconsistencies in the amount of time it takes to create an array with `zeros` + `shape` and `zeros_like` for large arrays.

It seems to me that a memory copy can be avoided by using `PyArray_NewFromDescr_int` in C.

I propose creating a new C_API function `PyArray_NewZerosLikeArray` that behaves much like the `PyArray_NewLikeArray` with the exception that it calls
`PyArray_NewFromDescr_int` instead of `PyArray_NewFromDescr` to initialize the array to zeros with calloc.

An all C implementation of `zeros_like` is also possible by adapting the `empty_like` function.

A draft implementation is viewable https://github.com/hmaarrfk/numpy/pull/2/files for those looking for more details about my proposed implementation.

Thank you for considering.

Mark

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion