ivy-llc / ivy

Convert Machine Learning Code Between Frameworks
https://ivy.dev
Other
14.02k stars 5.77k forks source link

Add Statistical Functions to Paddle Frontend #15045

Open hmahmood24 opened 1 year ago

hmahmood24 commented 1 year ago

Add Statistical Functions to PaddlePaddle Frontend

Please keep in mind that the proper way to link an issue to this list is to comment "- [ ] #issue_number" while the issue's title only includes the name of the function you've chosen.

ivy/functional/frontends/paddle/stat.py ivy\_tests/test\_ivy/test\_frontends/test\_paddle/test\_stat.py

owoeye-babatunde commented 1 year ago

15045

lucrieffel commented 1 year ago

Added quantile function: @with_supported_dtypes({"float32","float64"}) @to_ivy_arrays_and_back def quantile(x, q, axis=None, keepdim=False, name=None): x = ivy.cast(x, ivy.float64) if ivy.dtype(x) == 'float64' else ivy.cast(x, ivy.float32) sorted_x = ivy.sort(x, axis=axis) rank = (ivy.shape(sorted_x, axis=axis) - 1) q rank_int = ivy.floor(rank) rank_frac = rank - rank_int lower_values = ivy.gather(sorted_x, ivy.cast(rank_int, ivy.int32), axis=axis) upper_values = ivy.gather(sorted_x, ivy.cast(rank_int + 1, ivy.int32), axis=axis) quantile_value = lower_values + rank_frac (upper_values - lower_values) if not keepdim: quantile_value = ivy.squeeze(quantile_value, axis=axis)

  return quantile_value
Maxwel-ondieki commented 1 year ago

19176