Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Python Docstring Convetion #16550

Merged
merged 9 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions python/mxnet/kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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()])
Expand Down
20 changes: 6 additions & 14 deletions python/mxnet/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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
----------
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))

Expand Down
3 changes: 1 addition & 2 deletions python/mxnet/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def pause(profile_process='worker'):


def resume(profile_process='worker'):
"""
Resume paused profiling.
"""Resume paused profiling.

Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion python/mxnet/rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 6 additions & 16 deletions python/mxnet/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@
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)
]

@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):
Expand All @@ -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
-------
Expand All @@ -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:
Expand All @@ -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
----------
Expand Down
12 changes: 7 additions & 5 deletions python/mxnet/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,8 +1932,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():
...
Expand Down Expand Up @@ -2321,7 +2320,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)
Expand All @@ -2346,7 +2346,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':
Expand All @@ -2364,7 +2365,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"):
Expand Down
6 changes: 2 additions & 4 deletions python/mxnet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
----------
Expand Down