From b35d8c9021446df3f0c6a117db78fa4a143a8656 Mon Sep 17 00:00:00 2001 From: Piyush Ghai Date: Tue, 5 Feb 2019 11:50:59 -0800 Subject: [PATCH 1/2] updating scala docs --- .../main/scala/org/apache/mxnet/Context.scala | 17 ++++----- .../main/scala/org/apache/mxnet/NDArray.scala | 36 ++++++++++--------- .../apache/mxnet/infer/ObjectDetector.scala | 3 +- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala b/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala index ab44f434b160..3d562fc0715b 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala @@ -38,11 +38,12 @@ object Context { } /** - * Constructing a context. - - * @param deviceTypeName {'cpu', 'gpu'} String representing the device type - * @param deviceId (default=0) The device id of the device, needed for GPU - */ + * Constructing a context which is used to specify the device and device type that will + * be utilized by the engine. + * + * @param deviceTypeName {'cpu', 'gpu'} String representing the device type + * @param deviceId The device id of the device, needed for GPU + */ class Context(deviceTypeName: String, val deviceId: Int = 0) extends Serializable { val deviceTypeid: Int = Context.devstr2type(deviceTypeName) @@ -61,9 +62,9 @@ class Context(deviceTypeName: String, val deviceId: Int = 0) extends Serializabl } /** - * Return device type of current context. - * @return device_type - */ + * Return device type of current context. + * @return device_type + */ def deviceType: String = Context.devtype2str(deviceTypeid) override def toString: String = { 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 4324b3dbe63e..ca2e986e7f29 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 @@ -728,12 +728,15 @@ object NDArray extends NDArrayBase { } /** - * NDArray object in mxnet. - * NDArray is basic ndarray/Tensor like data structure in mxnet.
- * - * WARNING: it is your responsibility to clear this object through dispose(). - * - */ + * NDArray object in mxnet. + * NDArray is basic ndarray/Tensor like data structure in mxnet.
+ * + * NOTE: NDArray is stored in native memory. Use NDArray in a try-with-resources() construct + * or a [[org.apache.mxnet.ResourceScope]] in a try-with-resource to have them + * automatically disposed. You can explicitly control the lifetime of NDArray + * by calling dispose manually. Failure to do this will result in leaking native memory. + * + */ class NDArray private[mxnet](private[mxnet] val handle: NDArrayHandle, val writable: Boolean = true, addToCollector: Boolean = true) extends NativeResource { @@ -775,21 +778,22 @@ class NDArray private[mxnet](private[mxnet] val handle: NDArrayHandle, } /** - * Dispose all NDArrays who help to construct this array.
- * e.g. (a * b + c).disposeDeps() will dispose a, b, c (including their deps) and a * b - * @return this array - */ + * Dispose all NDArrays who help to construct this array.
+ * e.g. (a * b + c).disposeDeps() will dispose a, b, c (including their deps) and a * b + * @return this NDArray + */ def disposeDeps(): NDArray = { disposeDepsExcept() } /** - * Dispose all NDArrays who help to construct this array, excepts those in the arguments.
- * e.g. (a * b + c).disposeDepsExcept(a, b) - * will dispose c and a * b. - * Note that a, b's dependencies will not be disposed either. - * @return this array - */ + * Dispose all NDArrays who help to construct this array, excepts those in the arguments.
+ * e.g. (a * b + c).disposeDepsExcept(a, b) + * will dispose c and a * b. + * Note that a, b's dependencies will not be disposed either. + * @param arrs array of NDArrays + * @return this array + */ def disposeDepsExcept(arrs: NDArray*): NDArray = { if (dependencies != null) { val excepts = mutable.HashSet.empty[Long] diff --git a/scala-package/infer/src/main/scala/org/apache/mxnet/infer/ObjectDetector.scala b/scala-package/infer/src/main/scala/org/apache/mxnet/infer/ObjectDetector.scala index 78b237a4a9c6..7146156d7cc5 100644 --- a/scala-package/infer/src/main/scala/org/apache/mxnet/infer/ObjectDetector.scala +++ b/scala-package/infer/src/main/scala/org/apache/mxnet/infer/ObjectDetector.scala @@ -28,7 +28,8 @@ import org.apache.mxnet.Context import scala.collection.mutable.ListBuffer /** - * A class for object detection tasks + * The ObjectDetector class helps to run ObjectDetection tasks where the goal + * is to find bounding boxes and corresponding labels for objects in a image. * * @param modelPathPrefix Path prefix from where to load the model artifacts. * These include the symbol, parameters, and synset.txt. From 9ec9943d4295d4f21220d1b59daebb8a62212f95 Mon Sep 17 00:00:00 2001 From: Piyush Ghai Date: Wed, 6 Feb 2019 09:38:18 -0800 Subject: [PATCH 2/2] Addressed PR feedback --- .../core/src/main/scala/org/apache/mxnet/Context.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala b/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala index 3d562fc0715b..b04cd31ff67f 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/Context.scala @@ -42,7 +42,7 @@ object Context { * be utilized by the engine. * * @param deviceTypeName {'cpu', 'gpu'} String representing the device type - * @param deviceId The device id of the device, needed for GPU + * @param deviceId (default=0) The device id of the device, needed for GPU */ class Context(deviceTypeName: String, val deviceId: Int = 0) extends Serializable { val deviceTypeid: Int = Context.devstr2type(deviceTypeName)