Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Arguments need not be strictly positional or keyword-only for creation and manipulation functions #85

Closed
@shoyer

Description

@shoyer

It makes sense to require positional only arguments for functions like add() where there are no meaningful names, and likewise to require keyword arguments for true options.

However, this is less useful for most creation and manipulation functions. For example, arange currently has the signature arange(start, /, *, stop=None, step=1, dtype=None), but readable code could pass both start and stop as either positional or keyword arguments, e.g., np.arange(start, stop) and np.arange(start=0, stop=10).

I would suggest revisiting all of these functions and allowing arguments to be positional and keyword based when appropriate. Here are my suggestions off-hand:

  • arange(start, /, *, stop=None, step=1, dtype=None) -> arange(start, stop=None, *, step=1, dtype=None)
  • empty(shape, /, *, dtype=None) -> empty(shape, dtype=None)
  • full(shape, fill_value, /, *, dtype=None) -> full(shape, fill_value, *, dtype=None)
  • linspace(start, stop, num, /, *, dtype=None, endpoint=True) -> linspace(start, stop, num, *, dtype=None, endpoint=True)
  • ones and zeros should match empty
  • expand_dims(x, axis, /) -> expand_dims(x, /, axis) or even expand_dims(x, /, *, axis) to match other manipulation functions
  • reshape(x, shape, /) -> reshape(x, /, shape)
  • roll(x, shift, /, *, axis=None) -> roll(x, /, shift, *, axis=None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions