GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: `ufunc.at()` can cause segfaults if `nin=0` and `nout=1` · Issue #33053 · numpy/numpy

BUG: ufunc.at() can cause segfaults if nin=0 and nout=1 #33053

New issue
Copy link
New issue
Copy link
Closed
#33068
Closed
BUG: ufunc.at() can cause segfaults if nin=0 and nout=1#33053
#33068
Copy link
Labels
00 - Bug

Description

@eerovaher
eerovaher
opened on Oct 15, 2026
Issue body actions

Describe the issue:

The at() method of a ufunc with nin=0 and nout>1 causes a ValueError and the at() method of a gufunc with nin=0 and nout=1 causes a TypeError (it's not clear to me why the error types should differ, but this bug report is not about that). In contrast a ufunc with nin=0 and nout=1 causes a segmentation fault.

Reproduce the code example:

import numpy as np

ufunc_nin0_nout1 = np.frompyfunc(lambda: 0, nin=0, nout=1)
ufunc_nin0_nout1.at(np.empty((1,)), True)

Error message:

Program received signal SIGSEGV, Segmentation fault.
PyArray_CastDescrToDType (descr=0x7ffff71dcf20 <DOUBLE_Descr>, given_DType=0x0)
    at ../numpy/_core/src/multiarray/dtypemeta.h:127
127	    return (dtype->flags & NPY_DT_PARAMETRIC) != 0;

Python and NumPy Versions:

2.6.0.dev0+git20261015.8ecb569
3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

I am working on adding type annotations to custom ufuncs of a downstream library. When I was checking if the annotations for the at() methods match runtime behavior I triggered a segmentation fault instead of the error I was expecting.

Activity

  1. eerovaher
    added
    00 - Bug
    on Oct 15, 2026
  2. jorenham commented on Oct 15, 2026

    @jorenham
    jorenham
    on Oct 15, 2026
    Member
    More actions

    Haha, I didn't expect anyone to vectorize a function that takes no arguments. Anyway, segfaults shouldn't happen, so thanks for reporting :)

  3. eerovaher commented on Oct 15, 2026

    @eerovaher
    eerovaher
    on Oct 15, 2026
    ContributorAuthor
    More actions

    The library in question provides ufunc wrappers for a C library. The source code for the ufuncs is not written down, it is instead generated at build time by a Python script that takes the source code of the C library as an input. Apparently it is simpler if the Python script just generates ufuncs with nin=0.

  4. ikrommyd commented on Oct 15, 2026

    @ikrommyd
    ikrommyd
    on Oct 15, 2026
    Member
    More actions

    We had a similar issue recently but for no output arguments ufuncs. I’ll take a look. Definitely a clean error instead of a seg fault is needed but theoretically this operation could work where it’s just like a setitem where the elements of the input are just set to what the ufunc outputs. But I wouldn’t want to enable this if it’s not trivial in code.

  5. ikrommyd commented on Oct 17, 2026

    @ikrommyd
    ikrommyd
    on Oct 17, 2026
    Member
    More actions

    I thought about it a bit more and I think just erroring is the right fix. ufunc.at(a, idx, b) is a[idx] = ufunc(a[idx], b) and if we were to support nin=0 ufuncs it would mean this a[idx] = f(). Doing this is not trivial and needs reworking ufunc_at__fast_iter/ufunc_at__slow_iter which is something nobody asked for. So just erroring is the way to go IMO. I put a PR up.

  6. ngoldbaum
    closed this as completedin #33068on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.