-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Operators for mean(csr, axis=0) and mean(csr, axis=1) #8264
Conversation
I just merged #8174, what's in this PR? |
@piiswrong this PR doesn't have to go in this release. This just adds support for doing mean operation along the axis. The logic is small but it still needs to go through review. |
@@ -566,7 +566,7 @@ struct SumCsrKernel<req, 1> { | |||
} | |||
}; | |||
|
|||
template <typename xpu> | |||
template <typename xpu, bool normalize = false> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add brief comment regarding what normalize is for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment!
if (normalize) { | ||
mshadow::Tensor<xpu, 1, DType> out_data = | ||
output->data().FlatTo1D<xpu, DType>(s); | ||
out_data /= scalar<DType>(num_cols); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using mshadow here for the divide, can you use a divide by scalar kernel? Mshadow is being deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use:
Kernel<mxnet_op::op_with_req<mshadow::op__div, Req>, xpu>::Launch(...)
Dee _div_scalar op (elemwise_binary_scalar_op_basic.cc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Chris! I have fixed this and I am using Kernel::Launch instead of mshadow.
@@ -96,8 +96,11 @@ MXNET_OPERATOR_REGISTER_REDUCE_BACKWARD(_backward_sum) | |||
.set_attr<FCompute>("FCompute<cpu>", ReduceAxesBackwardUseNone<cpu>); | |||
|
|||
MXNET_OPERATOR_REGISTER_REDUCE(mean) | |||
MXNET_ADD_SPARSE_OP_ALIAS(mean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work for GPU?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It falls back to dense operator for GPU.
Kernel<SumCsrKernel<req_type, 1>, xpu>::Launch( | ||
s, out_data_size, output->data().dptr<DType>(), in_indptr, | ||
in_data); | ||
MSHADOW_IDX_TYPE_SWITCH(input.aux_type(kIdx), IType, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the mean turns out to be zero, does the op effectively produce a dense result? What does numpy produce in an equivalent dense operation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operator is mean(csr, axis=0) = dense and thus always produces a dense result.
* Add Infer storage for sparse slice operator * Remove unused files * Indentation fix and add gpu test for fallback * Change sum builtin to py_sum * Add sum_axis(csr,axis=0)=dense and sum(csr,axis=1)=dense operator * Documentation changes for sparse * Add fallback unittest for keepdims and exclude * PR review based changes : * Fix CHECK_NE * Change in_stype to int * Using const int instead of int * Initialize mid with the start * Add mean(csr, axis=0) and mean(csr, axis=1) * Removing whitespace * Add brief comment for normalize * Add a comma * Lint changes
* Add Infer storage for sparse slice operator * Remove unused files * Indentation fix and add gpu test for fallback * Change sum builtin to py_sum * Add sum_axis(csr,axis=0)=dense and sum(csr,axis=1)=dense operator * Documentation changes for sparse * Add fallback unittest for keepdims and exclude * PR review based changes : * Fix CHECK_NE * Change in_stype to int * Using const int instead of int * Initialize mid with the start * Add mean(csr, axis=0) and mean(csr, axis=1) * Removing whitespace * Add brief comment for normalize * Add a comma * Lint changes
* Add Infer storage for sparse slice operator * Remove unused files * Indentation fix and add gpu test for fallback * Change sum builtin to py_sum * Add sum_axis(csr,axis=0)=dense and sum(csr,axis=1)=dense operator * Documentation changes for sparse * Add fallback unittest for keepdims and exclude * PR review based changes : * Fix CHECK_NE * Change in_stype to int * Using const int instead of int * Initialize mid with the start * Add mean(csr, axis=0) and mean(csr, axis=1) * Removing whitespace * Add brief comment for normalize * Add a comma * Lint changes
Description
Checklist
Essentials
make lint
)Changes
Comments
@piiswrong @eric-haibin-lin @reminisce @cjolivier01