masahi commented on a change in pull request #6232:
URL: https://github.com/apache/incubator-tvm/pull/6232#discussion_r467647626



##########
File path: src/relay/op/tensor/reduce.cc
##########
@@ -542,51 +547,61 @@ bool VarianceRel(const Array<Type>& types, int 
num_inputs, const Attrs& attrs,
   std::vector<IndexExpr> mean_shape(mean->shape.begin(), mean->shape.end());
   CHECK_EQ(in_shape.size(), mean_shape.size());
 
-  const ReduceAttrs* param = attrs.as<ReduceAttrs>();
+  const VarianceAttrs* param = attrs.as<VarianceAttrs>();
   CHECK(param != nullptr);
 
   // assign output type and shape
-  auto oshape = ReduceShapeImpl(in_shape, param, reporter);
+  auto oshape = ReduceShapeImpl(in_shape, param->axis, param->keepdims, 
param->exclude, reporter);
   reporter->Assign(types[2], TensorType(oshape, data->dtype));
   return true;
 }
 
 Array<te::Tensor> VarianceCompute(const Attrs& attrs, const Array<te::Tensor>& 
inputs,
                                   const Type& out_type) {
   IndexExpr count = tir::make_const(inputs[0]->dtype, 1);
-  const ReduceAttrs* param = attrs.as<ReduceAttrs>();
+  const VarianceAttrs* param = attrs.as<VarianceAttrs>();
   CHECK(param != nullptr);
   auto axes = param->axis;
+  bool unbiased = param->unbiased;
   auto data = inputs[0];
   auto mean = inputs[1];
   for (int64_t i : GetReduceAxes(data->shape.size(), param->axis, 
param->exclude)) {
     count *= data->shape[i];
   }
+  if (unbiased) {
+    count -= 1;
+  }
   std::vector<Integer> expand_shape;
   auto sq_diff = topi::power(topi::subtract(data, mean), 2);
-  auto var = topi::divide(ReduceCompute(attrs, {sq_diff}, out_type, 
topi::sum)[0], count);

Review comment:
       If `VarianceAttrs` could inherit from `ReduceAttrs`, we don't have to 
introduce this change. But again, I don't know if that inheritance of Attrs 
works...




----------------------------------------------------------------
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.

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


Reply via email to