Files
wehub-resource-sync 26446540fa
Lint / lint (push) Waiting to run
CI / MacOS (push) Waiting to run
CI / Windows (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:36:25 +08:00

108 lines
4.0 KiB
C++

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*!
* \file tvm/relax/attrs/sorting.h
* \brief Attributes for sorting operators.
*/
#ifndef TVM_RELAX_ATTRS_SORTING_H_
#define TVM_RELAX_ATTRS_SORTING_H_
#include <tvm/relax/expr.h>
#include <tvm/tirx/index_map.h>
namespace tvm {
namespace relax {
/*! \brief Attributes used in sort operator */
struct SortAttrs : public AttrsNode {
int axis;
bool descending;
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<SortAttrs>()
.def_ro("axis", &SortAttrs::axis,
"Axis along which the sort is computed."
"The default the last axis is used.",
refl::DefaultValue(-1))
.def_ro("descending", &SortAttrs::descending,
"Whether to sort in descending order."
"If it is not specified, it defaults to the ascending order.",
refl::DefaultValue(false));
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SortAttrs", SortAttrs, AttrsNode);
}; // struct SortAttrs
/*! \brief Attributes used in argsort operator */
struct ArgsortAttrs : public AttrsNode {
int axis;
bool descending;
ffi::Optional<DLDataType> dtype;
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<ArgsortAttrs>()
.def_ro("axis", &ArgsortAttrs::axis,
"Axis along which the argsort is computed."
"The default the last axis is used.",
refl::DefaultValue(-1))
.def_ro("descending", &ArgsortAttrs::descending,
"Whether to argsort in descending order."
"If it is not specified, it defaults to the ascending order.",
refl::DefaultValue(false))
.def_ro("dtype", &ArgsortAttrs::dtype, "DType of the output indices.");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ArgsortAttrs", ArgsortAttrs, AttrsNode);
}; // struct ArgsortAttrs
/*! \brief Attributes used in topk operator */
struct TopKAttrs : public AttrsNode {
int k;
int axis;
bool largest;
ffi::String ret_type;
ffi::Optional<DLDataType> dtype;
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<TopKAttrs>()
.def_ro("k", &TopKAttrs::k, "Number of top elements to select")
.def_ro("axis", &TopKAttrs::axis, "Axis along which to sort the input tensor.",
refl::DefaultValue(-1))
.def_ro("ret_type", &TopKAttrs::ret_type,
"The return type [both, values, indices]."
"both - return both top k data and indices."
"values - return top k data only."
"indices - return top k indices only.",
refl::DefaultValue("both"))
.def_ro("largest", &TopKAttrs::largest,
"Whether to return largest or smallest elements."
"By default, return the largest k elements.",
refl::DefaultValue(true))
.def_ro("dtype", &TopKAttrs::dtype, "Data type of the output indices.");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.TopKAttrs", TopKAttrs, AttrsNode);
}; // struct TopKAttrs
} // namespace relax
} // namespace tvm
#endif // TVM_RELAX_ATTRS_SORTING_H_