From f5fe691b2a4fc94cfbcc00d06f48c51d504d11f1 Mon Sep 17 00:00:00 2001 From: Jiacheng Huang Date: Sat, 9 May 2026 18:19:26 +0800 Subject: [PATCH] feat: add `sort` base --- src/base/sort.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/base/sort.h diff --git a/src/base/sort.h b/src/base/sort.h new file mode 100644 index 00000000..37ab548b --- /dev/null +++ b/src/base/sort.h @@ -0,0 +1,57 @@ +#ifndef INFINI_OPS_BASE_SORT_H_ +#define INFINI_OPS_BASE_SORT_H_ + +#include "operator.h" + +namespace infini::ops { + +class Sort : public Operator { + public: + Sort(const Tensor input, const int64_t dim, const bool descending, + Tensor values, Tensor indices) + : input_shape_{input.shape()}, + input_strides_{input.strides()}, + input_type_{input.dtype()}, + values_shape_{values.shape()}, + values_strides_{values.strides()}, + values_type_{values.dtype()}, + indices_shape_{indices.shape()}, + indices_strides_{indices.strides()}, + indices_type_{indices.dtype()}, + dim_{dim}, + descending_{descending}, + device_index_{values.device().index()} {} + + virtual void operator()(const Tensor input, const int64_t dim, + const bool descending, Tensor values, + Tensor indices) const = 0; + + protected: + Tensor::Shape input_shape_; + + Tensor::Strides input_strides_; + + DataType input_type_; + + Tensor::Shape values_shape_; + + Tensor::Strides values_strides_; + + DataType values_type_; + + Tensor::Shape indices_shape_; + + Tensor::Strides indices_strides_; + + DataType indices_type_; + + int64_t dim_{}; + + bool descending_{}; + + int device_index_{0}; +}; + +} // namespace infini::ops + +#endif