Skip to content

np.fromiter crashes if NPY_RELAXED_STRIDES_DEBUG is set #15789

@eric-wieser

Description

@eric-wieser

If numpy is built with NPY_RELAXED_STRIDES_DEBUG == 1, then fromiter uses the invalid strides.

import numpy as np

NPY_RELAXED_STRIDES_DEBUG = np.ones(1, np.uint8).strides[0] != 1
assert NPY_RELAXED_STRIDES_DEBUG 

class MyIter:
    def __length_hint__(self):
        # only required to be an estimate, this is legal
        return 1  
    def __iter__(self):
        return iter([1, 2, 3])

x = np.fromiter(MyIter(), int)
# segfault

Tested on an approximation of master.

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