[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17316: [NumPy] add op random.laplace

2020-01-15 Thread GitBox
haojin2 commented on a change in pull request #17316: [NumPy] add op 
random.laplace
URL: https://github.com/apache/incubator-mxnet/pull/17316#discussion_r366767278
 
 

 ##
 File path: src/operator/numpy/random/np_laplace_op.h
 ##
 @@ -0,0 +1,218 @@
+/*
+ * 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_laplace_op.h
+ * \brief Operator for numpy sampling from Laplace distributions
+ */
+#ifndef MXNET_OPERATOR_NUMPY_RANDOM_NP_LAPLACE_OP_H_
+#define MXNET_OPERATOR_NUMPY_RANDOM_NP_LAPLACE_OP_H_
+
+#include 
+#include 
+#include 
+#include 
+#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 NumpyLaplaceParam : public dmlc::Parameter {
+  dmlc::optional loc;
+  dmlc::optional scale;
+  std::string ctx;
+  int dtype;
+  dmlc::optional> size;
+  DMLC_DECLARE_PARAMETER(NumpyLaplaceParam) {
+DMLC_DECLARE_FIELD(loc);
+DMLC_DECLARE_FIELD(scale);
+DMLC_DECLARE_FIELD(size)
+.set_default(dmlc::optional>())
 
 Review comment:
   2-space indentation.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17316: [NumPy] add op random.laplace

2020-01-15 Thread GitBox
haojin2 commented on a change in pull request #17316: [NumPy] add op 
random.laplace
URL: https://github.com/apache/incubator-mxnet/pull/17316#discussion_r366767071
 
 

 ##
 File path: python/mxnet/symbol/numpy/random.py
 ##
 @@ -290,6 +290,54 @@ def choice(a, size=None, replace=True, p=None, ctx=None, 
out=None):
 return _npi.choice(p, a=a, size=size, replace=replace, ctx=ctx, 
weighted=True, out=out)
 
 
+def laplace(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None):
+r"""Draw random samples from a Laplace distribution.
+
+Samples are distributed according to a Laplace distribution parametrized
+by *loc* (mean) and *scale* (the exponential decay).
+
+Parameters
+--
+loc : float, The position of the distribution peak.
+
+scale : float, the exponential decay.
+
+size : int or tuple of ints, optional. 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.
+
+dtype : {'float16', 'float32', 'float64'}, optional
+Data type of output samples. Default is 'float32'
+ctx : Context, optional
+Device context of output. Default is current context.
+out : ``ndarray``, optional
+Store output to an existing ``ndarray``.
+
+Returns
+---
+out : _Symbol (symbol representing `mxnet.numpy.ndarray` in computational 
graphs)
+Drawn samples from the parameterized Laplace distribution.
+"""
+from ._symbol import _Symbol as np_symbol
+input_type = (isinstance(loc, np_symbol), isinstance(scale, np_symbol))
+if dtype is None:
+dtype = 'float32'
+if ctx is None:
+ctx = current_context()
+if size == ():
+size = None
+if input_type == (True, True):
+return _npi.laplace(loc, scale, loc=None, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+elif input_type == (False, True):
+return _npi.laplace(scale, loc=loc, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+elif input_type == (True, False):
+return _npi.laplace(loc, loc=None, scale=scale, size=size,
+   ctx=ctx, dtype=dtype, out=out)
 
 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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17316: [NumPy] add op random.laplace

2020-01-15 Thread GitBox
haojin2 commented on a change in pull request #17316: [NumPy] add op 
random.laplace
URL: https://github.com/apache/incubator-mxnet/pull/17316#discussion_r366766965
 
 

 ##
 File path: python/mxnet/symbol/numpy/random.py
 ##
 @@ -290,6 +290,54 @@ def choice(a, size=None, replace=True, p=None, ctx=None, 
out=None):
 return _npi.choice(p, a=a, size=size, replace=replace, ctx=ctx, 
weighted=True, out=out)
 
 
+def laplace(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None):
+r"""Draw random samples from a Laplace distribution.
+
+Samples are distributed according to a Laplace distribution parametrized
+by *loc* (mean) and *scale* (the exponential decay).
+
+Parameters
+--
+loc : float, The position of the distribution peak.
+
+scale : float, the exponential decay.
+
+size : int or tuple of ints, optional. 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.
+
+dtype : {'float16', 'float32', 'float64'}, optional
+Data type of output samples. Default is 'float32'
+ctx : Context, optional
+Device context of output. Default is current context.
+out : ``ndarray``, optional
+Store output to an existing ``ndarray``.
+
+Returns
+---
+out : _Symbol (symbol representing `mxnet.numpy.ndarray` in computational 
graphs)
+Drawn samples from the parameterized Laplace distribution.
+"""
+from ._symbol import _Symbol as np_symbol
+input_type = (isinstance(loc, np_symbol), isinstance(scale, np_symbol))
+if dtype is None:
+dtype = 'float32'
+if ctx is None:
+ctx = current_context()
+if size == ():
+size = None
+if input_type == (True, True):
+return _npi.laplace(loc, scale, loc=None, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
 
 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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17316: [NumPy] add op random.laplace

2020-01-15 Thread GitBox
haojin2 commented on a change in pull request #17316: [NumPy] add op 
random.laplace
URL: https://github.com/apache/incubator-mxnet/pull/17316#discussion_r366767024
 
 

 ##
 File path: python/mxnet/symbol/numpy/random.py
 ##
 @@ -290,6 +290,54 @@ def choice(a, size=None, replace=True, p=None, ctx=None, 
out=None):
 return _npi.choice(p, a=a, size=size, replace=replace, ctx=ctx, 
weighted=True, out=out)
 
 
+def laplace(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None):
+r"""Draw random samples from a Laplace distribution.
+
+Samples are distributed according to a Laplace distribution parametrized
+by *loc* (mean) and *scale* (the exponential decay).
+
+Parameters
+--
+loc : float, The position of the distribution peak.
+
+scale : float, the exponential decay.
+
+size : int or tuple of ints, optional. 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.
+
+dtype : {'float16', 'float32', 'float64'}, optional
+Data type of output samples. Default is 'float32'
+ctx : Context, optional
+Device context of output. Default is current context.
+out : ``ndarray``, optional
+Store output to an existing ``ndarray``.
+
+Returns
+---
+out : _Symbol (symbol representing `mxnet.numpy.ndarray` in computational 
graphs)
+Drawn samples from the parameterized Laplace distribution.
+"""
+from ._symbol import _Symbol as np_symbol
+input_type = (isinstance(loc, np_symbol), isinstance(scale, np_symbol))
+if dtype is None:
+dtype = 'float32'
+if ctx is None:
+ctx = current_context()
+if size == ():
+size = None
+if input_type == (True, True):
+return _npi.laplace(loc, scale, loc=None, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+elif input_type == (False, True):
+return _npi.laplace(scale, loc=loc, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
 
 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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17316: [NumPy] add op random.laplace

2020-01-15 Thread GitBox
haojin2 commented on a change in pull request #17316: [NumPy] add op 
random.laplace
URL: https://github.com/apache/incubator-mxnet/pull/17316#discussion_r366767094
 
 

 ##
 File path: python/mxnet/symbol/numpy/random.py
 ##
 @@ -290,6 +290,54 @@ def choice(a, size=None, replace=True, p=None, ctx=None, 
out=None):
 return _npi.choice(p, a=a, size=size, replace=replace, ctx=ctx, 
weighted=True, out=out)
 
 
+def laplace(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None):
+r"""Draw random samples from a Laplace distribution.
+
+Samples are distributed according to a Laplace distribution parametrized
+by *loc* (mean) and *scale* (the exponential decay).
+
+Parameters
+--
+loc : float, The position of the distribution peak.
+
+scale : float, the exponential decay.
+
+size : int or tuple of ints, optional. 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.
+
+dtype : {'float16', 'float32', 'float64'}, optional
+Data type of output samples. Default is 'float32'
+ctx : Context, optional
+Device context of output. Default is current context.
+out : ``ndarray``, optional
+Store output to an existing ``ndarray``.
+
+Returns
+---
+out : _Symbol (symbol representing `mxnet.numpy.ndarray` in computational 
graphs)
+Drawn samples from the parameterized Laplace distribution.
+"""
+from ._symbol import _Symbol as np_symbol
+input_type = (isinstance(loc, np_symbol), isinstance(scale, np_symbol))
+if dtype is None:
+dtype = 'float32'
+if ctx is None:
+ctx = current_context()
+if size == ():
+size = None
+if input_type == (True, True):
+return _npi.laplace(loc, scale, loc=None, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+elif input_type == (False, True):
+return _npi.laplace(scale, loc=loc, scale=None, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+elif input_type == (True, False):
+return _npi.laplace(loc, loc=None, scale=scale, size=size,
+   ctx=ctx, dtype=dtype, out=out)
+else:
+return _npi.laplace(loc=loc, scale=scale, size=size,
+   ctx=ctx, dtype=dtype, out=out)
 
 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:
us...@infra.apache.org


With regards,
Apache Git Services