mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-27 19:31:16 +08:00
feat: enhancement of the error message for mlx.core.mean (#608)
* add error message
This commit is contained in:
parent
e319383ef9
commit
31fea3758e
@ -1319,6 +1319,15 @@ array mean(
|
||||
const std::vector<int>& axes,
|
||||
bool keepdims /* = false */,
|
||||
StreamOrDevice s /* = {}*/) {
|
||||
int ndim = a.ndim();
|
||||
for (int axis : axes) {
|
||||
if (axis < -ndim || axis >= ndim) {
|
||||
std::ostringstream msg;
|
||||
msg << "[mean] axis " << axis + " is out of bounds for array with "
|
||||
<< ndim + " dimensions.";
|
||||
throw std::invalid_argument(msg.str());
|
||||
}
|
||||
}
|
||||
auto nelements = compute_number_of_elements(a, axes);
|
||||
auto dtype = at_least_float(a.dtype());
|
||||
return multiply(sum(a, axes, keepdims, s), array(1.0 / nelements, dtype), s);
|
||||
|
Loading…
Reference in New Issue
Block a user