def _repr(obj, *args, **kwargs): """Helper to get a structured __repr__ for all objects. Parameters ---------- obj : object This will typically be `self` of the to be documented object. *args, **kwargs : str An arbitrary number of additional items. All of them must be of type `str`. All items will be appended comma separated to the class name. Keyword arguments will be appended as `key`=`value. Returns ------- str """ cls_name = obj.__class__.__name__ truncate = cfg.get_as_dtype('verbose', 'truncate repr', int, default=200) # -5 to take (...) into account max_length = truncate - 5 - len(cls_name) if max_length < 0: max_length = 0 auto_repr = ', '.join(list(args) + ["%s=%s" % (k, v) for k, v in kwargs.iteritems()]) if not truncate is None and len(auto_repr) > max_length: auto_repr = auto_repr[:max_length] + '...' # finally wrap in <> and return # + instead of '%s' for bits of speedup return "%s(%s)" % (cls_name, auto_repr)
def __check_rpy2(): """Check either rpy2 is available and also set it for the sane execution """ import rpy2 versions['rpy2'] = SmartVersion(rpy2.__version__) import rpy2.robjects r = rpy2.robjects.r r.options(warn=cfg.get_as_dtype('rpy', 'warn', dtype=int, default=-1)) # To shut R up while it is importing libraries to do not ruin out # doctests r.library = _R_library
def _str(obj, *args, **kwargs): """Helper to get a structured __str__ for all objects. If an object has a `descr` attribute, its content will be used instead of an auto-generated description. Optional additional information might be added under certain debugging conditions (e.g. `id(obj)`). Parameters ---------- obj : object This will typically be `self` of the to be documented object. *args, **kwargs : str An arbitrary number of additional items. All of them must be of type `str`. All items will be appended comma separated to the class name. Keyword arguments will be appended as `key`=`value. Returns ------- str """ truncate = cfg.get_as_dtype('verbose', 'truncate str', int, default=200) s = None # don't do descriptions for dicts like our collections as they might contain # an actual item 'descr' if hasattr(obj, 'descr') and not isinstance(obj, dict): s = obj.descr if s is None: s = obj.__class__.__name__ auto_descr = ', '.join(list(args) + ["%s=%s" % (k, v) for k, v in kwargs.iteritems()]) if len(auto_descr): s = s + ': ' + auto_descr if truncate is not None and len(s) > truncate - 5: # -5 to take <...> into account s = s[:truncate-5] + '...' if __debug__ and 'DS_ID' in debug.active: # in case there was nothing but the class name if len(s): if s[-1]: s += ',' s += ' ' s += _strid(obj) # finally wrap in <> and return # + instead of '%s' for bits of speedup return '<' + s + '>'
def _str(obj, *args, **kwargs): """Helper to get a structured __str__ for all objects. If an object has a `descr` attribute, its content will be used instead of an auto-generated description. Optional additional information might be added under certain debugging conditions (e.g. `id(obj)`). Parameters ---------- obj : object This will typically be `self` of the to be documented object. *args, **kwargs : str An arbitrary number of additional items. All of them must be of type `str`. All items will be appended comma separated to the class name. Keyword arguments will be appended as `key`=`value. Returns ------- str """ truncate = cfg.get_as_dtype('verbose', 'truncate str', int, default=200) s = None # don't do descriptions for dicts like our collections as they might contain # an actual item 'descr' if hasattr(obj, 'descr') and not isinstance(obj, dict): s = obj.descr if s is None: s = obj.__class__.__name__ auto_descr = ', '.join(list(args) + ["%s=%s" % (k, v) for k, v in kwargs.iteritems()]) if len(auto_descr): s = s + ': ' + auto_descr if not truncate is None and len(s) > truncate - 5: # -5 to take <...> into account s = s[:truncate-5] + '...' if __debug__ and 'DS_ID' in debug.active: # in case there was nothing but the class name if len(s): if s[-1]: s += ',' s += ' ' s += _strid(obj) # finally wrap in <> and return # + instead of '%s' for bits of speedup return '<' + s + '>'
def _str(obj, *args, **kwargs): """Helper to get a structured __str__ for all objects. If an object has a `descr` attribute, its content will be used instead of an auto-generated description. Optional additional information might be added under certain debugging conditions (e.g. `id(obj)`). Parameters ---------- obj : object This will typically be `self` of the to be documented object. *args, **kwargs : str An arbitrary number of additional items. All of them must be of type `str`. All items will be appended comma separated to the class name. Keyword arguments will be appended as `key`=`value. Returns ------- str """ truncate = cfg.get_as_dtype("verbose", "truncate str", int, default=200) s = None if hasattr(obj, "descr"): s = obj.descr if s is None: s = obj.__class__.__name__ auto_descr = ", ".join(list(args) + ["%s=%s" % (k, v) for k, v in kwargs.iteritems()]) if len(auto_descr): s = s + ": " + auto_descr if not truncate is None and len(s) > truncate - 5: # -5 to take <...> into account s = s[: truncate - 5] + "..." if __debug__ and "DS_ID" in debug.active: # in case there was nothing but the class name if len(s): if s[-1]: s += "," s += " " s += "id=%i" % id(obj) # finally wrap in <> and return # + instead of '%s' for bits of speedup return "<" + s + ">"
from mvpa2 import cfg, externals from mvpa2.datasets.base import Dataset, HollowSamples from mvpa2.generators.partition import OddEvenPartitioner from mvpa2.misc.data_generators import * from mvpa2.testing.tools import reseed_rng __all__ = [ 'datasets', 'get_random_rotation', 'saveload_warehouse', 'pure_multivariate_signal' ] # Define datasets to be used all over. Split-half later on is used to # split into training/testing # snr_scale = cfg.get_as_dtype('tests', 'snr scale', float, default=1.0) specs = { 'large': { 'perlabel': 99, 'nchunks': 11, 'nfeatures': 20, 'snr': 8 * snr_scale }, 'medium': { 'perlabel': 24, 'nchunks': 6, 'nfeatures': 14, 'snr': 8 * snr_scale }, 'small': {
import sys import numpy as np from mvpa2 import cfg, externals from mvpa2.datasets.base import Dataset, HollowSamples from mvpa2.generators.partition import OddEvenPartitioner from mvpa2.misc.data_generators import * from mvpa2.testing.tools import reseed_rng __all__ = [ 'datasets', 'get_random_rotation', 'saveload_warehouse', 'pure_multivariate_signal'] # Define datasets to be used all over. Split-half later on is used to # split into training/testing # snr_scale = cfg.get_as_dtype('tests', 'snr scale', float, default=1.0) specs = {'large' : { 'perlabel': 99, 'nchunks': 11, 'nfeatures': 20, 'snr': 8 * snr_scale}, 'medium' :{ 'perlabel': 24, 'nchunks': 6, 'nfeatures': 14, 'snr': 8 * snr_scale}, 'small' : { 'perlabel': 12, 'nchunks': 4, 'nfeatures': 6, 'snr' : 14 * snr_scale} } # to assure reproducibility -- lets reseed the RNG at this point @reseed_rng() def generate_testing_datasets(specs): # Lets permute upon each invocation of test, so we could possibly # trigger some funny cases nonbogus_pool = np.random.permutation([0, 1, 3, 5])