@@ -2794,17 +2794,9 @@ array sort(const array& a, StreamOrDevice s /* = {} */) {
27942794
27952795/* * Returns a sorted copy of the array along a given axis. */
27962796array sort (const array& a, int axis, StreamOrDevice s /* = {} */ ) {
2797- // Check for valid axis
2798- if (axis + static_cast <int >(a.ndim ()) < 0 ||
2799- axis >= static_cast <int >(a.ndim ())) {
2800- std::ostringstream msg;
2801- msg << " [sort] Received invalid axis " << axis << " for array with "
2802- << a.ndim () << " dimensions." ;
2803- throw std::invalid_argument (msg.str ());
2804- }
2805-
2797+ auto ax = normalize_axis_index (axis, a.ndim (), " [sort] " );
28062798 return array (
2807- a.shape (), a.dtype (), std::make_shared<Sort>(to_stream (s), axis ), {a});
2799+ a.shape (), a.dtype (), std::make_shared<Sort>(to_stream (s), ax ), {a});
28082800}
28092801
28102802/* * Returns indices that sort the flattened array. */
@@ -2815,17 +2807,9 @@ array argsort(const array& a, StreamOrDevice s /* = {} */) {
28152807
28162808/* * Returns indices that sort the array along a given axis. */
28172809array argsort (const array& a, int axis, StreamOrDevice s /* = {} */ ) {
2818- // Check for valid axis
2819- if (axis + static_cast <int >(a.ndim ()) < 0 ||
2820- axis >= static_cast <int >(a.ndim ())) {
2821- std::ostringstream msg;
2822- msg << " [argsort] Received invalid axis " << axis << " for array with "
2823- << a.ndim () << " dimensions." ;
2824- throw std::invalid_argument (msg.str ());
2825- }
2826-
2810+ auto ax = normalize_axis_index (axis, a.ndim (), " [argsort] " );
28272811 return array (
2828- a.shape (), uint32, std::make_shared<ArgSort>(to_stream (s), axis ), {a});
2812+ a.shape (), uint32, std::make_shared<ArgSort>(to_stream (s), ax ), {a});
28292813}
28302814
28312815/* *
0 commit comments