From 86036d0d9385cad831a79277176f4bf3f0670d96 Mon Sep 17 00:00:00 2001 From: kiendang Date: Wed, 9 Jan 2019 22:20:26 +0800 Subject: [PATCH 1/6] Add default arguments for arange --- .../core/src/main/scala/org/apache/mxnet/NDArray.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala index 125958150b72..277863eada8f 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala @@ -412,8 +412,9 @@ object NDArray extends NDArrayBase { * @param dType The data type of the `NDArray`. The default datatype is `DType.Float32`. * @return NDArray of evenly spaced values in the specified range. */ - def arange(start: Float, stop: Option[Float], step: Float, - repeat: Int, ctx: Context, dType: DType): NDArray = { + def arange(start: Float, stop: Option[Float] = None, step: Float = 1.0f, + repeat: Int = 1, ctx: Context = Context.defaultCtx, + dType: DType = Base.MX_REAL_TYPE): NDArray = { val params = Map("start" -> start, "step" -> step, "repeat" -> repeat, "infer_range" -> false, "ctx" -> ctx.toString, "dtype" -> dType.toString()) val fParams = if (stop == None) params else params ++ Map("stop" -> stop.get) From 1a48ba159a531553143f48bb157c2893d841ed82 Mon Sep 17 00:00:00 2001 From: kiendang Date: Wed, 9 Jan 2019 22:25:48 +0800 Subject: [PATCH 2/6] Remove redundant tag --- .../core/src/main/scala/org/apache/mxnet/NDArray.scala | 3 --- 1 file changed, 3 deletions(-) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala index 277863eada8f..cc83a620c3da 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala @@ -405,9 +405,6 @@ object NDArray extends NDArrayBase { * @param stop End of interval. * @param step Spacing between values. The default step size is 1. * @param repeat Number of times to repeat each element. The default repeat count is 1. - * @param infer_range - * When set to True, infer the stop position from the start, step, - * repeat, and output tensor size. * @param ctx Device context. Default context is the current default context. * @param dType The data type of the `NDArray`. The default datatype is `DType.Float32`. * @return NDArray of evenly spaced values in the specified range. From 153d7b72688d89ad1fc78660350036256cfdbd10 Mon Sep 17 00:00:00 2001 From: kiendang Date: Thu, 10 Jan 2019 00:31:51 +0800 Subject: [PATCH 3/6] Update test --- .../scala/org/apache/mxnet/NDArraySuite.scala | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scala-package/core/src/test/scala/org/apache/mxnet/NDArraySuite.scala b/scala-package/core/src/test/scala/org/apache/mxnet/NDArraySuite.scala index 2db9ff11b374..ebc4ea5dcbfb 100644 --- a/scala-package/core/src/test/scala/org/apache/mxnet/NDArraySuite.scala +++ b/scala-package/core/src/test/scala/org/apache/mxnet/NDArraySuite.scala @@ -167,11 +167,21 @@ class NDArraySuite extends FunSuite with BeforeAndAfterAll with Matchers { val stop = start + scala.util.Random.nextFloat() * 100 val step = scala.util.Random.nextFloat() * 4 val repeat = 1 - val result = (start.toDouble until stop.toDouble by step.toDouble) - .flatMap(x => Array.fill[Float](repeat)(x.toFloat)) - val range = NDArray.arange(start = start, stop = Some(stop), step = step, - repeat = repeat, ctx = Context.cpu(), dType = DType.Float32) - assert(CheckUtils.reldiff(result.toArray, range.toArray) <= 1e-4f) + + val result1 = (start.toDouble until stop.toDouble by step.toDouble) + .flatMap(x => Array.fill[Float](repeat)(x.toFloat)) + val range1 = NDArray.arange(start = start, stop = Some(stop), step = step, + repeat = repeat) + assert(CheckUtils.reldiff(result1.toArray, range1.toArray) <= 1e-4f) + + val result2 = (0.0 until stop.toDouble by step.toDouble) + .flatMap(x => Array.fill[Float](repeat)(x.toFloat)) + val range2 = NDArray.arange(stop, step = step, repeat = repeat) + assert(CheckUtils.reldiff(result2.toArray, range2.toArray) <= 1e-4f) + + val result3 = 0f to stop by 1f + val range3 = NDArray.arange(stop) + assert(CheckUtils.reldiff(result3.toArray, range3.toArray) <= 1e-4f) } } From a0432c2865e2520d5ae61166b2a2709d4d632280 Mon Sep 17 00:00:00 2001 From: kiendang Date: Tue, 29 Jan 2019 17:29:16 +0800 Subject: [PATCH 4/6] Remove infer_range for python ndarray.arange --- python/mxnet/ndarray/ndarray.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 9a62620da85c..bc026699b613 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -2536,7 +2536,7 @@ def moveaxis(tensor, source, destination): # pylint: disable= no-member, protected-access, too-many-arguments, redefined-outer-name -def arange(start, stop=None, step=1.0, repeat=1, infer_range=False, ctx=None, dtype=mx_real_t): +def arange(start, stop=None, step=1.0, repeat=1, ctx=None, dtype=mx_real_t): """Returns evenly spaced values within a given interval. Values are generated within the half-open interval [`start`, `stop`). In other @@ -2554,9 +2554,6 @@ def arange(start, stop=None, step=1.0, repeat=1, infer_range=False, ctx=None, dt Spacing between values. The default step size is 1. repeat : int, optional Number of times to repeat each element. The default repeat count is 1. - infer_range : boolean, optional - When set to True, infer the stop position from the start, step, - repeat, and output tensor size. ctx : Context, optional Device context. Default context is the current default context. dtype : str or numpy.dtype, optional @@ -2583,7 +2580,7 @@ def arange(start, stop=None, step=1.0, repeat=1, infer_range=False, ctx=None, dt if ctx is None: ctx = current_context() return _internal._arange(start=start, stop=stop, step=step, repeat=repeat, - infer_range=infer_range, dtype=dtype, ctx=str(ctx)) + infer_range=False, dtype=dtype, ctx=str(ctx)) # pylint: enable= no-member, protected-access, too-many-arguments From c6beec204ef536ac86eeb47c03902d5013bb770f Mon Sep 17 00:00:00 2001 From: kiendang Date: Tue, 29 Jan 2019 17:35:35 +0800 Subject: [PATCH 5/6] Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b9f84d592a70..80bacfd0374d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -193,6 +193,7 @@ List of Contributors * [Yuxi Hu](https://github.com/yuxihu) * [Harsh Patel](https://github.com/harshp8l) * [Xiao Wang](https://github.com/BeyonderXX) +* [Dang Trung Kien](https://github.com/kiendang) Label Bot --------- From fc124aa21a5a5cca0206c8a13ace6c459420648d Mon Sep 17 00:00:00 2001 From: kiendang Date: Thu, 31 Jan 2019 16:38:20 +0800 Subject: [PATCH 6/6] Deprecate infer_range argument in ndarray.arange --- python/mxnet/ndarray/ndarray.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index f09a6217473b..351c013d9c04 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -2544,7 +2544,7 @@ def moveaxis(tensor, source, destination): # pylint: disable= no-member, protected-access, too-many-arguments, redefined-outer-name -def arange(start, stop=None, step=1.0, repeat=1, ctx=None, dtype=mx_real_t): +def arange(start, stop=None, step=1.0, repeat=1, infer_range=None, ctx=None, dtype=mx_real_t): """Returns evenly spaced values within a given interval. Values are generated within the half-open interval [`start`, `stop`). In other @@ -2562,6 +2562,9 @@ def arange(start, stop=None, step=1.0, repeat=1, ctx=None, dtype=mx_real_t): Spacing between values. The default step size is 1. repeat : int, optional Number of times to repeat each element. The default repeat count is 1. + infer_range : boolean, optional + When set to True, infer the stop position from the start, step, + repeat, and output tensor size. ctx : Context, optional Device context. Default context is the current default context. dtype : str or numpy.dtype, optional @@ -2585,6 +2588,9 @@ def arange(start, stop=None, step=1.0, repeat=1, ctx=None, dtype=mx_real_t): >>> mx.nd.arange(2, 6, step=2, repeat=3, dtype='int32').asnumpy() array([2, 2, 2, 4, 4, 4], dtype=int32) """ + if infer_range is not None: + warnings.warn('`infer_range` argument has been deprecated', + DeprecationWarning) if ctx is None: ctx = current_context() return _internal._arange(start=start, stop=stop, step=step, repeat=repeat,