                   dp_keys_first,
                   divides<size_t>());
 
-        // Sorting with back-to-back approach.
-        stable_sort_by_key(dp_data_first,
-                           dp_data_last,
-                           dp_keys_first,
-                           less<T>());
-
-        stable_sort_by_key(dp_keys_first,
-                           dp_keys_last,
-                           dp_data_first,
-                           less<size_t>());
+        stable_sort(
+            make_zip_iterator(make_tuple(dp_keys_first, dp_data_first)),
+            make_zip_iterator(make_tuple(dp_keys_last, dp_data_last)),
+            tuple_less<size_t, T>());
     }
 }
 

/*
 * sort
 */

template <typename T>
void cupy::thrust::_sort(void *data_start, size_t *keys_start, const std::vector<ptrdiff_t>& shape) {

#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/sequence.h>
#include <thrust/sort.h>
#include "cupy_common.h"
