Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ignore 𝙽𝚊𝙽 in reduce? #166

Open
randolf-scholz opened this issue Jan 17, 2022 · 1 comment
Open

How to ignore 𝙽𝚊𝙽 in reduce? #166

randolf-scholz opened this issue Jan 17, 2022 · 1 comment
Labels
question Further information is requested

Comments

@randolf-scholz
Copy link

Numpy and many other libraries have introduced additional aggregation functions that ignore 𝙽𝚊𝙽-values, for instance:

  • numpy.nan[sum, mean, min, max, argmin, argmax, median, std, var, prod, quantile, percentile]
  • torch.nan[sum, mean, median, quantile]
  • tensorflow.experimental.numpy
  • jax.numpy
  1. Use-cases This would be mostly a comfort increase. Avoiding aggregation over 𝙽𝚊𝙽-values when working with data that has missing values, or when padding (padding with 𝙽𝚊𝙽's instead of 0's has the advantage that any computation that accidentally uses the padding values will result in a 𝙽𝚊𝙽 again - thus making it easier to notice such bugs.)
  2. Implementation. Either, avoid iterating over 𝙽𝚊𝙽-values altogether, or chose a masking value appropriate for the chosen reduction, e.g.
    • nansum → replace 𝙽𝚊𝙽 with 0
    • nanprod → replace 𝙽𝚊𝙽 with 1
    • nanmax → replace 𝙽𝚊𝙽 with -𝙸𝚗𝚏
  3. Integrity - does it interplay well with existing operations and notation in einops? It is a simple additional boolean flag ignore_nan for reduce
  4. Readability. Alternatively, one could have a nanreduce that does the same thing but is visually more striking.

Similarly, one could consider an additional ignore_infinite-flag.

@arogozhnikov
Copy link
Owner

It is currently supported by providing callables for reductions in einops.reduce. Example:

einops.reduce(array, 'i j k -> (i j)', np.nanmean)

@arogozhnikov arogozhnikov added question Further information is requested and removed feature suggestion labels Sep 27, 2022
@arogozhnikov arogozhnikov changed the title [Feature suggestion] ignore 𝙽𝚊𝙽 flag for reduce How to ignore 𝙽𝚊𝙽 in reduce? May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants