2. OpBuilders¶
如下展示各个OpBuilder的python接口用法.
算子的详细语义可以参考TopsGraph C++ API参考/Operation Semantics.
2.1. Abs¶
def abs(x)
总结: 计算输入tensor的绝对值
- 参数:
x
- 需要计算绝对值的tensor
- 返回值:
x
的绝对值
示例代码:
data = np.array([-1, 0, 1], dtype=np.float32)
output = tops.jit(tgb.abs)(data)
# expect: output = [1, 0, 1]
2.2. Acos¶
Computes the arccosine (inverse of cosine) of a tensor element-wise.
- Inputs:
\(x\) is an op whose result shape is \((*)\), where \(*\) means any number of dimensions.
- Outputs:
\(result\) with the same shape and data type as the input.
- Examples:
>>> data = np.array([-0.4, -0.2, 0.1, 0.3], dtype=np.float32) >>> output = tops.jit(tgb.acos)(data) >>> # expect: [1.98231317, 1.77215425, 1.47062891, 1.26610367]
2.3. Add¶
Add two tensors element-wise with Numpy-style broadcasting support.
- Inputs:
\(x\) is an op whose result shape is \((*)\), where \(*\) means any number of dimensions.
\(y\) is an op whose data type is same as \(x\).
- Parameters:
\(broadcast\_dimensions\) specify the dimensions in the target shape each dimension of the input shape corresponds to. If inputs are static shape and the user want to follow
numpy-style broadcasting
, just use the default value of empty list. Default: [].
- Outputs:
\(result\) with the same data type as the inputs.
- Examples:
>>> lhs = np.array([1, -2, 3, -4], dtype=np.float32) >>> rhs = np.array([0, 2, -1, 8], dtype=np.float32) >>> output = tops.jit(tgb.add)(lhs, rhs) >>> # expect: [1., 0., 2., 4.]