gemini-code-assist[bot] commented on code in PR #19683:
URL: https://github.com/apache/tvm/pull/19683#discussion_r3372271193


##########
include/tvm/topi/reduction.h:
##########
@@ -184,7 +184,9 @@ inline Tensor DoCommReduce(const Tensor& data, FReduce func,
 inline Tensor CommReduce(const Tensor& data, const 
ffi::Optional<ffi::Array<int64_t>>& axis,
                          FReduce func, bool keepdims, bool atleast1d) {
   auto ndim = data->shape.size();
-  TVM_FFI_ICHECK_NE(ndim, 0) << "Cannot reduce a 0 dim Tensor";
+  if (ndim == 0) {
+    return topi::identity(data, data->op->name + "_red", kCommReduce);
+  }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   When `ndim == 0` and `atleast1d` is `true`, the output tensor should be at 
least 1-dimensional (i.e., shape `[1]`). However, returning `topi::identity` 
directly ignores the `atleast1d` flag and returns a 0-dimensional tensor. We 
should wrap the identity tensor with `topi::expand_dims` if `atleast1d` is 
enabled.
   
   ```suggestion
     if (ndim == 0) {
       auto identity = topi::identity(data, data->op->name + "_red", 
kCommReduce);
       return atleast1d ? topi::expand_dims(identity, 0, 1) : identity;
     }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to