pypto.uniform#
产品支持情况#
产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
功能说明#
生成指定shape的均匀分布随机数,其元素范围为\([0, 1)\)。 $\( x_i \sim U(0, 1) \)$
函数原型#
uniform(shape: List[int], key: List[int], counter: List[int], alg: List[int], dtype: DataType) -> Tensor
参数说明#
参数名 |
输入/输出 |
说明 |
|---|---|---|
shape |
输入 |
输出Tensor的形状。 |
key |
输入 |
随机数生成器的seed。 |
counter |
输入 |
随机数生成器的计数器。 |
alg |
输入 |
随机数生成算法,当前仅支持值1(Philox算法),3(auto_select,选择Philox算法)。 |
dtype |
输入 |
输出Tensor的数据类型。 |
约束说明#
只在A5上支持。
不支持shape切分多个view shape,view shape必须和输入的shape一致。
tile shape尾轴必须是4的倍数。
返回值说明#
返回一个指定shape、数据类型为dtype的Tensor,其元素服从均匀分布,元素范围为\([0, 1)\)。
调用示例#
TileShape设置示例#
调用该operation接口前,应通过set_vec_tile_shapes设置TileShape。
TileShape维度应和输入一致。
如输入shape为[m, n],TileShape设置为[m1, n1], 则m1, n1分别用于切分m, n轴。
pypto.set_vec_tile_shapes(4, 4)
接口调用示例#
shape = [4, 4]
key = [1234]
counter = [0, 1]
alg = [1]
dtype = pypto.DT_FP32
y = pypto.uniform(shape, key, counter, alg, dtype)
结果示例如下:
输出数据y: [[0.1689806 0.9725481 0.90036285 0.16582811]
[0.1454581 0.48029935 0.02495587 0.99239147]
[0.02835405 0.10649502 0.45283175 0.87260246]
[0.6877538 0.24809706 0.95886254 0.24039495]]