yongwww commented on code in PR #16575: URL: https://github.com/apache/tvm/pull/16575#discussion_r1491930906
########## python/tvm/relax/frontend/nn/op.py: ########## @@ -1825,3 +1826,260 @@ def print_(tensor: Tensor): filename, line_number = inspect.getframeinfo(inspect.currentframe().f_back)[:2] line_info = f"{filename}:{line_number}" debug_func("vm.builtin.debug_print", tensor, _line_info=line_info) + + +def less(a: Tensor, b: Tensor, name: str = "less") -> Tensor: + """Broadcasted element-wise comparison for (lhs < rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.less(a._expr, b._expr), name) + + +def less_equal(a: Tensor, b: Tensor, name: str = "less_equal") -> Tensor: + """Broadcasted element-wise comparison for (lhs <= rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.less_equal(a._expr, b._expr), name) + + +def greater(a: Tensor, b: Tensor, name: str = "greater") -> Tensor: + """Broadcasted element-wise comparison for (lhs > rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.greater(a._expr, b._expr), name) + + +def greater_equal(a: Tensor, b: Tensor, name: str = "greater_equal") -> Tensor: + """Broadcasted element-wise comparison for (lhs >= rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.greater_equal(a._expr, b._expr), name) + + +def equal(a: Tensor, b: Tensor, name: str = "equal") -> Tensor: + """Broadcasted element-wise comparison for (lhs == rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.equal(a._expr, b._expr), name) + + +def not_equal(a: Tensor, b: Tensor, name: str = "not_equal") -> Tensor: + """Broadcasted element-wise comparison for (lhs != rhs). + + Parameters + ---------- + a : Tensor + The first input tensor. + + b : Tensor + The second input tensor. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The computed result. + """ + return wrap_nested(_op.not_equal(a._expr, b._expr), name) + + +def cumsum( + data: Tensor, + axis: Optional[int] = None, + dtype: Optional[str] = None, + exclusive: Optional[bool] = None, + name: str = "cumsum", +) -> Tensor: + """Numpy style cumsum op. Return the cumulative inclusive sum of the elements along + a given axis. + + Parameters + ---------- + data : Tensor + The input data to the operator. + + axis : Optional[int] + Axis along which the cumulative sum is computed. The default (None) is to compute + the cumsum over the flattened array. + + dtype : Optional[str] + Type of the returned array and of the accumulator in which the elements are summed. + If dtype is not specified, it defaults to the dtype of data. + + exclusive : Optional[bool] + If true will return exclusive sum in which the first element is not + included. + + name : str + Name hint. + + Returns + ------- + result : Tensor + The result has the same size as data, and the same shape as data if axis is not None. + If axis is None, the result is a 1-d array. + + Examples + -------- + .. code-block:: python + + a = [[1, 2, 3], [4, 5, 6]] + + cumsum(a) # if axis is not provided, cumsum is done over the flattened input. + -> [ 1, 3, 6, 10, 15, 21] + + cumsum(a, dtype="float32") + -> [ 1., 3., 6., 10., 15., 21.] + + cumsum(a, axis=0) # sum over rows for each of the 3 columns + -> [[1, 2, 3], + [5, 7, 9]] + + cumsum(a, axis=1) + -> [[ 1, 3, 6], + [ 4, 9, 15]] + + a = [1, 0, 1, 0, 1, 1, 0] # a is a boolean array + cumsum(a, dtype=int32) # dtype should be provided to get the expected results + -> [1, 1, 2, 2, 3, 4, 4] + """ + return wrap_nested(_op.cumsum(data._expr, axis, dtype, exclusive), name) + + +def multinomial_from_uniform(prob: Tensor, uniform_sample: Tensor): Review Comment: good catch! The test case can be found [here](https://github.com/apache/tvm/pull/16575/commits/abbe733e4af04ac1591066769d269d8c3aa95d56#diff-cd42596733b780d4b3ca6e4e66a002f6175c144821cdeabe8ebaa91bc6c16f67L907-L924). The reason I didn't enable it was the nn module tests currently don't cover the build and run. I will add it back. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org