rank
产品支持情况
- Ascend 950PR&950DT系列产品:支持
- Atlas A3系列产品:不支持
- Atlas A2系列产品:不支持
- Atlas 200I/500 A2推理产品:不支持
- Atlas推理系列产品AI Core:不支持
- Atlas推理系列产品Vector Core:不支持
- Atlas训练系列产品:不支持
功能说明
用于返回layout的秩。
函数原型
template <size_t... Is, typename Layout>
__aicore__ inline constexpr auto rank(const Layout& layout);
参数说明
表1 模板参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| Is... | size_t | 索引序列,用于编译时递归选择shape和stride的子结构。 |
| Layout | 输入 | layout对象的类型。 |
表2 参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| layout | 输入 | layout用于描述张量的布局。 |
返回值
返回layout的秩,即返回layout布局的shape或其子结构的元组(tuple)维度的个数。
示例代码
#include "tensor_api/tensor.h"
using namespace asc::te;
auto layout = make_layout(make_shape(10, 20), make_stride(1, 100));
auto rank1 = rank(layout); //rank1 = 2
auto rank2 = rank<0>(layout); //rank2 = 1