You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/02/07 08:44:39 UTC
[GitHub] [incubator-mxnet] Yiyan66 opened a new pull request #17541: [numpy]
add op random.rayleigh
Yiyan66 opened a new pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541
## Description ##
add op random.rayleigh
## Checklist ##
### Essentials ###
Please feel free to remove inapplicable items for your PR.
- [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
- [ ] Changes are complete (i.e. I finished coding on this PR)
- [ ] All changes have test coverage:
- Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
- Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
- Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
- [ ] Code is well-documented:
- For user-facing API changes, API doc string has been updated.
- For new C++ functions in header files, their functionalities and arguments are documented.
- For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
- Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
- [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
### Changes ###
- [ ] Feature1, tests, (and when applicable, API doc)
- [ ] Feature2, tests, (and when applicable, API doc)
## Comments ##
- If this change is a backward incompatible change, why must this change be made.
- Interesting edge cases to note here
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r380003075
##########
File path: src/operator/numpy/random/np_rayleigh_op.h
##########
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file np_rayleigh_op.h
+ * \brief Operator for numpy sampling from rayleigh distribution.
+ */
+
+#ifndef MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+#define MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+
+#include <mxnet/operator_util.h>
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <cmath>
+#include "../../elemwise_op_common.h"
+#include "../../mshadow_op.h"
+#include "../../mxnet_op.h"
+#include "../../operator_common.h"
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+#include "./dist_common.h"
+
+namespace mxnet {
+namespace op {
+
+struct NumpyRayleighParam : public dmlc::Parameter<NumpyRayleighParam> {
+ dmlc::optional<float> scale;
+ dmlc::optional<mxnet::Tuple<int>> size;
+ std::string ctx;
+ DMLC_DECLARE_PARAMETER(NumpyRayleighParam) {
+ DMLC_DECLARE_FIELD(scale)
+ .set_default(dmlc::optional<float>(1.0));
+ DMLC_DECLARE_FIELD(size)
+ .set_default(dmlc::optional<mxnet::Tuple<int>>())
+ .describe("Output shape. If the given shape is, "
+ "e.g., (m, n, k), then m * n * k samples are drawn. "
+ "Default is None, in which case a single value is returned.");
+ DMLC_DECLARE_FIELD(ctx).set_default("cpu").describe(
+ "Context of output, in format [cpu|gpu|cpu_pinned](n)."
+ " Only used for imperative calls.");
+ }
+};
+
+template <typename DType>
+struct scalar_rayleigh_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, float scale, float *threshold,
+ DType *out) {
+ threshold[i] = sqrt(-2 * log(threshold[i]));
+ out[i] = scale * threshold[i];
+ }
+};
+
+namespace mxnet_op {
+
+template <typename IType>
+struct check_legal_scale_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, IType *scalar, float* flag) {
+ if (scalar[i] < 0.0) {
+ flag[0] = -1.0;
+ }
+ }
+};
+
Review comment:
1 blank line between functions in c++
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] xidulu commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
xidulu commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378687598
##########
File path: python/mxnet/ndarray/numpy/random.py
##########
@@ -24,6 +24,7 @@
__all__ = ['randint', 'uniform', 'normal', "choice", "rand", "multinomial", "multivariate_normal",
+ "rayleigh",
Review comment:
Don't start a new line for only **one** item.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378675708
##########
File path: python/mxnet/symbol/numpy/random.py
##########
@@ -382,6 +383,42 @@ def gamma(shape, scale=1.0, size=None, dtype=None, ctx=None, out=None):
raise ValueError("Distribution parameters must be either _Symbol or numbers")
+def rayleigh(scale=0.0, size=None, ctx=None, out=None):
+ r"""Draw samples from a Rayleigh distribution.
+
+ The :math:`\chi` and Weibull distributions are generalizations of the
+ Rayleigh.
+
+ Parameters
+ ----------
+ scale : float or _Symbol of floats
Review comment:
not `float or _Symbol of floats`, should simply be `float or _Symbol`
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378675457
##########
File path: python/mxnet/ndarray/numpy/random.py
##########
@@ -279,6 +280,44 @@ def multinomial(n, pvals, size=None):
return _npi.multinomial(n=n, pvals=pvals, size=size)
+def rayleigh(scale=1.0, size=None, ctx=None, out=None):
+ r"""Draw samples from a Rayleigh distribution.
+
+ The :math:`\chi` and Weibull distributions are generalizations of the
+ Rayleigh.
+
+ Parameters
+ ----------
+ scale : float or array_like of floats, optional
Review comment:
not `array_like`, we should only support either `mx.numpy.ndarray` or a float scalar.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378675242
##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -3624,6 +3624,44 @@ def _test_random_beta_range(output):
assert _test_random_beta_range(mx_out_imperative.asnumpy()) == True
+@with_seed()
+@use_np
+def test_np_rayleigh():
Review comment:
`test_np_random_rayleigh`
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] xidulu commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
xidulu commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378687862
##########
File path: python/mxnet/numpy/random.py
##########
@@ -22,6 +22,7 @@
__all__ = ["randint", "uniform", "normal", "choice", "rand", "multinomial", "multivariate_normal",
+ "rayleigh",
Review comment:
Don't start a new line for only one item.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378675086
##########
File path: src/operator/numpy/random/np_rayleigh_op.h
##########
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file np_rayleigh_op.h
+ * \brief Operator for numpy sampling from rayleigh distribution.
+ */
+
+#ifndef MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+#define MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+
+#include <mxnet/operator_util.h>
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <cmath>
+#include "../../elemwise_op_common.h"
+#include "../../mshadow_op.h"
+#include "../../mxnet_op.h"
+#include "../../operator_common.h"
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+#include "./dist_common.h"
+
+namespace mxnet {
+namespace op {
+
+struct NumpyRayleighParam : public dmlc::Parameter<NumpyRayleighParam> {
+ dmlc::optional<float> scale;
+ dmlc::optional<mxnet::Tuple<int>> size;
+ std::string ctx;
+ DMLC_DECLARE_PARAMETER(NumpyRayleighParam) {
+ DMLC_DECLARE_FIELD(scale)
+ .set_default(dmlc::optional<float>(1.0));
+ DMLC_DECLARE_FIELD(size)
+ .set_default(dmlc::optional<mxnet::Tuple<int>>())
+ .describe("Output shape. If the given shape is, "
+ "e.g., (m, n, k), then m * n * k samples are drawn. "
+ "Default is None, in which case a single value is returned.");
+ DMLC_DECLARE_FIELD(ctx).set_default("cpu").describe(
+ "Context of output, in format [cpu|gpu|cpu_pinned](n)."
+ " Only used for imperative calls.");
+ }
+};
+
+template <typename DType>
+struct scalar_rayleigh_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, float scale, float *threshold,
+ DType *out) {
+ threshold[i] = sqrt(-2 * log(threshold[i]));
+ out[i] = scale * threshold[i];
+ }
+};
+
+namespace mxnet_op {
+
+template <typename IType>
+struct check_legal_scale_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, IType *scalar, float* flag) {
+ if (scalar[i] < 0.0) {
+ flag[0] = -1.0;
+ }
+ }
+};
+
+
+template <int ndim, typename IType, typename OType>
+struct rayleigh_kernel {
+ MSHADOW_XINLINE static void Map(index_t i,
+ const Shape<ndim> &stride,
+ const Shape<ndim> &oshape,
+ IType *scales, float* threshold, OType *out) {
+ Shape<ndim> coord = unravel(i, oshape);
+ auto idx = static_cast<index_t>(dot(coord, stride));
+ threshold[i] = sqrt(-2 * log(threshold[i]));
+ out[i] = scales[idx] * threshold[i];
+ }
+};
+
+} // namespace mxnet_op
+
+template <typename xpu>
+void NumpyRayleighForward(const nnvm::NodeAttrs &attrs,
+ const OpContext &ctx,
+ const std::vector<TBlob> &inputs,
+ const std::vector<OpReqType> &req,
+ const std::vector<TBlob> &outputs) {
+ using namespace mshadow;
+ using namespace mxnet_op;
+ const NumpyRayleighParam ¶m = nnvm::get<NumpyRayleighParam>(attrs.parsed);
+ Stream<xpu> *s = ctx.get_stream<xpu>();
+ Random<xpu, float> *prnd = ctx.requested[0].get_random<xpu, float>(s);
+ Tensor<xpu, 1, float> workspace =
+ ctx.requested[1].get_space_typed<xpu, 1, float>(Shape1(1), s);
+ Tensor<xpu, 1, float> uniform_tensor = outputs[1].FlatTo1D<xpu, float>(s);
+ Tensor<xpu, 1, float> indicator_device = workspace;
+ float indicator_host = 1.0;
+ float *indicator_device_ptr = indicator_device.dptr_;
+ Kernel<set_zero, xpu>::Launch(s, 1, indicator_device_ptr);
+ prnd->SampleUniform(&uniform_tensor, 0.0, 1.0);
+ if (param.scale.has_value()) {
+ CHECK_GE(param.scale.value(), 0.0) << "ValueError: expect scale >= 0";
+ MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+ Kernel<scalar_rayleigh_kernel<DType>, xpu>::Launch(
+ s, outputs[0].Size(), param.scale.value(),
+ uniform_tensor.dptr_, outputs[0].dptr<DType>());
+ });
+ } else {
+ MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, IType, {
+ Kernel<check_legal_scale_kernel<IType>, xpu>::Launch(
+ s, inputs[0].Size(), inputs[0].dptr<IType>(), indicator_device_ptr);
+ });
+ _copy<xpu>(s, &indicator_host, indicator_device_ptr);
+ CHECK_GE(indicator_host, 0.0) << "ValueError: expect scale >= 0";
+ mxnet::TShape new_lshape, new_oshape;
+ int ndim = FillShape(inputs[0].shape_, inputs[0].shape_, outputs[0].shape_,
+ &new_lshape, &new_lshape, &new_oshape);
+ MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, IType, {
+ MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, OType, {
+ BROADCAST_NDIM_SWITCH(ndim, NDim, {
+ Shape<NDim> oshape = new_oshape.get<NDim>();
+ Shape<NDim> stride = calc_stride(new_lshape.get<NDim>());
+ Kernel<rayleigh_kernel<NDim, IType, OType>, xpu>::Launch(
+ s, outputs[0].Size(), stride, oshape, inputs[0].dptr<IType>(),
+ uniform_tensor.dptr_, outputs[0].dptr<OType>());
+ });
+ });
+ });
+ }
+}
+
+template<typename xpu, int ndim, typename DType>
+inline void ScalarRayleighReparamBackwardImpl(const OpContext& ctx,
+ const std::vector<TBlob>& inputs,
Review comment:
alignment.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request
#17541: [numpy] add op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541#discussion_r378675122
##########
File path: src/operator/numpy/random/np_rayleigh_op.h
##########
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file np_rayleigh_op.h
+ * \brief Operator for numpy sampling from rayleigh distribution.
+ */
+
+#ifndef MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+#define MXNET_OPERATOR_NUMPY_RANDOM_NP_RAYLEIGH_OP_H_
+
+#include <mxnet/operator_util.h>
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <cmath>
+#include "../../elemwise_op_common.h"
+#include "../../mshadow_op.h"
+#include "../../mxnet_op.h"
+#include "../../operator_common.h"
+#include "../../tensor/elemwise_binary_broadcast_op.h"
+#include "./dist_common.h"
+
+namespace mxnet {
+namespace op {
+
+struct NumpyRayleighParam : public dmlc::Parameter<NumpyRayleighParam> {
+ dmlc::optional<float> scale;
+ dmlc::optional<mxnet::Tuple<int>> size;
+ std::string ctx;
+ DMLC_DECLARE_PARAMETER(NumpyRayleighParam) {
+ DMLC_DECLARE_FIELD(scale)
+ .set_default(dmlc::optional<float>(1.0));
+ DMLC_DECLARE_FIELD(size)
+ .set_default(dmlc::optional<mxnet::Tuple<int>>())
+ .describe("Output shape. If the given shape is, "
+ "e.g., (m, n, k), then m * n * k samples are drawn. "
+ "Default is None, in which case a single value is returned.");
+ DMLC_DECLARE_FIELD(ctx).set_default("cpu").describe(
+ "Context of output, in format [cpu|gpu|cpu_pinned](n)."
+ " Only used for imperative calls.");
+ }
+};
+
+template <typename DType>
+struct scalar_rayleigh_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, float scale, float *threshold,
+ DType *out) {
+ threshold[i] = sqrt(-2 * log(threshold[i]));
+ out[i] = scale * threshold[i];
+ }
+};
+
+namespace mxnet_op {
+
+template <typename IType>
+struct check_legal_scale_kernel {
+ MSHADOW_XINLINE static void Map(index_t i, IType *scalar, float* flag) {
+ if (scalar[i] < 0.0) {
+ flag[0] = -1.0;
+ }
+ }
+};
+
+
+template <int ndim, typename IType, typename OType>
+struct rayleigh_kernel {
+ MSHADOW_XINLINE static void Map(index_t i,
+ const Shape<ndim> &stride,
+ const Shape<ndim> &oshape,
+ IType *scales, float* threshold, OType *out) {
+ Shape<ndim> coord = unravel(i, oshape);
+ auto idx = static_cast<index_t>(dot(coord, stride));
+ threshold[i] = sqrt(-2 * log(threshold[i]));
+ out[i] = scales[idx] * threshold[i];
+ }
+};
+
+} // namespace mxnet_op
+
+template <typename xpu>
+void NumpyRayleighForward(const nnvm::NodeAttrs &attrs,
+ const OpContext &ctx,
+ const std::vector<TBlob> &inputs,
+ const std::vector<OpReqType> &req,
+ const std::vector<TBlob> &outputs) {
+ using namespace mshadow;
+ using namespace mxnet_op;
+ const NumpyRayleighParam ¶m = nnvm::get<NumpyRayleighParam>(attrs.parsed);
+ Stream<xpu> *s = ctx.get_stream<xpu>();
+ Random<xpu, float> *prnd = ctx.requested[0].get_random<xpu, float>(s);
+ Tensor<xpu, 1, float> workspace =
+ ctx.requested[1].get_space_typed<xpu, 1, float>(Shape1(1), s);
+ Tensor<xpu, 1, float> uniform_tensor = outputs[1].FlatTo1D<xpu, float>(s);
+ Tensor<xpu, 1, float> indicator_device = workspace;
+ float indicator_host = 1.0;
+ float *indicator_device_ptr = indicator_device.dptr_;
+ Kernel<set_zero, xpu>::Launch(s, 1, indicator_device_ptr);
+ prnd->SampleUniform(&uniform_tensor, 0.0, 1.0);
+ if (param.scale.has_value()) {
+ CHECK_GE(param.scale.value(), 0.0) << "ValueError: expect scale >= 0";
+ MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+ Kernel<scalar_rayleigh_kernel<DType>, xpu>::Launch(
+ s, outputs[0].Size(), param.scale.value(),
+ uniform_tensor.dptr_, outputs[0].dptr<DType>());
+ });
+ } else {
+ MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, IType, {
+ Kernel<check_legal_scale_kernel<IType>, xpu>::Launch(
+ s, inputs[0].Size(), inputs[0].dptr<IType>(), indicator_device_ptr);
+ });
+ _copy<xpu>(s, &indicator_host, indicator_device_ptr);
+ CHECK_GE(indicator_host, 0.0) << "ValueError: expect scale >= 0";
+ mxnet::TShape new_lshape, new_oshape;
+ int ndim = FillShape(inputs[0].shape_, inputs[0].shape_, outputs[0].shape_,
+ &new_lshape, &new_lshape, &new_oshape);
+ MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, IType, {
+ MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, OType, {
+ BROADCAST_NDIM_SWITCH(ndim, NDim, {
+ Shape<NDim> oshape = new_oshape.get<NDim>();
+ Shape<NDim> stride = calc_stride(new_lshape.get<NDim>());
+ Kernel<rayleigh_kernel<NDim, IType, OType>, xpu>::Launch(
+ s, outputs[0].Size(), stride, oshape, inputs[0].dptr<IType>(),
+ uniform_tensor.dptr_, outputs[0].dptr<OType>());
+ });
+ });
+ });
+ }
+}
+
+template<typename xpu, int ndim, typename DType>
+inline void ScalarRayleighReparamBackwardImpl(const OpContext& ctx,
+ const std::vector<TBlob>& inputs,
+ const std::vector<OpReqType>& req,
+ const std::vector<TBlob>& outputs,
+ const mxnet::TShape& new_ishape,
+ const mxnet::TShape& new_oshape) {
+ using namespace mshadow;
+ using namespace mshadow::expr;
+ using namespace broadcast;
+ Stream<xpu> *s = ctx.get_stream<xpu>();
+ const TBlob igrad = outputs[0].reshape(new_ishape);
+ // inputs: [grad_from_samples, grad_from_noise(invisible), input_tensor,
+ // samples, noise]
+ const TBlob ograd = inputs[0].reshape(new_oshape);
+ const TBlob itensor = inputs[2].reshape(new_ishape);
+ const TBlob samples = inputs[3].reshape(new_oshape);
+ const TBlob noise = inputs[4].reshape(new_oshape);
+ size_t workspace_size =
+ ReduceWorkspaceSize<ndim, DType>(s, igrad.shape_, req[0], ograd.shape_);
+ Tensor<xpu, 1, char> workspace =
+ ctx.requested[0].get_space_typed<xpu, 1, char>(Shape1(workspace_size), s);
+ Reduce<red::sum, ndim, DType, op::mshadow_op::mul, op::mshadow_op::left>(
+ s, igrad, req[0], workspace, ograd, noise, noise);
+}
+
+template<typename xpu>
+void RayleighReparamBackward(const nnvm::NodeAttrs& attrs,
+ const OpContext& ctx,
Review comment:
alignment
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-mxnet] haojin2 merged pull request #17541: [numpy] add
op random.rayleigh
Posted by GitBox <gi...@apache.org>.
haojin2 merged pull request #17541: [numpy] add op random.rayleigh
URL: https://github.com/apache/incubator-mxnet/pull/17541
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services