Skip to content

Instantly share code, notes, and snippets.

@MaartenBaert
MaartenBaert / numpy_fix_temp_elision.md
Created April 10, 2026 11:55
Fix incorrect temp elision for new-style (NEP 43) user-defined dtypes

Fix incorrect temp elision for new-style (NEP 43) user-defined dtypes

Summary

can_elide_temp() in temp_elide.c incorrectly identifies new-style user-defined dtypes as numeric types eligible for in-place buffer reuse. For large arrays this silently rewrites a*a + b*b into (a*a) += (b*b), which raises a TypeError when the result dtype of the in-place add does not match the pre-allocated buffer.

Root cause

@MaartenBaert
MaartenBaert / numpy_fix_zeros_leak.md
Created April 24, 2026 14:20
Fix memory leak in `np.zeros` when fill-zero loop raises

BUG: Fix memory leak in np.zeros when fill-zero loop raises

Problem

PyArray_NewFromDescr_int in ctors.c leaks the data buffer when a user-defined DType's fill-zero loop raises an error.

This affects any DType that defines a get_fill_zero_loop that can fail — for example, a fixed-point DType whose fill-zero rejects zero because it falls outside the type's representable range.