24#ifndef TVM_TOPI_DETAIL_RAVEL_UNRAVEL_H_
25#define TVM_TOPI_DETAIL_RAVEL_UNRAVEL_H_
45inline PrimExpr RavelIndex(ffi::Array<PrimExpr> indices, ffi::Array<PrimExpr>
shape) {
46 TVM_FFI_ICHECK_EQ(indices.size(),
shape.size()) <<
"indices and shape must have equal size";
47 if (indices.size() == 0U) {
51 for (
size_t i = 1; i < indices.size(); ++i) {
52 idx = idx *
shape[i] + indices[i];
65inline ffi::Array<PrimExpr> UnravelIndex(
PrimExpr idx, ffi::Array<PrimExpr>
shape) {
66 std::vector<PrimExpr> indices;
68 for (
int i =
static_cast<int>(
shape.size()) - 1; i >= 0; --i) {
72 std::reverse(indices.begin(), indices.end());
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Tensor expression language DSL.
Definition extracted_task.h:33
Tensor shape(const Tensor &src, PrimType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition transform.h:2016
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL PrimExpr indexdiv(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute floor(a / b) where a and b are non-negative.
TVM_TIRX_DLL PrimExpr indexmod(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute the remainder floor(a / b) where a and b are non-negative.
Operation node can generate one or multiple Tensors.