Skip to content

BUG: SeedSequence accepts types outside of spec #27380

Open

Description

@bashtage

Describe the issue:

SeedSequence supports None, int, Sequence[int] for entropy. It turns out that anythign with len(obj)==0 in the leading dimension will be accepted and is identical to 0. This includes ndarrays with any number of dimensions.

This might be more of a FR than a bug, but the lack of standardization could increase end users error risk.

Reproduce the code example:

import numpy as np

np.random.SeedSequence(0).generate_state(1)
np.random.SeedSequence([]).generate_state(1)
np.random.SeedSequence([[],[]]).generate_state(1)
np.random.SeedSequence(np.empty((0,10,10))).generate_state(1)
np.random.SeedSequence(np.empty((0,10,10), dtype=float)).generate_state(1)

Error message:

No error. The output of the above is

All produce

array([2968811710], dtype=uint32)
array([2968811710], dtype=uint32)
array([2968811710], dtype=uint32)
array([2968811710], dtype=uint32)
array([2968811710], dtype=uint32)

Python and NumPy Versions:

2.1.1
3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:03:56) [MSC v.1929 64 bit (AMD64)]

Runtime Environment:

No response

Context for the issue:

It simply seems a bit less careful than it should be, and could allow accidental seed values in.

Activity

  1. rkern commented on Sep 12, 2024

    @rkern
    Member

    The 0-padding behavior for [] should certainly be documented (we 0-pad out to pool_size uint32 integers so that spawning doesn't create conflicts).

    We certainly could tighten up our validation in _coerce_to_uint32_array(). What we implemented there was really an older proposal that didn't make the final cut that allowed a lot more than what we currently document because we thought we might want to allow things like hex-int '0x1badcafe' strings for ease of integration. That could certainly use another pass to align it with the final documentation.

    As a rule though, the documentation defines the standard and things outside of what's documented MAY raise a helpful exception but MAY also just execute with undefined behavior. Possibly worth tightening up if it's easy, but not urgently.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions