SparseBincount
产品支持情况
| 产品 | 是否支持 |
|---|---|
| Ascend 950PR&950DT系列产品 | √ |
| Atlas A3系列产品 | √ |
| Atlas A2系列产品 | √ |
| Atlas 200I/500 A2推理产品 | × |
| Atlas推理系列产品 | × |
| Atlas训练系列产品 | × |
功能说明
-
算子功能:统计稀疏张量中每个值(bin index)的出现次数或加权累加和。支持1D和多维模式,支持binary_output模式。
-
计算公式:
1D: output[v]+=wi(if v<size)\text{1D: } output[v] += w_i \quad (\text{if } v < size)
Multi-dim: output[batch][v]+=wi(if v<size and batch<dense_shape[0])\text{Multi-dim: } output[batch][v] += w_i \quad (\text{if } v < size \text{ and } batch < dense\_shape[0])
参数说明
| 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 |
|---|---|---|---|---|
| indices | 输入 | 稀疏张量的索引,2D tensor,shape (N, R)。 | INT64 | ND |
| values | 输入 | 稀疏张量的值(bin index),1D tensor,shape (N,)。 | INT32、INT64 | ND |
| dense_shape | 输入 | 稀疏张量的稠密形状,1D tensor,shape (R,)。 | INT64 | ND |
| size | 输入 | bin的数量(标量tensor),shape (1,)。 | INT32、INT64 | ND |
| weights | 输入 | 权重,1D tensor,shape (N,)或(0,)。为空时每个出现计为1。 | FLOAT | ND |
| binary_output | 可选属性 | 是否二值输出,缺省值为false。True时出现过的bin设为1,False时输出计数或加权累加。 | BOOL | - |
| output | 输出 | 统计结果。1D时shape=[size],多维时shape=[dense_shape[0], size]。 | FLOAT | ND |
约束说明
- indices为2D tensor,shape (N, R);values、dense_shape、size、weights均为1D tensor
- indices行数(N)必须等于values元素数(N)
- indices列数(R)必须等于dense_shape元素数(R),且dense_shape元素数(R)至少为1(dense_shape非空)
- indices[:, j]必须在[0, dense_shape[j])范围内
- values[i]必须在[0, size)范围内
- weights非空时,元素数必须与values元素数(N)相等
- size为非负标量,shape为(1,)
- weights为空(元素数为0)时,每个出现计为1.0
- binary_output = True时,出现过的bin设为1.0,忽略权重
调用说明
| 调用方式 | 样例代码 | 说明 |
|---|---|---|
| GE图模式 | test_geir_sparse_bincount | 通过算子IR构图方式调用SparseBincount算子。 |