From 82ddc93e215e45419d3dc3db0ec30f24f40de851 Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Fri, 25 Oct 2019 01:10:07 +0900 Subject: [PATCH] Python Docstring Convetion (#16550) * Docstring convetnion for * Docstring convention for * Docstring convention for * Docstring convention for * Docstring convention for * Docstring convention for * Docstring convention * Revert removing new line * Remove white space --- python/mxnet/kvstore.py | 7 ++----- python/mxnet/metric.py | 20 ++++++-------------- python/mxnet/profiler.py | 3 +-- python/mxnet/rtc.py | 3 ++- python/mxnet/runtime.py | 22 ++++++---------------- python/mxnet/test_utils.py | 12 +++++++----- python/mxnet/util.py | 6 ++---- 7 files changed, 26 insertions(+), 47 deletions(-) diff --git a/python/mxnet/kvstore.py b/python/mxnet/kvstore.py index 5d332ff45ecb..61c64ec0984f 100644 --- a/python/mxnet/kvstore.py +++ b/python/mxnet/kvstore.py @@ -31,8 +31,7 @@ from .profiler import set_kvstore_handle def _ctype_key_value(keys, vals): - """ - Returns ctype arrays for the key-value args, and the whether string keys are used. + """Returns ctype arrays for the key-value args, and the whether string keys are used. For internal use only. """ if isinstance(keys, (tuple, list)): @@ -66,9 +65,7 @@ def _ctype_key_value(keys, vals): return (c_keys, c_handle_array(vals), use_str_keys) def _ctype_dict(param_dict): - """ - Returns ctype arrays for keys and values(converted to strings) in a dictionary - """ + """Returns ctype arrays for keys and values(converted to strings) in a dictionary""" assert(isinstance(param_dict, dict)), \ "unexpected type for param_dict: " + str(type(param_dict)) c_keys = c_array(ctypes.c_char_p, [c_str(k) for k in param_dict.keys()]) diff --git a/python/mxnet/metric.py b/python/mxnet/metric.py index 07ec2ef4d61d..6e2d66cb9d15 100644 --- a/python/mxnet/metric.py +++ b/python/mxnet/metric.py @@ -153,8 +153,7 @@ def reset(self): self.global_sum_metric = 0.0 def reset_local(self): - """Resets the local portion of the internal evaluation results - to initial state.""" + """Resets the local portion of the internal evaluation results to initial state.""" self.num_inst = 0 self.sum_metric = 0.0 @@ -372,8 +371,7 @@ def reset(self): pass def reset_local(self): - """Resets the local portion of the internal evaluation results - to initial state.""" + """Resets the local portion of the internal evaluation results to initial state.""" try: for metric in self.metrics: metric.reset_local() @@ -592,8 +590,7 @@ def update(self, labels, preds): class _BinaryClassificationMetrics(object): - """ - Private container class for classification metric statistics. True/false positive and + """Private container class for classification metric statistics. True/false positive and true/false negative counts are sufficient statistics for various classification metrics. This class provides the machinery to track those statistics across mini-batches of (label, prediction) pairs. @@ -610,9 +607,7 @@ def __init__(self): self.global_true_negatives = 0 def update_binary_stats(self, label, pred): - """ - Update various binary classification counts for a single (label, pred) - pair. + """Update various binary classification counts for a single (label, pred) pair. Parameters ---------- @@ -691,9 +686,7 @@ def global_fscore(self): return 0. def matthewscc(self, use_global=False): - """ - Calculate the Matthew's Correlation Coefficent - """ + """Calculate the Matthew's Correlation Coefficent""" if use_global: if not self.global_total_examples: return 0. @@ -1604,8 +1597,7 @@ def reset(self): self.reset_local() def reset_local(self): - """Resets the local portion of the internal evaluation results - to initial state.""" + """Resets the local portion of the internal evaluation results to initial state.""" self.num_inst = 0. self.lcm = numpy.zeros((self.k, self.k)) diff --git a/python/mxnet/profiler.py b/python/mxnet/profiler.py index 7dbc060ed60f..8e8ac87c9e06 100644 --- a/python/mxnet/profiler.py +++ b/python/mxnet/profiler.py @@ -207,8 +207,7 @@ def pause(profile_process='worker'): def resume(profile_process='worker'): - """ - Resume paused profiling. + """Resume paused profiling. Parameters ---------- diff --git a/python/mxnet/rtc.py b/python/mxnet/rtc.py index 4dea0e656b7e..5dfc5ea6dfe2 100644 --- a/python/mxnet/rtc.py +++ b/python/mxnet/rtc.py @@ -172,7 +172,8 @@ def get_kernel(self, name, signature): class CudaKernel(object): """Constructs CUDA kernel. Should be created by `CudaModule.get_kernel`, - not intended to be used by users.""" + not intended to be used by users. + """ def __init__(self, handle, name, is_ndarray, dtypes): self.handle = handle self._name = name diff --git a/python/mxnet/runtime.py b/python/mxnet/runtime.py index 0f7de76937c0..f2e98fe674fa 100644 --- a/python/mxnet/runtime.py +++ b/python/mxnet/runtime.py @@ -26,9 +26,7 @@ from .base import _LIB, check_call class Feature(ctypes.Structure): - """ - Compile time feature description, member fields: `name` and `enabled`. - """ + """Compile time feature description, member fields: `name` and `enabled`.""" _fields_ = [ ("_name", ctypes.c_char_p), ("_enabled", ctypes.c_bool) @@ -36,16 +34,12 @@ class Feature(ctypes.Structure): @property def name(self): - """ - Feature name. - """ + """Feature name.""" return self._name.decode() @property def enabled(self): - """ - True if MXNet was compiled with the given compile-time feature. - """ + """True if MXNet was compiled with the given compile-time feature.""" return self._enabled def __repr__(self): @@ -55,8 +49,7 @@ def __repr__(self): return "✖ {}".format(self.name) def feature_list(): - """ - Check the library for compile-time features. The list of features are maintained in libinfo.h and libinfo.cc + """Check the library for compile-time features. The list of features are maintained in libinfo.h and libinfo.cc Returns ------- @@ -70,9 +63,7 @@ def feature_list(): return features class Features(collections.OrderedDict): - """ - OrderedDict of name to Feature - """ + """OrderedDict of name to Feature""" instance = None def __new__(cls): if cls.instance is None: @@ -84,8 +75,7 @@ def __repr__(self): return str(list(self.values())) def is_enabled(self, feature_name): - """ - Check for a particular feature by name + """Check for a particular feature by name Parameters ---------- diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py index 4862aee8570d..6c8fefca4490 100644 --- a/python/mxnet/test_utils.py +++ b/python/mxnet/test_utils.py @@ -1935,8 +1935,7 @@ def same_array(array1, array2): @contextmanager def discard_stderr(): - """ - Discards error output of a routine if invoked as: + """Discards error output of a routine if invoked as: with discard_stderr(): ... @@ -2324,7 +2323,8 @@ def __exit__(self, ptype, value, trace): def collapse_sum_like(a, shape): """Given `a` as a numpy ndarray, perform reduce_sum on `a` over the axes that do not - exist in `shape`. Note that an ndarray with `shape` must be broadcastable to `a`.""" + exist in `shape`. Note that an ndarray with `shape` must be broadcastable to `a`. + """ assert len(a.shape) >= len(shape) if np.prod(shape) == 0 or a.size == 0: return np.zeros(shape, dtype=a.dtype) @@ -2349,7 +2349,8 @@ def is_cd_run(): def has_tvm_ops(): """Returns True if MXNet is compiled with TVM generated operators. If current ctx - is GPU, it only returns True for CUDA compute capability > 52 where FP16 is supported.""" + is GPU, it only returns True for CUDA compute capability > 52 where FP16 is supported. + """ built_with_tvm_op = _features.is_enabled("TVM_OP") ctx = current_context() if ctx.device_type == 'gpu': @@ -2367,7 +2368,8 @@ def has_tvm_ops(): def is_op_runnable(): """Returns True for all CPU tests. Returns True for GPU tests that are either of the following. 1. Built with USE_TVM_OP=0. - 2. Built with USE_TVM_OP=1, but with compute capability >= 53.""" + 2. Built with USE_TVM_OP=1, but with compute capability >= 53. + """ ctx = current_context() if ctx.device_type == 'gpu': if not _features.is_enabled("TVM_OP"): diff --git a/python/mxnet/util.py b/python/mxnet/util.py index cef034fd0caa..9e15caae9698 100644 --- a/python/mxnet/util.py +++ b/python/mxnet/util.py @@ -60,8 +60,7 @@ def get_gpu_memory(gpu_dev_id): def set_np_shape(active): - """ - Turns on/off NumPy shape semantics, in which `()` represents the shape of scalar tensors, + """Turns on/off NumPy shape semantics, in which `()` represents the shape of scalar tensors, and tuples with `0` elements, for example, `(0,)`, `(1, 0, 2)`, represent the shapes of zero-size tensors. This is turned off by default for keeping backward compatibility. @@ -568,8 +567,7 @@ def hybrid_forward(self, F, x, w): def np_ufunc_legal_option(key, value): - """ - Checking if ufunc arguments are legal inputs + """Checking if ufunc arguments are legal inputs Parameters ----------