8000 Reducing over empty dimensions for reductions without identity · Issue #61901 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Reducing over empty dimensions for reductions without identity #61901
@heitorschueroff

Description

@heitorschueroff

This issue is for discussing what should be the result fo reducing nothing. Ideally, this behavior should be consistent across our reduction operators, however, this is what the current reductions return.

* max, min → always raise an error. NumPy always errors
* sum → always return 0 (identity value)
* prod → always return 1 (identity value)
* amax, amin → garbage value for dim=None, otherwise error. NumPy always errors
* mean → returns nan. NumPy raises warning and returns nan
* median → without dim returns nan for floating point inputs and garbage for integral, with dim errors. NumPy raises a warning and returns nan, however NumPy also promotes to floating point which we should not do. So we should error for integral input at least.
* mode → raises an error
* std(_mean), var(_mean) → always returns nan. NumPy raises warning and returns nan.
* logsumexp → returns -inf
* quantile → raises an error, nanquantile where all inputs are nan returns nan, this should be consistent with quantile over empty dimension. NumPy raises an IndexError for quantile but returns nan for nanquantile.
* kthvalue → raises an error
* topk → only allowed for k=0 in which case an empty tensor is returned
* argmax, argmin → always raise an error
* all → always returns True (identity)
* any → always returns False (identity)
* count_nonzero → always returns 0 (identity)
* linalg.vector_norm → if selected ord has identity, returns it otherwise raises error

Some options for making this consistent are:

  • If the operator has an identity (e.g. identity of sum is 0) then the identity should be returned
  • if the operator does not have an identity, it could (from least to most permissive)
    • always raise an error
    • return nan only for reductions that promote integers to float (mean, std, var, std_mean, var_mean, logsumexp) and raise error for all others, even if the input has floating point type.*
    • return nan if result type is floating point, otherwise raise an error
    • always return nan, performing type promotion to float if needed
    • just be a no-op?

cc @mruberry @rgommers @heitorschueroff

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: numpyRelated to numpy support, and also numpy compatibility of our operatorsmodule: reductionsneeds designWe want to add this feature but we need to figure out how firsttriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0