def term_echo(command, nindent=<NUM_LIT:0>, env=None, fpointer=None, cols=<NUM_LIT>):

<EOL>os.environ["<STR_LIT>"] = str(cols)<EOL>command_int = command<EOL>if env:<EOL><INDENT>for var, repl in env.items():<EOL><INDENT>command_int = command_int.replace("<STR_LIT>" + var + "<STR_LIT:}>", repl)<EOL><DEDENT><DEDENT>tokens = command_int.split("<STR_LIT:U+0020>")<EOL>if (platform.system().lower() == "<STR_LIT>") and (tokens[<NUM_LIT:0>].endswith("<STR_LIT>")):<EOL><INDENT>tokens = [sys.executable] + tokens<EOL><DEDENT>proc = subprocess.Popen(tokens, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)<EOL>stdout = proc.communicate()[<NUM_LIT:0>]<EOL>if sys.hexversion >= <NUM_LIT>:<EOL><INDENT>stdout = stdout.decode("<STR_LIT:utf-8>")<EOL><DEDENT>stdout = stdout.split("<STR_LIT:\n>")<EOL>indent = nindent * "<STR_LIT:U+0020>"<EOL>fpointer("<STR_LIT:\n>", dedent=False)<EOL>fpointer("<STR_LIT>".format(indent), dedent=False)<EOL>fpointer("<STR_LIT:\n>", dedent=False)<EOL>fpointer("<STR_LIT>".format(indent, command), dedent=False)<EOL>for line in stdout:<EOL><INDENT>if line.strip():<EOL><INDENT>fpointer(indent + "<STR_LIT:U+0020>" + line.replace("<STR_LIT:\t>", "<STR_LIT:U+0020>") + "<STR_LIT:\n>", dedent=False)<EOL><DEDENT>else:<EOL><INDENT>fpointer("<STR_LIT:\n>", dedent=False)<EOL><DEDENT><DEDENT>fpointer("<STR_LIT:\n>", dedent=False)<EOL>

Print STDOUT resulting from a Bash shell command formatted in reStructuredText.

:param command: Bash shell command
:type  command: string

:param nindent: Indentation level
:type  nindent: integer

:param env: Environment variable replacement dictionary. The Bash
            command is pre-processed and any environment variable
            represented in the full notation (:bash:`${...}`) is replaced.
            The dictionary key is the environment variable name and the
            dictionary value is the replacement value. For example, if
            **command** is :code:`'${PYTHON_CMD} -m "x=5"'` and **env**
            is :code:`{'PYTHON_CMD':'python3'}` the actual command issued
            is :code:`'python3 -m "x=5"'`
:type  env: dictionary

:param fpointer: Output function pointer. Normally is :code:`cog.out` but
                 :code:`print` or other functions can be used for
                 debugging
:type  fpointer: function object

:param cols: Number of columns of output
:type  cols: integer


try:<EOL><INDENT>obj = obj.rstrip()<EOL>float(obj[:-<NUM_LIT:1>] if obj[-<NUM_LIT:1>] in _SUFFIX_TUPLE else obj)<EOL>return None<EOL><DEDENT>except (AttributeError, IndexError, ValueError):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`EngineeringNotationNumber` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


try:<EOL><INDENT>assert obj in _SUFFIX_TUPLE<EOL><DEDENT>except AssertionError:<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`EngineeringNotationSuffix` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the *name* of the argument the
     contract is attached to

    :rtype: None


if _check_increasing_real_numpy_vector(obj):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is :ref:`IncreasingRealNumpyVector` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if _check_number_numpy_vector(obj):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is a :ref:`NumberNumpyVector` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if _check_real_numpy_vector(obj):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is a :ref:`RealNumpyVector` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if (not isinstance(obj, dict)) or (<EOL>isinstance(obj, dict)<EOL>and (sorted(obj.keys()) != sorted(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]))<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (isinstance(obj["<STR_LIT>"], int) and (obj["<STR_LIT>"] > <NUM_LIT:0>)):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_increasing_real_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not isinstance(obj["<STR_LIT>"], np.ndarray):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>vdata = ["<STR_LIT:int>", "<STR_LIT:float>", "<STR_LIT>"]<EOL>if not any([obj["<STR_LIT>"].dtype.name.startswith(item) for item in vdata]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if obj["<STR_LIT>"].size != obj["<STR_LIT>"]:<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>nports = int(math.sqrt(obj["<STR_LIT>"].size / obj["<STR_LIT>"].size))<EOL>if obj["<STR_LIT>"] * (nports ** <NUM_LIT:2>) != obj["<STR_LIT>"].size:<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`TouchstoneData` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if isinstance(obj, dict) and (not obj):<EOL><INDENT>return None<EOL><DEDENT>if (not isinstance(obj, dict)) or (<EOL>isinstance(obj, dict)<EOL>and (sorted(obj.keys()) != sorted(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]))<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (isinstance(obj["<STR_LIT>"], int) and (obj["<STR_LIT>"] > <NUM_LIT:0>)):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_increasing_real_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_real_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if _check_number_numpy_vector(obj["<STR_LIT>"]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (<EOL>isinstance(obj["<STR_LIT>"], np.ndarray)<EOL>and (len(obj["<STR_LIT>"].shape) == <NUM_LIT:1>)<EOL>and (obj["<STR_LIT>"].shape[<NUM_LIT:0>] > <NUM_LIT:0>)<EOL>and np.all(obj["<STR_LIT>"] >= <NUM_LIT:0>)<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>sizes = [obj["<STR_LIT>"].size, obj["<STR_LIT>"].size, obj["<STR_LIT>"].size, obj["<STR_LIT>"].size]<EOL>if set(sizes) != set([obj["<STR_LIT>"]]):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>return None<EOL>

r"""
    Validate if an object is an :ref:`TouchstoneNoiseData` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


if (not isinstance(obj, dict)) or (<EOL>isinstance(obj, dict)<EOL>and (sorted(obj.keys()) != sorted(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]))<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>if not (<EOL>(obj["<STR_LIT>"].lower() in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>and (obj["<STR_LIT>"].lower() in ["<STR_LIT:s>", "<STR_LIT:y>", "<STR_LIT:z>", "<STR_LIT:h>", "<STR_LIT:g>"])<EOL>and (obj["<STR_LIT>"].lower() in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>and isinstance(obj["<STR_LIT>"], float)<EOL>and (obj["<STR_LIT>"] >= <NUM_LIT:0>)<EOL>):<EOL><INDENT>raise ValueError(pexdoc.pcontracts.get_exdesc())<EOL><DEDENT>

r"""
    Validate if an object is an :ref:`TouchstoneOptions` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


exdesc = pexdoc.pcontracts.get_exdesc()<EOL>if not isinstance(obj, str):<EOL><INDENT>raise ValueError(exdesc)<EOL><DEDENT>if obj.upper() in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>return None<EOL><DEDENT>raise ValueError(exdesc)<EOL>

r"""
    Validate if an object is a :ref:`WaveInterpOption` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


r"""
    Validate if an object is a :ref:`WaveScaleOption` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


exdesc = pexdoc.pcontracts.get_exdesc()<EOL>if not isinstance(obj, list) or (isinstance(obj, list) and not obj):<EOL><INDENT>raise ValueError(exdesc)<EOL><DEDENT>if any([not (isinstance(item, tuple) and len(item) == <NUM_LIT:2>) for item in obj]):<EOL><INDENT>raise ValueError(exdesc)<EOL><DEDENT>indep_vector, dep_vector = zip(*obj)<EOL>if _check_increasing_real_numpy_vector(np.array(indep_vector)):<EOL><INDENT>raise ValueError(exdesc)<EOL><DEDENT>if _check_real_numpy_vector(np.array(dep_vector)):<EOL><INDENT>raise ValueError(exdesc)<EOL><DEDENT>

r"""
    Validate if an object is a :ref:`WaveVectors` pseudo-type object.

    :param obj: Object
    :type  obj: any

    :raises: RuntimeError (Argument \`*[argument_name]*\` is not valid). The
     token \*[argument_name]\* is replaced by the name of the argument the
     contract is attached to

    :rtype: None


fdict = json_load(os.path.join("<STR_LIT:data>", "<STR_LIT>"))<EOL>sdeps = sorted(fdict.keys())<EOL>olines = []<EOL>for item in sdeps:<EOL><INDENT>olines.append(<EOL>"<STR_LIT>".format(<EOL>name=fdict[item]["<STR_LIT:name>"], url=fdict[item]["<STR_LIT:url>"]<EOL>)<EOL>)<EOL><DEDENT>ret = []<EOL>for line in olines:<EOL><INDENT>wobj = textwrap.wrap(line, width=LINE_WIDTH, subsequent_indent="<STR_LIT:U+0020>")<EOL>ret.append("<STR_LIT:\n>".join([item for item in wobj]))<EOL><DEDENT>mobj.out("<STR_LIT:\n>".join(ret))<EOL>


def make_common_entry(plist, pyver, suffix, req_ver):

prefix = "<STR_LIT>".format(pyver=pyver, suffix=suffix)<EOL>plist.append("<STR_LIT>".format(prefix=prefix, ver=ops_to_words(req_ver)))<EOL>

Generate Python interpreter version entries for 2.x or 3.x series.


def make_multi_entry(plist, pkg_pyvers, ver_dict):

for pyver in pkg_pyvers:<EOL><INDENT>pver = pyver[<NUM_LIT:2>] + "<STR_LIT:.>" + pyver[<NUM_LIT:3>:]<EOL>plist.append("<STR_LIT>".format(pver, ops_to_words(ver_dict[pyver])))<EOL><DEDENT>

Generate Python interpreter version entries.


sdicts = [<EOL>{"<STR_LIT>": "<STR_LIT>"},<EOL>{"<STR_LIT>": "<STR_LIT>"},<EOL>{"<STR_LIT:>>": "<STR_LIT>"},<EOL>{"<STR_LIT>": "<STR_LIT>"},<EOL>{"<STR_LIT:<>": "<STR_LIT>"},<EOL>{"<STR_LIT>": "<STR_LIT>"},<EOL>]<EOL>for sdict in sdicts:<EOL><INDENT>prefix = list(sdict.keys())[<NUM_LIT:0>]<EOL>suffix = sdict[prefix]<EOL>if item.startswith(prefix):<EOL><INDENT>if prefix == "<STR_LIT>":<EOL><INDENT>return item[<NUM_LIT:2>:]<EOL><DEDENT>if prefix == "<STR_LIT>":<EOL><INDENT>return suffix + item[<NUM_LIT:2>:]<EOL><DEDENT>if prefix in ["<STR_LIT:>>", "<STR_LIT:<>"]:<EOL><INDENT>return suffix + item[<NUM_LIT:1>:]<EOL><DEDENT>return item[<NUM_LIT:2>:] + suffix<EOL><DEDENT><DEDENT>raise RuntimeError("<STR_LIT>")<EOL>


unsupp_ops = ["<STR_LIT>", "<STR_LIT>"]<EOL>supp_ops = ["<STR_LIT>", "<STR_LIT:>>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:<>", "<STR_LIT>"]<EOL>tokens = sorted(item.split("<STR_LIT:U+002C>"), reverse=True)<EOL>actual_tokens = []<EOL>for req in tokens:<EOL><INDENT>for op in unsupp_ops:<EOL><INDENT>if req.startswith(op):<EOL><INDENT>raise RuntimeError("<STR_LIT>".format(op))<EOL><DEDENT><DEDENT>for op in supp_ops:<EOL><INDENT>if req.startswith(op):<EOL><INDENT>actual_tokens.append(op)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>".format(op))<EOL><DEDENT><DEDENT>if len(list(set(actual_tokens))) != len(actual_tokens):<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in actual_tokens:<EOL><INDENT>return (<EOL>"<STR_LIT>".join([op_to_words(token) for token in tokens[:-<NUM_LIT:1>]])<EOL>+ "<STR_LIT:U+0020>"<EOL>+ op_to_words(tokens[-<NUM_LIT:1>])<EOL>)<EOL><DEDENT>return "<STR_LIT>".join([op_to_words(token) for token in tokens])<EOL>

Translate requirement specification to words.


pyvers = ["<STR_LIT>".format(item.replace("<STR_LIT:.>", "<STR_LIT>")) for item in get_supported_interps()]<EOL>py2vers = sorted([item for item in pyvers if item.startswith("<STR_LIT>")])<EOL>py3vers = sorted([item for item in pyvers if item.startswith("<STR_LIT>")])<EOL>fdict = json_load(os.path.join("<STR_LIT:data>", "<STR_LIT>"))<EOL>olines = ["<STR_LIT>"]<EOL>sdict = dict([(item["<STR_LIT:name>"], item) for item in fdict.values()])<EOL>for real_name in sorted(sdict.keys()):<EOL><INDENT>pkg_dict = sdict[real_name]<EOL>if pkg_dict["<STR_LIT>"] == ["<STR_LIT>"]:<EOL><INDENT>continue<EOL><DEDENT>plist = [] if not pkg_dict["<STR_LIT>"] else ["<STR_LIT>"]<EOL>if isinstance(pkg_dict["<STR_LIT>"], str):<EOL><INDENT>pkg_dict["<STR_LIT>"] = dict([(pyver, pkg_dict["<STR_LIT>"]) for pyver in pyvers])<EOL><DEDENT>pkg_pyvers = sorted(pkg_dict["<STR_LIT>"].keys())<EOL>pkg_py2vers = sorted(<EOL>[item for item in pkg_dict["<STR_LIT>"].keys() if item.startswith("<STR_LIT>")]<EOL>)<EOL>req_vers = list(set(pkg_dict["<STR_LIT>"].values()))<EOL>req_py2vers = list(<EOL>set([pkg_dict["<STR_LIT>"][item] for item in py2vers if item in pkg_dict["<STR_LIT>"]])<EOL>)<EOL>req_py3vers = list(<EOL>set([pkg_dict["<STR_LIT>"][item] for item in py3vers if item in pkg_dict["<STR_LIT>"]])<EOL>)<EOL>if (len(req_vers) == <NUM_LIT:1>) and (pkg_pyvers == pyvers):<EOL><INDENT>plist.append(ops_to_words(req_vers[<NUM_LIT:0>]))<EOL><DEDENT>elif (<EOL>(pkg_pyvers == pyvers)<EOL>and (len(req_py2vers) == <NUM_LIT:1>)<EOL>and (len(req_py3vers) == <NUM_LIT:1>)<EOL>):<EOL><INDENT>make_common_entry(plist, "<STR_LIT:2>", "<STR_LIT>", req_py2vers[<NUM_LIT:0>])<EOL>make_common_entry(plist, "<STR_LIT:3>", "<STR_LIT>", req_py3vers[<NUM_LIT:0>])<EOL><DEDENT>elif (<EOL>(pkg_pyvers == pyvers)<EOL>and (len(req_py2vers) == len(py2vers))<EOL>and (len(req_py3vers) == <NUM_LIT:1>)<EOL>and (pkg_dict["<STR_LIT>"][pkg_py2vers[-<NUM_LIT:1>]] == req_py3vers[<NUM_LIT:0>])<EOL>):<EOL><INDENT>py2dict = dict(<EOL>[<EOL>(key, value)<EOL>for key, value in pkg_dict["<STR_LIT>"].items()<EOL>if key.startswith("<STR_LIT>") and (key != pkg_py2vers[-<NUM_LIT:1>])<EOL>]<EOL>)<EOL>make_multi_entry(plist, py2vers[:-<NUM_LIT:1>], py2dict)<EOL>pver = pkg_py2vers[-<NUM_LIT:1>][<NUM_LIT:2>] + "<STR_LIT:.>" + pkg_py2vers[-<NUM_LIT:1>][<NUM_LIT:3>:]<EOL>plist.append(<EOL>"<STR_LIT>".format(<EOL>pyver=pver, ver=ops_to_words(req_py3vers[<NUM_LIT:0>])<EOL>)<EOL>)<EOL><DEDENT>elif (<EOL>(pkg_pyvers == pyvers)<EOL>and (len(req_py2vers) == len(py2vers))<EOL>and (len(req_py3vers) == <NUM_LIT:1>)<EOL>):<EOL><INDENT>py2dict = dict(<EOL>[<EOL>(key, value)<EOL>for key, value in pkg_dict["<STR_LIT>"].items()<EOL>if key.startswith("<STR_LIT>")<EOL>]<EOL>)<EOL>make_multi_entry(plist, py2vers, py2dict)<EOL>make_common_entry(plist, "<STR_LIT:3>", "<STR_LIT>", req_py3vers[<NUM_LIT:0>])<EOL><DEDENT>elif (<EOL>(pkg_pyvers == pyvers)<EOL>and (len(req_py3vers) == len(py3vers))<EOL>and (len(req_py2vers) == <NUM_LIT:1>)<EOL>):<EOL><INDENT>py3dict = dict(<EOL>[<EOL>(key, value)<EOL>for key, value in pkg_dict["<STR_LIT>"].items()<EOL>if key.startswith("<STR_LIT>")<EOL>]<EOL>)<EOL>make_common_entry(plist, "<STR_LIT:2>", "<STR_LIT>", req_py2vers[<NUM_LIT:0>])<EOL>make_multi_entry(plist, py3vers, py3dict)<EOL><DEDENT>elif (len(req_vers) == <NUM_LIT:1>) and (pkg_pyvers == py2vers):<EOL><INDENT>make_common_entry(plist, "<STR_LIT:2>", "<STR_LIT>", req_vers[<NUM_LIT:0>])<EOL><DEDENT>elif (len(req_vers) == <NUM_LIT:1>) and (pkg_pyvers == py3vers):<EOL><INDENT>make_common_entry(plist, "<STR_LIT:3>", "<STR_LIT>", req_vers[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>make_multi_entry(plist, pkg_pyvers, pkg_dict["<STR_LIT>"])<EOL><DEDENT>olines.append(<EOL>"<STR_LIT>".format(<EOL>name=pkg_dict["<STR_LIT:name>"], par="<STR_LIT:U+002CU+0020>".join(plist)<EOL>)<EOL>)<EOL><DEDENT>ret = []<EOL>for line in olines:<EOL><INDENT>wobj = textwrap.wrap(line, width=LINE_WIDTH, subsequent_indent="<STR_LIT:U+0020>")<EOL>ret.append("<STR_LIT:\n>".join([item for item in wobj]))<EOL><DEDENT>mobj.out("<STR_LIT>".join(ret) + "<STR_LIT>")<EOL>

Get requirements in reStructuredText format.


mname = "<STR_LIT>"<EOL>fname = "<STR_LIT>"<EOL>module_prefix = "<STR_LIT>".format(mname)<EOL>callable_names = (<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>)<EOL>return docs.support.trace_support.run_trace(<EOL>mname, fname, module_prefix, callable_names, no_print<EOL>)<EOL>


pickle_fname = os.path.join(os.path.dirname(__file__), "<STR_LIT>".format(mname))<EOL>ddir = os.path.dirname(os.path.dirname(__file__))<EOL>moddb_fname = os.path.join(ddir, "<STR_LIT>")<EOL>in_callables_fname = moddb_fname if os.path.exists(moddb_fname) else None<EOL>out_callables_fname = os.path.join(ddir, "<STR_LIT>".format(mname))<EOL>noption = os.environ.get("<STR_LIT>", None)<EOL>exclude = ["<STR_LIT>", "<STR_LIT>"]<EOL>partuple = collections.namedtuple(<EOL>"<STR_LIT>",<EOL>[<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>],<EOL>)<EOL>return partuple(<EOL>pickle_fname, in_callables_fname, out_callables_fname, noption, exclude<EOL>)<EOL>


<EOL>module_exclude = [] if module_exclude is None else module_exclude<EOL>callable_exclude = [] if callable_exclude is None else callable_exclude<EOL>par = trace_pars(mname)<EOL>start_time = datetime.datetime.now()<EOL>with pexdoc.exdoc.ExDocCxt(<EOL>exclude=par.exclude + module_exclude,<EOL>pickle_fname=par.pickle_fname,<EOL>in_callables_fname=par.in_callables_fname,<EOL>out_callables_fname=par.out_callables_fname,<EOL>_no_print=no_print,<EOL>) as exdoc_obj:<EOL><INDENT>fname = os.path.realpath(<EOL>os.path.join(<EOL>os.path.dirname(__file__),<EOL>"<STR_LIT:..>",<EOL>"<STR_LIT:..>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>".format(fname),<EOL>)<EOL>)<EOL>test_cmd = (<EOL>["<STR_LIT>"]<EOL>+ (["<STR_LIT>", "<STR_LIT>"] if debug else ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL>+ ["<STR_LIT>"]<EOL>+ ["<STR_LIT>"]<EOL>+ ([par.noption] if par.noption else [])<EOL>+ ["<STR_LIT>" + mname]<EOL>+ [fname]<EOL>)<EOL>with warnings.catch_warnings():<EOL><INDENT>warnings.filterwarnings("<STR_LIT:ignore>", category=PytestWarning)<EOL>if pytest.main(test_cmd):<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>stop_time = datetime.datetime.now()<EOL>if not no_print:<EOL><INDENT>print(<EOL>"<STR_LIT>".format(<EOL>pmisc.elapsed_time_string(start_time, stop_time)<EOL>)<EOL>)<EOL>for callable_name in callable_names:<EOL><INDENT>callable_name = module_prefix + callable_name<EOL>print("<STR_LIT>".format(callable_name))<EOL>print(exdoc_obj.get_sphinx_doc(callable_name, exclude=callable_exclude))<EOL>print("<STR_LIT:\n>")<EOL><DEDENT><DEDENT>return copy.copy(exdoc_obj)<EOL>


def incfile(fname, fpointer, lrange="<STR_LIT>", sdir=None):

<EOL>file_dir = (<EOL>sdir<EOL>if sdir<EOL>else os.environ.get("<STR_LIT>", os.path.abspath(os.path.dirname(__file__)))<EOL>)<EOL>fname = os.path.join(file_dir, fname)<EOL>with open(fname) as fobj:<EOL><INDENT>lines = fobj.readlines()<EOL><DEDENT>tokens = [item.strip() for item in lrange.split("<STR_LIT:U+002C>")]<EOL>inc_lines = []<EOL>for token in tokens:<EOL><INDENT>if "<STR_LIT:->" in token:<EOL><INDENT>subtokens = token.split("<STR_LIT:->")<EOL>lmin, lmax = (<EOL>int(subtokens[<NUM_LIT:0>]),<EOL>int(subtokens[<NUM_LIT:1>]) if subtokens[<NUM_LIT:1>] else len(lines),<EOL>)<EOL>for num in range(lmin, lmax + <NUM_LIT:1>):<EOL><INDENT>inc_lines.append(num)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>inc_lines.append(int(token))<EOL><DEDENT><DEDENT>fpointer("<STR_LIT>")<EOL>fpointer("<STR_LIT:\n>")<EOL>for num, line in enumerate(lines):<EOL><INDENT>if num + <NUM_LIT:1> in inc_lines:<EOL><INDENT>fpointer("<STR_LIT:U+0020>" + line.replace("<STR_LIT:\t>", "<STR_LIT:U+0020>") if line.strip() else "<STR_LIT:\n>")<EOL><DEDENT><DEDENT>fpointer("<STR_LIT:\n>")<EOL>

r"""
    Include a Python source file in a docstring formatted in reStructuredText.

    :param fname: File name, relative to environment variable
                  :bash:`${TRACER_DIR}`
    :type  fname: string

    :param fpointer: Output function pointer. Normally is :code:`cog.out` but
                     :code:`print` or other functions can be used for
                     debugging
    :type  fpointer: function object

    :param lrange: Line range to include, similar to Sphinx
                   `literalinclude <http://sphinx-doc.org/markup/code.html
                   #directive-literalinclude>`_ directive
    :type  lrange: string

    :param sdir: Source file directory. If None the :bash:`${TRACER_DIR}`
                 environment variable is used if it is defined, otherwise
                 the directory where the :code:`docs.support.incfile` module
                 is located is used
    :type  sdir: string

    For example:

    .. code-block:: python

        def func():
            \"\"\"
            This is a docstring. This file shows how to use it:

            .. =[=cog
            .. import docs.support.incfile
            .. docs.support.incfile.incfile('func_example.py', cog.out)
            .. =]=
            .. code-block:: python

                # func_example.py
                if __name__ == '__main__':
                    func()

            .. =[=end=]=
            \"\"\"
            return 'This is func output'


lines  = string.split( adobe_glyph_list, '<STR_LIT:\n>' )<EOL>glyphs = []<EOL>values = []<EOL>for line in lines:<EOL><INDENT>if line:<EOL><INDENT>fields = string.split( line, '<STR_LIT:;>' )<EOL>

return the list of glyph names and their unicode values


def filter_glyph_names( alist, filter ):

count  = <NUM_LIT:0><EOL>extras = []<EOL>for name in alist:<EOL><INDENT>try:<EOL><INDENT>filtered_index = filter.index( name )<EOL><DEDENT>except:<EOL><INDENT>extras.append( name )<EOL><DEDENT><DEDENT>return extras<EOL>

filter `alist' by taking _out_ all glyph names that are in `filter


def dump_encoding( file, encoding_name, encoding_list ):

write = file.write<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" + encoding_name +<EOL>"<STR_LIT:[>" + repr( len( encoding_list ) ) + "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>line  = "<STR_LIT:U+0020>"<EOL>comma = "<STR_LIT>"<EOL>col   = <NUM_LIT:0><EOL>for value in encoding_list:<EOL><INDENT>line += comma<EOL>line += "<STR_LIT>" % value<EOL>comma = "<STR_LIT:U+002C>"<EOL>col  += <NUM_LIT:1><EOL>if col == <NUM_LIT:16>:<EOL><INDENT>col = <NUM_LIT:0><EOL>comma = "<STR_LIT>"<EOL><DEDENT><DEDENT>write( line + "<STR_LIT>" )<EOL>


def dump_array( the_array, write, array_name ):

write( "<STR_LIT>" + array_name +<EOL>"<STR_LIT:[>" + repr( len( the_array ) ) + "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>line  = "<STR_LIT>"<EOL>comma = "<STR_LIT:U+0020>"<EOL>col   = <NUM_LIT:0><EOL>for value in the_array:<EOL><INDENT>line += comma<EOL>line += "<STR_LIT>" % ord( value )<EOL>comma = "<STR_LIT:U+002C>"<EOL>col  += <NUM_LIT:1><EOL>if col == <NUM_LIT:16>:<EOL><INDENT>col   = <NUM_LIT:0><EOL>comma = "<STR_LIT>"<EOL><DEDENT>if len( line ) > <NUM_LIT>:<EOL><INDENT>write( line )<EOL>line = "<STR_LIT>"<EOL><DEDENT><DEDENT>write( line + "<STR_LIT>" )<EOL>


if len( sys.argv ) != <NUM_LIT:2>:<EOL><INDENT>print(__doc__ % sys.argv[<NUM_LIT:0>])<EOL>sys.exit( <NUM_LIT:1> )<EOL><DEDENT>file  = open( sys.argv[<NUM_LIT:1>], "<STR_LIT>" )<EOL>write = file.write<EOL>count_sid = len( sid_standard_names )<EOL>mac_extras = filter_glyph_names( mac_standard_names, sid_standard_names )<EOL>mac_extras_count = len( mac_extras )<EOL>base_list        = mac_extras + sid_standard_names<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" % os.path.basename( sys.argv[<NUM_LIT:1>] ) )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT:\n>" )<EOL>write( "<STR_LIT:\n>" )<EOL>write( "<STR_LIT>" )<EOL>write( "<STR_LIT:\n>" )<EOL>write( "<STR_LIT:\n>" )<EOL>st = StringTable( base_list, "<STR_LIT>" )<EOL>st.dump( file )<EOL>st.dump_sublist( file, "<STR_LIT>",<EOL>"<STR_LIT>", mac_standard_names )<EOL>st.dump_sublist( file, "<STR_LIT>",<EOL>"<STR_LIT>", sid_standard_names )<EOL>dump_encoding( file, "<STR_LIT>", t1_standard_encoding )<EOL>dump_encoding( file, "<STR_LIT>", t1_expert_encoding )<EOL>agl_glyphs, agl_values = adobe_glyph_values()<EOL>dict = StringNode( "<STR_LIT>", <NUM_LIT:0> )<EOL>for g in range( len( agl_glyphs ) ):<EOL><INDENT>dict.add( agl_glyphs[g], eval( "<STR_LIT>" + agl_values[g] ) )<EOL><DEDENT>dict       = dict.optimize()<EOL>dict_len   = dict.locate( <NUM_LIT:0> )<EOL>dict_array = dict.store( "<STR_LIT>" )<EOL>write( """<STR_LIT>"""<EOL>This function searches the compressed table efficiently.<EOL>/<EOL>atic unsigned long<EOL>_get_adobe_glyph_index( const char*  name,<EOL>const char*  limit )<EOL>int                   c = <NUM_LIT:0>;<EOL>int                   count, min, max;<EOL>const unsigned char*  p = ft_adobe_glyph_list;<EOL>if ( name == <NUM_LIT:0> || name >= limit )<EOL>goto NotFound;<EOL>c     = *name++;<EOL>count = p[<NUM_LIT:1>];<EOL>p    += <NUM_LIT:2>;<EOL>min = <NUM_LIT:0>;<EOL>max = count;<EOL>while ( min < max )<EOL>{<EOL>int                   mid = ( min + max ) >> <NUM_LIT:1>;<EOL>const unsigned char*  q   = p + mid * <NUM_LIT:2>;<EOL>int                   c2;<EOL>q = ft_adobe_glyph_list + ( ( (int)q[<NUM_LIT:0>] << <NUM_LIT:8> ) | q[<NUM_LIT:1>] );<EOL>c2 = q[<NUM_LIT:0>] & <NUM_LIT>;<EOL>if ( c2 == c )<EOL>{<EOL>p = q;<EOL>goto Found;<EOL>}<EOL>if ( c2 < c )<EOL>min = mid + <NUM_LIT:1>;<EOL>else<EOL>max = mid;<EOL>}<EOL>goto NotFound;<EOL>und:<EOL>for (;;)<EOL>{<EOL>/* assert (*p & <NUM_LIT>) == c */<EOL>if ( name >= limit )<EOL>{<EOL>if ( (p[<NUM_LIT:0>] & <NUM_LIT>) == <NUM_LIT:0> &&<EOL>(p[<NUM_LIT:1>] & <NUM_LIT>) != <NUM_LIT:0> )<EOL>return (unsigned long)( ( (int)p[<NUM_LIT:2>] << <NUM_LIT:8> ) | p[<NUM_LIT:3>] );<EOL>goto NotFound;<EOL>}<EOL>c = *name++;<EOL>if ( p[<NUM_LIT:0>] & <NUM_LIT> )<EOL>{<EOL>p++;<EOL>if ( c != (p[<NUM_LIT:0>] & <NUM_LIT>) )<EOL>goto NotFound;<EOL>continue;<EOL>}<EOL>p++;<EOL>count = p[<NUM_LIT:0>] & <NUM_LIT>;<EOL>if ( p[<NUM_LIT:0>] & <NUM_LIT> )<EOL>p += <NUM_LIT:2>;<EOL>p++;<EOL>for ( ; count > <NUM_LIT:0>; count--, p += <NUM_LIT:2> )<EOL>{<EOL>int                   offset = ( (int)p[<NUM_LIT:0>] << <NUM_LIT:8> ) | p[<NUM_LIT:1>];<EOL>const unsigned char*  q      = ft_adobe_glyph_list + offset;<EOL>if ( c == ( q[<NUM_LIT:0>] & <NUM_LIT> ) )<EOL>{<EOL>p = q;<EOL>goto NextIter;<EOL>}<EOL>}<EOL>goto NotFound;<EOL>NextIter:<EOL>;<EOL>}<EOL>tFound:<EOL>return <NUM_LIT:0>;<EOL>if /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */<EOL>)<EOL>if <NUM_LIT:0>:  <EOL><INDENT>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>for name in agl_glyphs:<EOL><INDENT>write( '<STR_LIT>' + name + '<STR_LIT>' )<EOL><DEDENT>write( "<STR_LIT>" )<EOL>write( "<STR_LIT>" )<EOL>for val in agl_values:<EOL><INDENT>write( '<STR_LIT>' + val + '<STR_LIT>' )<EOL><DEDENT>write( "<STR_LIT>" )<EOL>write(


global output_dir<EOL>try:<EOL><INDENT>opts, args = getopt.getopt( sys.argv[<NUM_LIT:1>:],"<STR_LIT>",["<STR_LIT>", "<STR_LIT>"] )<EOL><DEDENT>except getopt.GetoptError:<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:2> )<EOL><DEDENT>if args == []:<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:1> )<EOL><DEDENT>output_dir = None<EOL>do_backup  = None<EOL>for opt in opts:<EOL><INDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:0> )<EOL><DEDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>do_backup = <NUM_LIT:1><EOL><DEDENT><DEDENT>source_processor = SourceProcessor()<EOL>file_list = make_file_list( args )<EOL>for filename in file_list:<EOL><INDENT>source_processor.parse_file( filename )<EOL>for block in source_processor.blocks:<EOL><INDENT>beautify_block( block )<EOL><DEDENT>new_name = filename + "<STR_LIT>"<EOL>ok       = None<EOL>try:<EOL><INDENT>file = open( new_name, "<STR_LIT>" )<EOL>for block in source_processor.blocks:<EOL><INDENT>for line in block.lines:<EOL><INDENT>file.write( line )<EOL>file.write( "<STR_LIT:\n>" )<EOL><DEDENT><DEDENT>file.close()<EOL><DEDENT>except:<EOL><INDENT>ok = <NUM_LIT:0><EOL><DEDENT><DEDENT>


self.reset()<EOL>self.sections = {}    <EOL>self.section  = None  <EOL>self.chapters = []    <EOL>self.headers  = {}<EOL>


if section_name not in self.sections:<EOL><INDENT>section = DocSection( section_name )<EOL>self.sections[section_name] = section<EOL>self.section                = section<EOL><DEDENT>else:<EOL><INDENT>self.section = self.sections[section_name]<EOL><DEDENT>


self.markups      = []<EOL>self.markup       = None<EOL>self.markup_lines = []<EOL>

reset the content processor for a new block


if self.markup and self.markup_lines:<EOL><INDENT>marks = self.markup_lines<EOL>if len( marks ) > <NUM_LIT:0> and not string.strip( marks[-<NUM_LIT:1>] ):<EOL><INDENT>self.markup_lines = marks[:-<NUM_LIT:1>]<EOL><DEDENT>m = DocMarkup( self.markup, self.markup_lines )<EOL>self.markups.append( m )<EOL>self.markup       = None<EOL>self.markup_lines = []<EOL><DEDENT>


markup       = None<EOL>markup_lines = []<EOL>first        = <NUM_LIT:1><EOL>for line in content:<EOL><INDENT>found = None<EOL>for t in re_markup_tags:<EOL><INDENT>m = t.match( line )<EOL>if m:<EOL><INDENT>found  = string.lower( m.group( <NUM_LIT:1> ) )<EOL>prefix = len( m.group( <NUM_LIT:0> ) )<EOL>line   = "<STR_LIT:U+0020>" * prefix + line[prefix:]   <EOL>break<EOL><DEDENT><DEDENT>if found:<EOL><INDENT>first = <NUM_LIT:0><EOL>self.add_markup()  <EOL>self.markup = found<EOL>if len( string.strip( line ) ) > <NUM_LIT:0>:<EOL><INDENT>self.markup_lines.append( line )<EOL><DEDENT><DEDENT>elif first == <NUM_LIT:0>:<EOL><INDENT>self.markup_lines.append( line )<EOL><DEDENT><DEDENT>self.add_markup()<EOL>return self.markups<EOL>

process a block content and return a list of DocMarkup objects
           corresponding to it


for m in self.markups:<EOL><INDENT>if m.tag == string.lower( tag_name ):<EOL><INDENT>return m<EOL><DEDENT><DEDENT>return None<EOL>

return the DocMarkup corresponding to a given tag in a block


try:<EOL><INDENT>m = self.get_markup( tag_name )<EOL>return m.get_name()<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>

return the name of a given primary markup in a block


line = "<STR_LIT>"<EOL>if words:<EOL><INDENT>line = html_quote( words[<NUM_LIT:0>] )<EOL>for w in words[<NUM_LIT:1>:]:<EOL><INDENT>line = line + "<STR_LIT:U+0020>" + html_quote( w )<EOL><DEDENT><DEDENT>return line<EOL>

convert a series of simple words into some HTML text


<EOL>m = re_crossref.match( word )<EOL>if m:<EOL><INDENT>try:<EOL><INDENT>name = m.group( <NUM_LIT:1> )<EOL>rest = m.group( <NUM_LIT:2> )<EOL>block = self.identifiers[name]<EOL>url   = self.make_block_url( block )<EOL>return '<STR_LIT>' + url + '<STR_LIT>' + name + '<STR_LIT>' + rest<EOL><DEDENT>except:<EOL><INDENT>sys.stderr.write("<STR_LIT>" + name + "<STR_LIT>" )<EOL>return '<STR_LIT:?>' + name + '<STR_LIT:?>' + rest<EOL><DEDENT><DEDENT>m = re_italic.match( word )<EOL>if m:<EOL><INDENT>name = m.group( <NUM_LIT:1> )<EOL>rest = m.group( <NUM_LIT:3> )<EOL>return '<STR_LIT>' + name + '<STR_LIT>' + rest<EOL><DEDENT>m = re_bold.match( word )<EOL>if m:<EOL><INDENT>name = m.group( <NUM_LIT:1> )<EOL>rest = m.group( <NUM_LIT:3> )<EOL>return '<STR_LIT>' + name + '<STR_LIT>' + rest<EOL><DEDENT>return html_quote( word )<EOL>

analyze a simple word to detect cross-references and styling


line = "<STR_LIT>"<EOL>if words:<EOL><INDENT>line = self.make_html_word( words[<NUM_LIT:0>] )<EOL>for word in words[<NUM_LIT:1>:]:<EOL><INDENT>line = line + "<STR_LIT:U+0020>" + self.make_html_word( word )<EOL><DEDENT>line = re.sub( r"<STR_LIT>",r'<STR_LIT>',line )<EOL>line = string.replace( line, "<STR_LIT>", "<STR_LIT>" )<EOL><DEDENT>return para_header + line + para_footer<EOL>

convert words of a paragraph into tagged HTML text, handle xrefs


line = code_header + '<STR_LIT:\n>'<EOL>for l in lines:<EOL><INDENT>line = line + html_quote( l ) + '<STR_LIT:\n>'<EOL><DEDENT>return line + code_footer<EOL>


lines = []<EOL>for item in items:<EOL><INDENT>if item.lines:<EOL><INDENT>lines.append( self.make_html_code( item.lines ) )<EOL><DEDENT>else:<EOL><INDENT>lines.append( self.make_html_para( item.words ) )<EOL><DEDENT><DEDENT>return string.join( lines, '<STR_LIT:\n>' )<EOL>

convert a field's content into some valid HTML


def  __init__( self, id, start, column, end ):

self.id     = id<EOL>self.start  = re.compile( start, re.VERBOSE )<EOL>self.column = re.compile( column, re.VERBOSE )<EOL>self.end    = re.compile( end, re.VERBOSE )<EOL>

create a block pattern, used to recognize special documentation blocks


self.blocks   = []<EOL>self.filename = None<EOL>self.format   = None<EOL>self.lines    = []<EOL>


self.blocks = []<EOL>self.format = None<EOL>

reset a block processor, clean all its blocks


self.reset()<EOL>self.filename = filename<EOL>fileinput.close()<EOL>self.format = None<EOL>self.lineno = <NUM_LIT:0><EOL>self.lines  = []<EOL>for line in fileinput.input( filename ):<EOL><INDENT>if line[-<NUM_LIT:1>] == '<STR_LIT>':<EOL><INDENT>line = line[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL><DEDENT>if self.format == None:<EOL><INDENT>self.process_normal_line( line )<EOL><DEDENT>else:<EOL><INDENT>if self.format.end.match( line ):<EOL><INDENT>self.lines.append( line )<EOL>self.add_block_lines()<EOL><DEDENT>elif self.format.column.match( line ):<EOL><INDENT>self.lines.append( line )<EOL><DEDENT>else:<EOL><INDENT>self.add_block_lines()<EOL>self.process_normal_line( line )<EOL><DEDENT><DEDENT><DEDENT>self.add_block_lines()<EOL>

parse a C source file, and add its blocks to the processor's list


for f in re_source_block_formats:<EOL><INDENT>if f.start.match( line ):<EOL><INDENT>self.add_block_lines()<EOL>self.format = f<EOL>self.lineno = fileinput.filelineno()<EOL><DEDENT><DEDENT>self.lines.append( line )<EOL>

process a normal line and check whether it is the start of a new block


if self.lines != []:<EOL><INDENT>block = SourceBlock( self, self.filename, self.lineno, self.lines )<EOL>self.blocks.append( block )<EOL>self.format = None<EOL>self.lines  = []<EOL><DEDENT>

add the current accumulated lines and create a new block


for b in self.blocks:<EOL><INDENT>b.dump()<EOL><DEDENT>


result = <NUM_LIT:1><EOL>try:<EOL><INDENT>file = open( pathname, "<STR_LIT:r>" )<EOL>file.close()<EOL><DEDENT>except:<EOL><INDENT>result = None<EOL>sys.stderr.write( pathname + "<STR_LIT>" )<EOL><DEDENT>return result<EOL>


file_list = []<EOL>if not args:<EOL><INDENT>args = sys.argv[<NUM_LIT:1> :]<EOL><DEDENT>for pathname in args:<EOL><INDENT>if string.find( pathname, '<STR_LIT:*>' ) >= <NUM_LIT:0>:<EOL><INDENT>newpath = glob.glob( pathname )<EOL>newpath.sort()  <EOL><DEDENT>else:<EOL><INDENT>newpath = [pathname]<EOL><DEDENT>file_list.extend( newpath )<EOL><DEDENT>if len( file_list ) == <NUM_LIT:0>:<EOL><INDENT>file_list = None<EOL><DEDENT>else:<EOL><INDENT>file_list = filter( file_exists, file_list )<EOL><DEDENT>return file_list<EOL>

builds a list of input files from command-line arguments


global output_dir<EOL>try:<EOL><INDENT>opts, args = getopt.getopt( sys.argv[<NUM_LIT:1>:],"<STR_LIT>",["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"] )<EOL><DEDENT>except getopt.GetoptError:<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:2> )<EOL><DEDENT>if args == []:<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:1> )<EOL><DEDENT>project_title  = "<STR_LIT>"<EOL>project_prefix = None<EOL>output_dir     = None<EOL>for opt in opts:<EOL><INDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>usage()<EOL>sys.exit( <NUM_LIT:0> )<EOL><DEDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>project_title = opt[<NUM_LIT:1>]<EOL><DEDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>utils.output_dir = opt[<NUM_LIT:1>]<EOL><DEDENT>if opt[<NUM_LIT:0>] in ( "<STR_LIT>", "<STR_LIT>" ):<EOL><INDENT>project_prefix = opt[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>check_output()<EOL>source_processor  = SourceProcessor()<EOL>content_processor = ContentProcessor()<EOL>file_list = make_file_list( args )<EOL>for filename in file_list:<EOL><INDENT>source_processor.parse_file( filename )<EOL>content_processor.parse_sources( source_processor )<EOL><DEDENT>content_processor.finish()<EOL>formatter = HtmlFormatter( content_processor, project_title, project_prefix )<EOL>formatter.toc_dump()<EOL>formatter.index_dump()<EOL>formatter.section_dump_all()<EOL>


return self._controller_index<EOL>

The index of the controller, between 0 and 4 (read-only).  Typically this is assigned in the order the
        controllers are detected, however some controllers may have an intrinsic "player number" that is exposed
        through this number.  No two controllers will have the same controller index.


return (axis & self._supported_axes_mask) != <NUM_LIT:0><EOL>

Returns ``True`` if the controller has the requested axis, a value of enumeration :class:`ControllerAxes`.


try:<EOL><INDENT>return self._axes[axis]<EOL><DEDENT>except KeyError:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>

Get the absolute value of the requested axis.

        :param axis: An axis, one of the values in :class:`ControllerAxes`.
        :return: The absolute position of the axis, between -1.0 and 0.0.


return (button & self._supported_buttons_mask) != <NUM_LIT:0><EOL>

Returns ``True`` if the controller has the requested button, a value of enumeration :class:`ControllerButtons`.


return (button & self._buttons) != <NUM_LIT:0><EOL>

Get the pressed state of the requested button.

        :param button: A button, one of the values in :class:`ControllerButtons`.
        :return: ``True``` if the button is currently pressed, otherwise ``False``.


return self._controller_index is not None<EOL>

``True`` if the controller is still connected; ``False`` if it has been disconnected.

        Once a controller has been disconnected, it is never reconnected (if the same physical device is reconnected, a new
        ``Controller`` instance is created).


return self.get_axis(ControllerAxes.left_thumb_x)<EOL>

The absolute X axis value of the left thumb-stick, or the main stick on a joystick.


return self.get_axis(ControllerAxes.left_thumb_y)<EOL>

The absolute Y axis value of the left thumb-stick, or the main stick on a joystick.


return self.get_axis(ControllerAxes.right_thumb_x)<EOL>

The absolute X axis value of the right thumb-stick, or the twist axis on a joystick.


return self.get_axis(ControllerAxes.right_thumb_y)<EOL>

The absolute Y axis value of the right thumb-stick, or the throttle control on a joystick.


return self.get_axis(ControllerAxes.left_trigger)<EOL>

The absolute left trigger value, between 0.0 and 1.0.  Available only on game controllers with the
        ``extended`` profile.


return self.get_axis(ControllerAxes.right_trigger)<EOL>

The absolute right trigger value, between 0.0 and 1.0.  Available only on game controllers with the
        ``extended`` profile.


return self._buttons & ControllerButtons.start<EOL>

``True`` if the start button is pressed.  Available only on game controllers with the ``standard`` or
        ``extended`` profiles.


return self._buttons & ControllerButtons.back<EOL>

``True`` if the back button is pressed.  Available only on the Xbox 360 controller on Windows.


return self._buttons & ControllerButtons.select<EOL>

``True`` if the select button is pressed.


return self._buttons & ControllerButtons.action_up<EOL>

``True`` if the up action button ("Y" on Xbox 360) is pressed.  Available only on game controllers with
        the ``standard`` or ``extended`` profiles.


return self._buttons & ControllerButtons.action_down<EOL>

``True`` if the down action button ("A" on Xbox 360) is pressed.  Available only on game controllers with
        the ``standard`` or ``extended`` profiles.


return self._buttons & ControllerButtons.action_left<EOL>

``True`` if the left action button ("X" on Xbox 360) is pressed.  Available only on game controllers with
        the ``standard`` or ``extended`` profiles.


return self._buttons & ControllerButtons.action_right<EOL>

``True`` if the right action button ("B" on Xbox 360) is pressed.  Available only on game controllers with
        the ``standard`` or ``extended`` profiles.


return self._buttons & ControllerButtons.dpad_up<EOL>

``True`` if the up directional pad button is pressed.  The d-pad also corresponds to the POV or hat control
        on a joystick.


return self._buttons & ControllerButtons.dpad_down<EOL>

``True`` if the down directional pad button is pressed.  The d-pad also corresponds to the POV or hat control
        on a joystick.


return self._buttons & ControllerButtons.dpad_left<EOL>

``True`` if the left directional pad button is pressed.  The d-pad also corresponds to the POV or hat control
        on a joystick.


return self._buttons & ControllerButtons.dpad_right<EOL>

``True`` if the right directional pad button is pressed.  The d-pad also corresponds to the POV or hat control
        on a joystick.


return self._buttons & ControllerButtons.left_shoulder<EOL>

``True`` if the left shoulder button is pressed.  Available only on game controllers with the ``standard`` or
        ``extended`` profiles.


return self._buttons & ControllerButtons.right_shoulder<EOL>

``True`` if the right shoulder button is pressed.  Available only on game controllers with the ``standard`` or
        ``extended`` profiles.


return self._buttons & ControllerButtons.left_thumb<EOL>

``True`` if the left thumb stick is depressed.  Available only on game controllers with the
        ``extended`` profile.


return self._buttons & ControllerButtons.right_thumb<EOL>

``True`` if the right thumb stick is depressed.  Available only on game controllers with the
        ``extended`` profile.


@classmethod<EOL><INDENT>def register(cls, vendor_id, product_id, mapping):<DEDENT>

cls._registry[(vendor_id, product_id)] = mapping<EOL>

Register a mapping for controllers with the given vendor and product IDs.  The mapping will
        replace any existing mapping for these IDs for controllers not yet connected.

        :param vendor_id: the vendor ID of the controller, as reported by :attr:`Controller.vendor_id`
        :param product_id: the vendor ID of the controller, as reported by :attr:`Controller.product_id`
        :param mapping: a :class:`ControllerMapping` to apply


try:<EOL><INDENT>return cls._registry[(controller.vendor_id, controller.product_id)]<EOL><DEDENT>except KeyError:<EOL><INDENT>return None<EOL><DEDENT>

Find a mapping that can apply to the given controller.  Returns None if unsuccessful.

        :param controller: :class:`Controller` to look up
        :return: :class:`ControllerMapping`


if self._handle != -<NUM_LIT:1>:<EOL><INDENT>lib.UnloadImage(self._handle)<EOL><DEDENT>self._handle = -<NUM_LIT:1><EOL>

Releases renderer resources associated with this image.


return self._width<EOL>

The width of the image, in texels (read-only).


return self._height<EOL>

The height of the image, in texels (read-only).


return self._content_scale<EOL>

The content scale applied to the image (read-only).


handle = c_int()<EOL>lib.GetImageRegion(byref(handle), self._handle, x1, y1, x2, y2)<EOL>return Image(width = x2 - x1, height = y2 - y1, content_scale = self._content_scale, handle = handle)<EOL>

Get an image that refers to the given rectangle within this image.  The image data is not actually
        copied; if the image region is rendered into, it will affect this image.

        :param int x1: left edge of the image region to return
        :param int y1: top edge of the image region to return
        :param int x2: right edge of the image region to return
        :param int y2: bottom edge of the image region to return
        :return: :class:`Image`


lib.SetTransform((c_float * <NUM_LIT:16>)(*matrix))<EOL>

Replace the current graphics transform with the given 4x4 matrix.  For example, to replace
    the transform with a translation by ``(x, y)``::

        bacon.set_transform([1, 0, 0, x,
                             0, 1, 0, y,
                             0, 0, 1, 0,
                             0, 0, 0, 1])

    :param matrix: a 4x4 matrix in column major order, represented as a flat 16 element sequence.


_target_stack.append(target)<EOL>_set_target(target)<EOL>

Begin rendering to the given image or window.  All subsequent drawing will be to the given target.
    Use :func:`pop_target` to resume rendering to the previous target.

    The target stack is automatically cleared and returned to the window at the beginning of each frame.

    :param image: the :class:`Image` or :class:`Window` to render to


_target_stack.pop()<EOL>_set_target(_target_stack[-<NUM_LIT:1>])<EOL>

Remove the current target from the stack and resume rendering on the one that was active
    before :func:`push_target` was called.


return _target_stack[-<NUM_LIT:1>] or bacon.window<EOL>

Get the current target being rendered to.

    :return: :class:`Image` or :class:`Window`


lib.SetShader(shader._handle if shader else <NUM_LIT:0>)<EOL>

Set the current graphics shader.  All subsequent drawing commands will be rendered with this shader.
    To reset to the default shader, pass ``None`` as the argument.

    The shader is automatically reset to the default shader at the beginning of each frame.

    :param shader: a :class:`Shader` to render with


def draw_image(image, x1, y1, x2 = None, y2 = None):

if x2 is None:<EOL><INDENT>x2 = x1 + image.width<EOL><DEDENT>if y2 is None:<EOL><INDENT>y2 = y1 + image.height<EOL><DEDENT>lib.DrawImage(image._handle, x1, y1, x2, y2)<EOL>

Draw an image.

    The image's top-left corner is drawn at ``(x1, y1)``, and its lower-left at ``(x2, y2)``.  If ``x2`` and ``y2`` are omitted, they
    are calculated to render the image at its native resoultion.

    Note that images can be flipped and scaled by providing alternative values for ``x2`` and ``y2``.

    :param image: an :class:`Image` to draw


def draw_image_region(image, x1, y1, x2, y2,<EOL>ix1, iy1, ix2, iy2):

lib.DrawImageRegion(image._handle, x1, y1, x2, y2, ix1, iy1, ix2, iy2)<EOL>

Draw a rectangular region of an image.

    The part of the image contained by the rectangle in texel-space by the coordinates ``(ix1, iy1)`` to ``(ix2, iy2)`` is
    drawn at coordinates ``(x1, y1)`` to ``(x2, y2)``.  All coordinates have the origin ``(0, 0)`` at the upper-left corner.

    For example, to draw the left half of a ``100x100`` image at coordinates ``(x, y)``::

        bacon.draw_image_region(image, x, y, x + 50, y + 100,
                                0, 0, 50, 100)

    :param image: an :class:`Image` to draw


path = os.path.join(resource_dir, filename)<EOL>if _dll_dir and not os.path.exists(path):<EOL><INDENT>path = os.path.join(_dll_dir, filename)<EOL><DEDENT>return path<EOL>

Get a path to the given filename to load as a resource.  All non-absolute filenames passed to
    :class:`Image`, :class:`Font`, :class:`Sound`, etc are transformed through this function.

    :param str filename: a relative path to a resource file
    :return str: an absolute path to the file


return self.button_mask & (<NUM_LIT:1> << <NUM_LIT:0>)<EOL>

``True`` if the left mouse button is currently pressed.


return self.button_mask & (<NUM_LIT:1> << <NUM_LIT:1>)<EOL>

``True`` if the middle mouse button is currently pressed.


return self.button_mask & (<NUM_LIT:1> << <NUM_LIT:2>)<EOL>

``True`` if the right mouse button is currently pressed.


if self._handle != -<NUM_LIT:1>:<EOL><INDENT>lib.UnloadSound(self._handle)<EOL>self._handle = -<NUM_LIT:1><EOL><DEDENT>

Release all resources associated with the sound.


def play(self, gain=None, pan=None, pitch=None):

if gain is None and pan is None and pitch is None:<EOL><INDENT>lib.PlaySound(self._handle)<EOL><DEDENT>else:<EOL><INDENT>voice = Voice(self)<EOL>if gain is not None:<EOL><INDENT>voice.gain = gain<EOL><DEDENT>if pan is not None:<EOL><INDENT>voice.pan = pan<EOL><DEDENT>if pitch is not None:<EOL><INDENT>voice.pitch = pitch<EOL><DEDENT>voice.play()<EOL><DEDENT>

Play the sound as a `one-shot`.

        The sound will be played to completion.  If the sound is played more than once at a time, it will mix
        with all previous instances of itself.  If you need more control over the playback of sounds, see
        :class:`Voice`.

        :param gain: optional volume level to play the sound back at, between 0.0 and 1.0 (defaults to 1.0)
        :param pan: optional stereo pan, between -1.0 (left) and 1.0 (right)
        :param pitch: optional sampling rate modification, between 0.4 and 16.0, where 1.0 represents the original pitch


lib.DestroyVoice(self._handle)<EOL>self._handle = -<NUM_LIT:1><EOL>

Destroy a voice.  Required if a sound is stopped before completing to free associated resources.


def set_loop_points(self, start_sample=-<NUM_LIT:1>, end_sample=<NUM_LIT:0>):

lib.SetVoiceLoopPoints(self._handle, start_sample, end_sample)<EOL>

Set the loop points within the sound.

        The sound must have been created with ``loop=True``.  The default parameters cause the loop points to be set to
        the entire sound duration.

        :note: There is currently no API for converting sample numbers to times.
        :param start_sample: sample number to loop back to
        :param end_sample: sample number to loop at


Start running the game.  The window is created and shown at this point, and then
    the main event loop is entered.  'game.on_tick' and other event handlers are called
    repeatedly until the game exits.

    If a game is already running, this function replaces the :class:`Game` instance that
    receives events.


lib.Stop()<EOL>

Stop the game loop and exit the application before the next :func:`on_tick` is called.


pass<EOL>

Called once when the game starts.  You can use this to do any initialization that
        requires the graphics device to have been initialized; for example, rendering to a texture.


clear(<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:1>)<EOL>

Called once per frame to update and render the game.  You may only call
        drawing functions within the scope of this method.


pass<EOL>

Called when a key on the keyboard is pressed or released.

        :param key: key code, one of :class:`Keys` enumeration
        :param pressed: ``True`` if the key was pressed, otherwise ``False``


def on_mouse_button(self, button, pressed):

pass<EOL>

Called when a mouse button is pressed or released.

        :param button: button index, of :class:`MouseButton` enumeration
        :param pressed: ``True`` if the button was pressed, otherwise ``False``


pass<EOL>

Called when the mouse scroll wheel is scrolled.  Most mice have a scroll wheel that moves in
        the ``y`` axis only; Apple trackpads and mice support scrolling in ``x`` as well.

        :note: units are aribitrary and not currently consistent across platforms

        :param dx: relative scroll amount along the ``x`` axis
        :param dy: relative scroll amount along the ``y`` axis


pass<EOL>

Called when size of the window changes.

        :param width: width of the drawable area of the window, in pixels
        :param height: height of the drawable area of the window, in pixels


pass<EOL>

Called when a game controller is connected.

        :param controller: the :class:`Controller` that is now available for polling and events


pass<EOL>

Called when a game controller is disconnected.  You should use the `controller` parameter only
        to identify a previously used controller; its properties and values will no longer be available.

        :param controller: the :class:`Controller` that was disconnected


def on_controller_button(self, controller, button, pressed):

pass<EOL>

Called when a button on a game controller is pressed or released.

        :param controller: the :class:`Controller` containing the button
        :param button: button index, of :class:`ControllerButtons` enumeration
        :param pressed: ``True`` if the button was pressed, otherwise ``False``


def on_controller_axis(self, controller, axis, value):

pass<EOL>

Called when an axis on a game controller is moved.

        :param controller: the :class:`Controller` containing the axis
        :param button: axis index, of :class:`ControllerAxes` enumeration
        :param value: absolute position of the axis, between ``-1.0`` and ``1.0``


def draw_string(font, text, x, y, width=None, height=None, align=Alignment.left, vertical_align=VerticalAlignment.baseline):

style = Style(font)<EOL>run = GlyphRun(style, text)<EOL>glyph_layout = GlyphLayout([run], x, y, width, height, align, vertical_align)<EOL>draw_glyph_layout(glyph_layout)<EOL>

Draw a string with the given font.

    :note: Text alignment and word-wrapping is not yet implemented.  The text is rendered with the left edge and
        baseline at ``(x, y)``.

    :param font: the :class:`Font` to render text with
    :param text: a string of text to render.


pushed_color = False<EOL>for line in glyph_layout.lines:<EOL><INDENT>x = line.x<EOL>y = line.y<EOL>for run in line.runs:<EOL><INDENT>style = run.style<EOL>if style.color is not None:<EOL><INDENT>if not pushed_color:<EOL><INDENT>bacon.push_color()<EOL>pushed_color = True<EOL><DEDENT>bacon.set_color(*style.color)<EOL><DEDENT>elif pushed_color:<EOL><INDENT>bacon.pop_color()<EOL>pushed_color = False<EOL><DEDENT>for glyph in run.glyphs:<EOL><INDENT>if glyph.image:<EOL><INDENT>bacon.draw_image(glyph.image, x + glyph.offset_x, y - glyph.offset_y)<EOL><DEDENT>x += glyph.advance<EOL><DEDENT><DEDENT><DEDENT>if pushed_color:<EOL><INDENT>bacon.pop_color()<EOL><DEDENT>


return self._uniforms<EOL>

Map of shader uniforms available on this shader.

        :type: read-only dictionary of string to :class:`ShaderUniform`


return self._vertex_source<EOL>

Get the vertex shader source

        :type: ``str``


return self._fragment_source<EOL>

Get the fragment shader source

        :type: ``str``


return self._name.startswith('<STR_LIT>')<EOL>

Boolean indicating if this shader uniform's value is shared between all shaders

        :type: ``bool``


return self._name<EOL>

Name of the uniform, as it appears in the shader.

        :type: ``str``


return self._type<EOL>

Type of the uniform, or, if the uniform is an array, the element type of the array.

        :type: an enumeration of :class:`ShaderUniformType`


return self._array_count<EOL>

The size of the array, or 1 if this uniform is not an array.

        :type: ``int``


return self._descent<EOL>

Descent of the font below the baseline, in pixels; typically positive


return self._ascent<EOL>

Ascent of the font above the baseline, in pixels; typically negative


return self._char<EOL>

The character (a string) this glyph will render


return self._image<EOL>


return self._offset_x<EOL>

Offset in pixels to draw the image relative to the baseline origin


return self._offset_y<EOL>


return self._advance<EOL>


return self._metrics<EOL>

Retrieves the pixel-space design metrics of the font.

        :return: :class:`FontMetrics`


return self._metrics.ascent<EOL>

The ascent of the font above the baseline, in pixels; typically negative.


return self._metrics.descent<EOL>

The descent of the font below the baseline, in pixels; typically positive.


try:<EOL><INDENT>return self._glyphs[char]<EOL><DEDENT>except KeyError:<EOL><INDENT>glyph = self._font_file.get_glyph(self._size, self._content_scale, char, self._flags)<EOL>self._glyphs[char] = glyph<EOL>return glyph<EOL><DEDENT>

Retrieves a :class:`Glyph` that renders the given character.

        :param char: the character (a string)


return [self.get_glyph(c) for c in str]<EOL>

Retrieves a list of :class:`Glyph` for the given string.

        :param str: the string to render


style = bacon.text.Style(self)<EOL>run = bacon.text.GlyphRun(style, str)<EOL>glyph_layout = bacon.text.GlyphLayout([run], <NUM_LIT:0>, <NUM_LIT:0>)<EOL>return glyph_layout.content_width<EOL>

Calculates the width of the given string in this font.

        :param str: the string to measure
        :return float: width of the string, in pixels


def arc_distance(theta_1, phi_1, theta_2, phi_2):

temp = (np.sin((theta_2-theta_1)/<NUM_LIT:2>)**<NUM_LIT:2><EOL>+ np.cos(theta_1)*np.cos(theta_2) * np.sin((phi_2-phi_1)/<NUM_LIT:2>)**<NUM_LIT:2>)<EOL>distance_matrix = <NUM_LIT:2> * np.arctan2(np.sqrt(temp), np.sqrt(<NUM_LIT:1>-temp))<EOL>return distance_matrix<EOL>

Calculates the pairwise arc distance
between all points in vector a and b.


def export_hdf5_v1(dataset, path, column_names=None, byteorder="<STR_LIT:=>", shuffle=False, selection=False, progress=None, virtual=True):

if selection:<EOL><INDENT>if selection == True:  <EOL><INDENT>selection = "<STR_LIT:default>"<EOL><DEDENT><DEDENT>with h5py.File(path, "<STR_LIT:w>") as h5file_output:<EOL><INDENT>h5data_output = h5file_output.require_group("<STR_LIT:data>")<EOL>N = len(dataset) if not selection else dataset.selected_length(selection)<EOL>if N == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>", virtual)<EOL>logger.debug("<STR_LIT>" % (N, path))<EOL>column_names = column_names or dataset.get_column_names(virtual=virtual, strings=True)<EOL>logger.debug("<STR_LIT>" % column_names)<EOL>for column_name in column_names:<EOL><INDENT>dtype = dataset.dtype(column_name)<EOL>if column_name in dataset.get_column_names(strings=True):<EOL><INDENT>column = dataset.columns[column_name]<EOL>shape = (N,) + column.shape[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>shape = (N,)<EOL><DEDENT>if dtype.type == np.datetime64:<EOL><INDENT>array = h5file_output.require_dataset("<STR_LIT>" % column_name, shape=shape, dtype=np.int64)<EOL>array.attrs["<STR_LIT>"] = dtype.name<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>array = h5file_output.require_dataset("<STR_LIT>" % column_name, shape=shape, dtype=dtype.newbyteorder(byteorder))<EOL><DEDENT>except:<EOL><INDENT>logging.exception("<STR_LIT>" % (column_name, dtype))<EOL><DEDENT><DEDENT>array[<NUM_LIT:0>] = array[<NUM_LIT:0>]  <EOL><DEDENT>random_index_name = None<EOL>column_order = list(column_names)  <EOL>if shuffle:<EOL><INDENT>random_index_name = "<STR_LIT>"<EOL>while random_index_name in dataset.get_column_names():<EOL><INDENT>random_index_name += "<STR_LIT>"<EOL><DEDENT>shuffle_array = h5file_output.require_dataset("<STR_LIT>" + random_index_name, shape=(N,), dtype=byteorder + "<STR_LIT>")<EOL>shuffle_array[<NUM_LIT:0>] = shuffle_array[<NUM_LIT:0>]<EOL>column_order.append(random_index_name)  <EOL><DEDENT>h5data_output.attrs["<STR_LIT>"] = "<STR_LIT:U+002C>".join(column_order)  <EOL><DEDENT>dataset_output = vaex.hdf5.dataset.Hdf5MemoryMapped(path, write=True)<EOL>column_names = vaex.export._export(dataset_input=dataset, dataset_output=dataset_output, path=path, random_index_column=random_index_name,<EOL>column_names=column_names, selection=selection, shuffle=shuffle, byteorder=byteorder,<EOL>progress=progress)<EOL>import getpass<EOL>import datetime<EOL>user = getpass.getuser()<EOL>date = str(datetime.datetime.now())<EOL>source = dataset.path<EOL>description = "<STR_LIT>" % (user, date, source)<EOL>if dataset.description:<EOL><INDENT>description += "<STR_LIT>" + dataset.description<EOL><DEDENT>dataset_output.copy_metadata(dataset)<EOL>dataset_output.description = description<EOL>logger.debug("<STR_LIT>")<EOL>dataset_output.write_meta()<EOL>dataset_output.close_files()<EOL>return<EOL>

:param DatasetLocal dataset: dataset to export
:param str path: path for file
:param lis[str] column_names: list of column names to export or None for all columns
:param str byteorder: = for native, < for little endian and > for big endian
:param bool shuffle: export rows in random order
:param bool selection: export selection or not
:param progress: progress callback that gets a progress fraction as argument and should return True to continue,
        or a default progress bar when progress=True
:param: bool virtual: When True, export virtual columns
:return:


def export_hdf5(dataset, path, column_names=None, byteorder="<STR_LIT:=>", shuffle=False, selection=False, progress=None, virtual=True, sort=None, ascending=True):

if selection:<EOL><INDENT>if selection == True:  <EOL><INDENT>selection = "<STR_LIT:default>"<EOL><DEDENT><DEDENT>with h5py.File(path, "<STR_LIT:w>") as h5file_output:<EOL><INDENT>h5table_output = h5file_output.require_group("<STR_LIT>")<EOL>h5table_output.attrs["<STR_LIT:type>"] = "<STR_LIT>"<EOL>h5columns_output = h5file_output.require_group("<STR_LIT>")<EOL>N = len(dataset) if not selection else dataset.selected_length(selection)<EOL>if N == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>", virtual)<EOL>logger.debug("<STR_LIT>" % (N, path))<EOL>column_names = column_names or dataset.get_column_names(virtual=virtual, strings=True)<EOL>logger.debug("<STR_LIT>" % column_names)<EOL>sparse_groups = collections.defaultdict(list)<EOL>sparse_matrices = {}  <EOL>for column_name in list(column_names):<EOL><INDENT>sparse_matrix = dataset._sparse_matrix(column_name)<EOL>if sparse_matrix is not None:<EOL><INDENT>sparse_groups[id(sparse_matrix)].append(column_name)<EOL>sparse_matrices[id(sparse_matrix)] = sparse_matrix<EOL>continue<EOL><DEDENT>dtype = dataset.dtype(column_name)<EOL>if column_name in dataset.get_column_names(virtual=False):<EOL><INDENT>column = dataset.columns[column_name]<EOL>shape = (N,) + column.shape[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>shape = (N,)<EOL><DEDENT>h5column_output = h5columns_output.require_group(column_name)<EOL>if dtype == str_type:<EOL><INDENT>byte_length = dataset[column_name].str.byte_length().sum(selection=selection)<EOL>if byte_length > max_int32:<EOL><INDENT>dtype_indices = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>dtype_indices = '<STR_LIT>'<EOL><DEDENT>data_shape = (byte_length, )<EOL>indices_shape = (N+<NUM_LIT:1>, )<EOL>array = h5column_output.require_dataset('<STR_LIT:data>', shape=data_shape, dtype='<STR_LIT>')<EOL>array[<NUM_LIT:0>] = array[<NUM_LIT:0>]  <EOL>index_array = h5column_output.require_dataset('<STR_LIT>', shape=indices_shape, dtype=dtype_indices)<EOL>index_array[<NUM_LIT:0>] = index_array[<NUM_LIT:0>]  <EOL>null_value_count = N - dataset.count(column_name, selection=selection)<EOL>if null_value_count > <NUM_LIT:0>:<EOL><INDENT>null_shape = ((N + <NUM_LIT:7>) // <NUM_LIT:8>, )  <EOL>null_bitmap_array = h5column_output.require_dataset('<STR_LIT>', shape=null_shape, dtype='<STR_LIT>')<EOL>null_bitmap_array[<NUM_LIT:0>] = null_bitmap_array[<NUM_LIT:0>]  <EOL><DEDENT>array.attrs["<STR_LIT>"] = '<STR_LIT:str>'<EOL><DEDENT>else:<EOL><INDENT>if dtype.kind in '<STR_LIT>':<EOL><INDENT>array = h5column_output.require_dataset('<STR_LIT:data>', shape=shape, dtype=np.int64)<EOL>array.attrs["<STR_LIT>"] = dtype.name<EOL><DEDENT>elif dtype.kind == '<STR_LIT>':<EOL><INDENT>char_length = dtype.itemsize // <NUM_LIT:4><EOL>shape = (N, char_length)<EOL>array = h5column_output.require_dataset('<STR_LIT:data>', shape=shape, dtype=np.uint8)<EOL>array.attrs["<STR_LIT>"] = '<STR_LIT>'<EOL>array.attrs["<STR_LIT>"] = char_length<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>array = h5column_output.require_dataset('<STR_LIT:data>', shape=shape, dtype=dtype.newbyteorder(byteorder))<EOL><DEDENT>except:<EOL><INDENT>logging.exception("<STR_LIT>" % (column_name, dtype))<EOL>del h5columns_output[column_name]<EOL>column_names.remove(column_name)<EOL><DEDENT><DEDENT>array[<NUM_LIT:0>] = array[<NUM_LIT:0>]  <EOL>data = dataset.evaluate(column_name, <NUM_LIT:0>, <NUM_LIT:1>)<EOL>if np.ma.isMaskedArray(data):<EOL><INDENT>mask = h5column_output.require_dataset('<STR_LIT>', shape=shape, dtype=np.bool)<EOL>mask[<NUM_LIT:0>] = mask[<NUM_LIT:0>]  <EOL><DEDENT><DEDENT><DEDENT>random_index_name = None<EOL>column_order = list(column_names)  <EOL>if shuffle:<EOL><INDENT>random_index_name = "<STR_LIT>"<EOL>while random_index_name in dataset.get_column_names():<EOL><INDENT>random_index_name += "<STR_LIT>"<EOL><DEDENT>shuffle_array = h5columns_output.require_dataset(random_index_name + "<STR_LIT>", shape=(N,), dtype=byteorder + "<STR_LIT>")<EOL>shuffle_array[<NUM_LIT:0>] = shuffle_array[<NUM_LIT:0>]<EOL>column_order.append(random_index_name)  <EOL><DEDENT>h5columns_output.attrs["<STR_LIT>"] = "<STR_LIT:U+002C>".join(column_order)  <EOL>sparse_index = <NUM_LIT:0><EOL>for sparse_matrix in sparse_matrices.values():<EOL><INDENT>columns = sorted(sparse_groups[id(sparse_matrix)], key=lambda col: dataset.columns[col].column_index)<EOL>name = "<STR_LIT>" + str(sparse_index)<EOL>sparse_index += <NUM_LIT:1><EOL>sparse_group = h5columns_output.require_group(name)<EOL>sparse_group.attrs['<STR_LIT:type>'] = '<STR_LIT>'<EOL>ar = sparse_group.require_dataset('<STR_LIT:data>', shape=(len(sparse_matrix.data), ), dtype=sparse_matrix.dtype)<EOL>ar[<NUM_LIT:0>] = ar[<NUM_LIT:0>]<EOL>ar = sparse_group.require_dataset('<STR_LIT>', shape=(len(sparse_matrix.indptr), ), dtype=sparse_matrix.indptr.dtype)<EOL>ar[<NUM_LIT:0>] = ar[<NUM_LIT:0>]<EOL>ar = sparse_group.require_dataset('<STR_LIT>', shape=(len(sparse_matrix.indices), ), dtype=sparse_matrix.indices.dtype)<EOL>ar[<NUM_LIT:0>] = ar[<NUM_LIT:0>]<EOL>for i, column_name in enumerate(columns):<EOL><INDENT>h5column = sparse_group.require_group(column_name)<EOL>h5column.attrs['<STR_LIT>'] = i<EOL><DEDENT><DEDENT><DEDENT>dataset_output = vaex.hdf5.dataset.Hdf5MemoryMapped(path, write=True)<EOL>column_names = vaex.export._export(dataset_input=dataset, dataset_output=dataset_output, path=path, random_index_column=random_index_name,<EOL>column_names=column_names, selection=selection, shuffle=shuffle, byteorder=byteorder,<EOL>progress=progress, sort=sort, ascending=ascending)<EOL>import getpass<EOL>import datetime<EOL>user = getpass.getuser()<EOL>date = str(datetime.datetime.now())<EOL>source = dataset.path<EOL>description = "<STR_LIT>" % (user, date, source)<EOL>if dataset.description:<EOL><INDENT>description += "<STR_LIT>" + dataset.description<EOL><DEDENT>dataset_output.copy_metadata(dataset)<EOL>dataset_output.description = description<EOL>logger.debug("<STR_LIT>")<EOL>dataset_output.write_meta()<EOL>dataset_output.close_files()<EOL>return<EOL>


with h5py.File(self.filename, "<STR_LIT>") as h5file_output:<EOL><INDENT>h5table_root = h5file_output[self.h5table_root_name]<EOL>if self.description is not None:<EOL><INDENT>h5table_root.attrs["<STR_LIT:description>"] = self.description<EOL><DEDENT>h5columns = h5table_root if self._version == <NUM_LIT:1> else h5table_root['<STR_LIT>']<EOL>for column_name in self.columns.keys():<EOL><INDENT>h5dataset = None<EOL>if column_name in h5columns:<EOL><INDENT>h5dataset = h5columns[column_name]<EOL><DEDENT>else:<EOL><INDENT>for group in h5columns.values():<EOL><INDENT>if '<STR_LIT:type>' in group.attrs:<EOL><INDENT>if group.attrs['<STR_LIT:type>'] in ['<STR_LIT>']: <EOL><INDENT>for name, column in group.items():<EOL><INDENT>if name == column_name:<EOL><INDENT>h5dataset = column<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if h5dataset is None:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(column_name))<EOL><DEDENT>for name, values in [("<STR_LIT>", self.ucds), ("<STR_LIT>", self.units), ("<STR_LIT:description>", self.descriptions)]:<EOL><INDENT>if column_name in values:<EOL><INDENT>value = ensure_string(values[column_name], cast=True)<EOL>h5dataset.attrs[name] = value<EOL><DEDENT>else:<EOL><INDENT>if name in h5columns.attrs:<EOL><INDENT>del h5dataset.attrs[name]<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

ucds, descriptions and units are written as attributes in the hdf5 file, instead of a seperate file as
         the default :func:`Dataset.write_meta`.


@classmethod<EOL><INDENT>def create(cls, path, N, column_names, dtypes=None, write=True):<DEDENT>

dtypes = dtypes or [np.float] * len(column_names)<EOL>if N == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>with h5py.File(path, "<STR_LIT:w>") as h5file_output:<EOL><INDENT>h5data_output = h5file_output.require_group("<STR_LIT:data>")<EOL>for column_name, dtype in zip(column_names, dtypes):<EOL><INDENT>shape = (N,)<EOL>print(dtype)<EOL>if dtype.type == np.datetime64:<EOL><INDENT>array = h5file_output.require_dataset("<STR_LIT>" % column_name, shape=shape, dtype=np.int64)<EOL>array.attrs["<STR_LIT>"] = dtype.name<EOL><DEDENT>else:<EOL><INDENT>array = h5file_output.require_dataset("<STR_LIT>" % column_name, shape=shape, dtype=dtype)<EOL><DEDENT>array[<NUM_LIT:0>] = array[<NUM_LIT:0>]  <EOL><DEDENT><DEDENT>return Hdf5MemoryMapped(path, write=write)<EOL>

Create a new (empty) hdf5 file with columns given by column names, of length N

        Optionally, numpy dtypes can be passed, default is floats


if self.delay:<EOL><INDENT>return promise<EOL><DEDENT>else:<EOL><INDENT>return promise.get()<EOL><DEDENT>

Helper function for returning tasks results, result when immediate is True, otherwise the task itself, which is a promise


meth.__hidden__ = True<EOL>return meth<EOL>


column = _ensure_string_from_expression(column)<EOL>return column in self._categories<EOL>


self.executor.execute()<EOL>self._task_aggs.clear()<EOL>


def nop(self, expression, progress=False, delay=False):

expression = _ensure_string_from_expression(expression)<EOL>def map(ar):<EOL><INDENT>pass<EOL><DEDENT>def reduce(a, b):<EOL><INDENT>pass<EOL><DEDENT>return self.map_reduce(map, reduce, [expression], delay=delay, progress=progress, name='<STR_LIT>', to_numpy=False)<EOL>

Evaluates expression, and drop the result, usefull for benchmarking, since vaex is usually lazy


@docsubst<EOL><INDENT>def mutual_information(self, x, y=None, mi_limits=None, mi_shape=<NUM_LIT>, binby=[], limits=None, shape=default_shape, sort=False, selection=False, delay=False):<DEDENT>

if y is None:<EOL><INDENT>waslist, [x, ] = vaex.utils.listify(x)<EOL><DEDENT>else:<EOL><INDENT>waslist, [x, y] = vaex.utils.listify(x, y)<EOL>x = list(zip(x, y))<EOL>if mi_limits:<EOL><INDENT>mi_limits = [mi_limits]<EOL><DEDENT><DEDENT>limits = self.limits(binby, limits, delay=True)<EOL>mi_limits = self.limits(x, mi_limits, delay=True)<EOL>@delayed<EOL>def calculate(counts):<EOL><INDENT>counts = counts.astype(np.float64)<EOL>fullshape = _expand_shape(shape, len(binby))<EOL>out = np.zeros((fullshape), dtype=float)<EOL>if len(fullshape) == <NUM_LIT:0>:<EOL><INDENT>out = vaex.kld.mutual_information(counts)<EOL><DEDENT>elif len(fullshape) == <NUM_LIT:1>:<EOL><INDENT>for i in range(fullshape[<NUM_LIT:0>]):<EOL><INDENT>out[i] = vaex.kld.mutual_information(counts[..., i])<EOL><DEDENT><DEDENT>elif len(fullshape) == <NUM_LIT:2>:<EOL><INDENT>for i in range(fullshape[<NUM_LIT:0>]):<EOL><INDENT>for j in range(fullshape[<NUM_LIT:1>]):<EOL><INDENT>out[i, j] = vaex.kld.mutual_information(counts[..., i, j])<EOL><DEDENT><DEDENT><DEDENT>elif len(fullshape) == <NUM_LIT:3>:<EOL><INDENT>for i in range(fullshape[<NUM_LIT:0>]):<EOL><INDENT>for j in range(fullshape[<NUM_LIT:1>]):<EOL><INDENT>for k in range(fullshape[<NUM_LIT:2>]):<EOL><INDENT>out[i, j, k] = vaex.kld.mutual_information(counts[..., i, j, k])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return out<EOL><DEDENT>@delayed<EOL>def has_limits(limits, mi_limits):<EOL><INDENT>if not _issequence(binby):<EOL><INDENT>limits = [list(limits)]<EOL><DEDENT>values = []<EOL>for expressions, expression_limits in zip(x, mi_limits):<EOL><INDENT>total_shape = _expand_shape(mi_shape, len(expressions)) + _expand_shape(shape, len(binby))<EOL>counts = self.count(binby=list(expressions) + list(binby), limits=list(expression_limits) + list(limits),<EOL>shape=total_shape, delay=True, selection=selection)<EOL>values.append(calculate(counts))<EOL><DEDENT>return values<EOL><DEDENT>@delayed<EOL>def finish(mi_list):<EOL><INDENT>if sort:<EOL><INDENT>mi_list = np.array(mi_list)<EOL>indices = np.argsort(mi_list)[::-<NUM_LIT:1>]<EOL>sorted_x = list([x[k] for k in indices])<EOL>return mi_list[indices], sorted_x<EOL><DEDENT>else:<EOL><INDENT>return np.array(vaex.utils.unlistify(waslist, mi_list))<EOL><DEDENT><DEDENT>values = finish(delayed_list(has_limits(limits, mi_limits)))<EOL>return self._delay(delay, values)<EOL>

Estimate the mutual information between and x and y on a grid with shape mi_shape and mi_limits, possibly on a grid defined by binby.

        If sort is True, the mutual information is returned in sorted (descending) order and the list of expressions is returned in the same order.

        Example:

        >>> df.mutual_information("x", "y")
        array(0.1511814526380327)
        >>> df.mutual_information([["x", "y"], ["x", "z"], ["E", "Lz"]])
        array([ 0.15118145,  0.18439181,  1.07067379])
        >>> df.mutual_information([["x", "y"], ["x", "z"], ["E", "Lz"]], sort=True)
        (array([ 1.07067379,  0.18439181,  0.15118145]),
        [['E', 'Lz'], ['x', 'z'], ['x', 'y']])

        :param x: {expression}
        :param y: {expression}
        :param limits: {limits}
        :param shape: {shape}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param sort: return mutual information in sorted (descending) order, and also return the correspond list of expressions when sorted is True
        :param selection: {selection}
        :param delay: {delay}
        :return: {return_stat_scalar},


@docsubst<EOL><INDENT>def count(self, expression=None, binby=[], limits=None, shape=default_shape, selection=False, delay=False, edges=False, progress=None):<DEDENT>

return self._compute_agg('<STR_LIT:count>', expression, binby, limits, shape, selection, delay, edges, progress)<EOL>

Count the number of non-NaN values (or all, if expression is None or "*").

        Example:

        >>> df.count()
        330000
        >>> df.count("*")
        330000.0
        >>> df.count("*", binby=["x"], shape=4)
        array([  10925.,  155427.,  152007.,   10748.])

        :param expression: Expression or column for which to count non-missing values, or None or '*' for counting the rows
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :param edges: {edges}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>def first(self, expression, order_expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, edges=False, progress=None):<DEDENT>

return self._compute_agg('<STR_LIT>', expression, binby, limits, shape, selection, delay, edges, progress, extra_expressions=[order_expression])<EOL>logger.debug("<STR_LIT>", expression, binby, limits)<EOL>logger.debug("<STR_LIT>", expression, binby, limits)<EOL>expression = _ensure_strings_from_expressions(expression)<EOL>order_expression = _ensure_string_from_expression(order_expression)<EOL>binby = _ensure_strings_from_expressions(binby)<EOL>waslist, [expressions,] = vaex.utils.listify(expression)<EOL>@delayed<EOL>def finish(*counts):<EOL><INDENT>counts = np.asarray(counts)<EOL>return vaex.utils.unlistify(waslist, counts)<EOL><DEDENT>progressbar = vaex.utils.progressbars(progress)<EOL>limits = self.limits(binby, limits, delay=True, shape=shape)<EOL>stats = [self._first_calculation(expression, order_expression, binby=binby, limits=limits, shape=shape, selection=selection, edges=edges, progressbar=progressbar) for expression in expressions]<EOL>var = finish(*stats)<EOL>return self._delay(delay, var)<EOL>

Return the first element of a binned `expression`, where the values each bin are sorted by `order_expression`.

        Example:

        >>> import vaex
        >>> df = vaex.example()
        >>> df.first(df.x, df.y, shape=8)
        >>> df.first(df.x, df.y, shape=8, binby=[df.y])
        >>> df.first(df.x, df.y, shape=8, binby=[df.y])
        array([-4.81883764, 11.65378   ,  9.70084476, -7.3025589 ,  4.84954977,
                8.47446537, -5.73602629, 10.18783   ])

        :param expression: The value to be placed in the bin.
        :param order_expression: Order the values in the bins by this expression.
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :param edges: {edges}
        :return: Ndarray containing the first elements.
        :rtype: numpy.array


@docsubst<EOL><INDENT>@stat_1d<EOL>def mean(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None, edges=False):<DEDENT>

return self._compute_agg('<STR_LIT>', expression, binby, limits, shape, selection, delay, edges, progress)<EOL>logger.debug("<STR_LIT>", expression, binby, limits, shape, selection, delay)<EOL>expression = _ensure_strings_from_expressions(expression)<EOL>selection = _ensure_strings_from_expressions(selection)<EOL>binby = _ensure_strings_from_expressions(binby)<EOL>@delayed<EOL>def calculate(expression, limits):<EOL><INDENT>task = tasks.TaskStatistic(self, binby, shape, limits, weight=expression, op=tasks.OP_ADD_WEIGHT_MOMENTS_01, selection=selection)<EOL>self.executor.schedule(task)<EOL>progressbar.add_task(task, "<STR_LIT>" % expression)<EOL>return task<EOL><DEDENT>@delayed<EOL>def finish(*stats_args):<EOL><INDENT>stats = np.array(stats_args)<EOL>counts = stats[..., <NUM_LIT:0>]<EOL>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>mean = stats[..., <NUM_LIT:1>] / counts<EOL><DEDENT>return vaex.utils.unlistify(waslist, mean)<EOL><DEDENT>waslist, [expressions, ] = vaex.utils.listify(expression)<EOL>progressbar = vaex.utils.progressbars(progress)<EOL>limits = self.limits(binby, limits, delay=True)<EOL>stats = [calculate(expression, limits) for expression in expressions]<EOL>var = finish(*stats)<EOL>return self._delay(delay, var)<EOL>

Calculate the mean for expression, possibly on a grid defined by binby.

        Example:

        >>> df.mean("x")
        -0.067131491264005971
        >>> df.mean("(x**2+y**2)**0.5", binby="E", shape=4)
        array([  2.43483742,   4.41840721,   8.26742458,  15.53846476])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>@stat_1d<EOL>def sum(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None, edges=False):<DEDENT>

return self._compute_agg('<STR_LIT>', expression, binby, limits, shape, selection, delay, edges, progress)<EOL>@delayed<EOL>def finish(*sums):<EOL><INDENT>return vaex.utils.unlistify(waslist, sums)<EOL><DEDENT>expression = _ensure_strings_from_expressions(expression)<EOL>binby = _ensure_strings_from_expressions(binby)<EOL>waslist, [expressions, ] = vaex.utils.listify(expression)<EOL>progressbar = vaex.utils.progressbars(progress)<EOL>limits = self.limits(binby, limits, delay=True)<EOL>sums = [self._sum_calculation(expression, binby=binby, limits=limits, shape=shape, selection=selection, progressbar=progressbar) for expression in expressions]<EOL>s = finish(*sums)<EOL>return self._delay(delay, s)<EOL>

Calculate the sum for the given expression, possible on a grid defined by binby

        Example:

        >>> df.sum("L")
        304054882.49378014
        >>> df.sum("L", binby="E", shape=4)
        array([  8.83517994e+06,   5.92217598e+07,   9.55218726e+07,
                         1.40008776e+08])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>@stat_1d<EOL>def std(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None):<DEDENT>

@delayed<EOL>def finish(var):<EOL><INDENT>return var**<NUM_LIT:0.5><EOL><DEDENT>return self._delay(delay, finish(self.var(expression, binby=binby, limits=limits, shape=shape, selection=selection, delay=True, progress=progress)))<EOL>

Calculate the standard deviation for the given expression, possible on a grid defined by binby

        >>> df.std("vz")
        110.31773397535071
        >>> df.std("vz", binby=["(x**2+y**2)**0.5"], shape=4)
        array([ 123.57954851,   85.35190177,   61.14345748,   38.0740619 ])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>@stat_1d<EOL>def var(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None):<DEDENT>

expression = _ensure_strings_from_expressions(expression)<EOL>@delayed<EOL>def calculate(expression, limits):<EOL><INDENT>task = tasks.TaskStatistic(self, binby, shape, limits, weight=expression, op=tasks.OP_ADD_WEIGHT_MOMENTS_012, selection=selection)<EOL>progressbar.add_task(task, "<STR_LIT>" % expression)<EOL>self.executor.schedule(task)<EOL>return task<EOL><DEDENT>@delayed<EOL>def finish(*stats_args):<EOL><INDENT>stats = np.array(stats_args)<EOL>counts = stats[..., <NUM_LIT:0>]<EOL>with np.errstate(divide='<STR_LIT:ignore>'):<EOL><INDENT>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):  <EOL><INDENT>mean = stats[..., <NUM_LIT:1>] / counts<EOL>raw_moments2 = stats[..., <NUM_LIT:2>] / counts<EOL><DEDENT><DEDENT>variance = (raw_moments2 - mean**<NUM_LIT:2>)<EOL>return vaex.utils.unlistify(waslist, variance)<EOL><DEDENT>binby = _ensure_strings_from_expressions(binby)<EOL>waslist, [expressions, ] = vaex.utils.listify(expression)<EOL>progressbar = vaex.utils.progressbars(progress)<EOL>limits = self.limits(binby, limits, delay=True)<EOL>stats = [calculate(expression, limits) for expression in expressions]<EOL>var = finish(*stats)<EOL>return self._delay(delay, var)<EOL>


@docsubst<EOL><INDENT>def covar(self, x, y, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None):<DEDENT>

@delayed<EOL>def cov(mean_x, mean_y, mean_xy):<EOL><INDENT>return mean_xy - mean_x * mean_y<EOL><DEDENT>waslist, [xlist, ylist] = vaex.utils.listify(x, y)<EOL>limits = self.limits(binby, limits, selection=selection, delay=True)<EOL>@delayed<EOL>def calculate(limits):<EOL><INDENT>results = []<EOL>for x, y in zip(xlist, ylist):<EOL><INDENT>mx = self.mean(x, binby=binby, limits=limits, shape=shape, selection=selection, delay=True, progress=progressbar)<EOL>my = self.mean(y, binby=binby, limits=limits, shape=shape, selection=selection, delay=True, progress=progressbar)<EOL>cxy = self.mean("<STR_LIT>" % (x, y), binby=binby, limits=limits, shape=shape, selection=selection,<EOL>delay=True, progress=progressbar)<EOL>results.append(cov(mx, my, cxy))<EOL><DEDENT>return results<EOL><DEDENT>progressbar = vaex.utils.progressbars(progress)<EOL>covars = calculate(limits)<EOL>@delayed<EOL>def finish(covars):<EOL><INDENT>value = np.array(vaex.utils.unlistify(waslist, covars))<EOL>return value<EOL><DEDENT>return self._delay(delay, finish(delayed_list(covars)))<EOL>

Calculate the covariance cov[x,y] between and x and y, possibly on a grid defined by binby.

        Example:

        >>> df.covar("x**2+y**2+z**2", "-log(-E+1)")
        array(52.69461456005138)
        >>> df.covar("x**2+y**2+z**2", "-log(-E+1)")/(df.std("x**2+y**2+z**2") * df.std("-log(-E+1)"))
        0.63666373822156686
        >>> df.covar("x**2+y**2+z**2", "-log(-E+1)", binby="Lz", shape=4)
        array([ 10.17387143,  51.94954078,  51.24902796,  20.2163929 ])

        :param x: {expression}
        :param y: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>def correlation(self, x, y=None, binby=[], limits=None, shape=default_shape, sort=False, sort_key=np.abs, selection=False, delay=False, progress=None):<DEDENT>

@delayed<EOL>def corr(cov):<EOL><INDENT>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):  <EOL><INDENT>return cov[..., <NUM_LIT:0>, <NUM_LIT:1>] / (cov[..., <NUM_LIT:0>, <NUM_LIT:0>] * cov[..., <NUM_LIT:1>, <NUM_LIT:1>])**<NUM_LIT:0.5><EOL><DEDENT><DEDENT>if y is None:<EOL><INDENT>if not isinstance(x, (tuple, list)):<EOL><INDENT>raise ValueError("<STR_LIT>" % x)<EOL><DEDENT>if _issequence(x) and not _issequence(x[<NUM_LIT:0>]) and len(x) == <NUM_LIT:2>:<EOL><INDENT>x = [x]<EOL><DEDENT>if not(_issequence(x) and all([_issequence(k) and len(k) == <NUM_LIT:2> for k in x])):<EOL><INDENT>raise ValueError("<STR_LIT>" % x)<EOL><DEDENT>waslist = True<EOL>xlist, ylist = zip(*x)<EOL><DEDENT>else:<EOL><INDENT>waslist, [xlist, ylist] = vaex.utils.listify(x, y)<EOL><DEDENT>limits = self.limits(binby, limits, selection=selection, delay=True)<EOL>@delayed<EOL>def echo(limits):<EOL><INDENT>logger.debug("<STR_LIT>", limits, np.array(limits).shape)<EOL><DEDENT>echo(limits)<EOL>@delayed<EOL>def calculate(limits):<EOL><INDENT>results = []<EOL>for x, y in zip(xlist, ylist):<EOL><INDENT>task = self.cov(x, y, binby=binby, limits=limits, shape=shape, selection=selection, delay=True,<EOL>progress=progressbar)<EOL>results.append(corr(task))<EOL><DEDENT>return results<EOL><DEDENT>progressbar = vaex.utils.progressbars(progress)<EOL>correlations = calculate(limits)<EOL>@delayed<EOL>def finish(correlations):<EOL><INDENT>if sort:<EOL><INDENT>correlations = np.array(correlations)<EOL>indices = np.argsort(sort_key(correlations) if sort_key else correlations)[::-<NUM_LIT:1>]<EOL>sorted_x = list([x[k] for k in indices])<EOL>return correlations[indices], sorted_x<EOL><DEDENT>value = np.array(vaex.utils.unlistify(waslist, correlations))<EOL>return value<EOL><DEDENT>return self._delay(delay, finish(delayed_list(correlations)))<EOL>

Calculate the correlation coefficient cov[x,y]/(std[x]*std[y]) between and x and y, possibly on a grid defined by binby.

        Example:

        >>> df.correlation("x**2+y**2+z**2", "-log(-E+1)")
        array(0.6366637382215669)
        >>> df.correlation("x**2+y**2+z**2", "-log(-E+1)", binby="Lz", shape=4)
        array([ 0.40594394,  0.69868851,  0.61394099,  0.65266318])

        :param x: {expression}
        :param y: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}


@docsubst<EOL><INDENT>def cov(self, x, y=None, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None):<DEDENT>

selection = _ensure_strings_from_expressions(selection)<EOL>if y is None:<EOL><INDENT>if not _issequence(x):<EOL><INDENT>raise ValueError("<STR_LIT>", x)<EOL><DEDENT>expressions = x<EOL><DEDENT>else:<EOL><INDENT>expressions = [x, y]<EOL><DEDENT>N = len(expressions)<EOL>binby = _ensure_list(binby)<EOL>shape = _expand_shape(shape, len(binby))<EOL>progressbar = vaex.utils.progressbars(progress)<EOL>limits = self.limits(binby, limits, selection=selection, delay=True)<EOL>@delayed<EOL>def calculate(expressions, limits):<EOL><INDENT>task = tasks.TaskStatistic(self, binby, shape, limits, weights=expressions, op=tasks.OP_COV, selection=selection)<EOL>self.executor.schedule(task)<EOL>progressbar.add_task(task, "<STR_LIT>" % expressions)<EOL>return task<EOL><DEDENT>@delayed<EOL>def finish(values):<EOL><INDENT>N = len(expressions)<EOL>counts = values[..., :N]<EOL>sums = values[..., N:<NUM_LIT:2> * N]<EOL>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>means = sums / counts<EOL><DEDENT>meansxy = means[..., None] * means[..., None, :]<EOL>counts = values[..., <NUM_LIT:2> * N:<NUM_LIT:2> * N + N**<NUM_LIT:2>]<EOL>sums = values[..., <NUM_LIT:2> * N + N**<NUM_LIT:2>:]<EOL>shape = counts.shape[:-<NUM_LIT:1>] + (N, N)<EOL>counts = counts.reshape(shape)<EOL>sums = sums.reshape(shape)<EOL>with np.errstate(divide='<STR_LIT:ignore>', invalid='<STR_LIT:ignore>'):<EOL><INDENT>moments2 = sums / counts<EOL><DEDENT>cov_matrix = moments2 - meansxy<EOL>return cov_matrix<EOL><DEDENT>progressbar = vaex.utils.progressbars(progress)<EOL>values = calculate(expressions, limits)<EOL>cov_matrix = finish(values)<EOL>return self._delay(delay, cov_matrix)<EOL>


@docsubst<EOL><INDENT>@stat_1d<EOL>def minmax(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None):<DEDENT>

<EOL>@delayed<EOL>def finish(*minmax_list):<EOL><INDENT>value = vaex.utils.unlistify(waslist, np.array(minmax_list))<EOL>value = value.astype(dtype0)<EOL>return value<EOL><DEDENT>@delayed<EOL>def calculate(expression, limits):<EOL><INDENT>task = tasks.TaskStatistic(self, binby, shape, limits, weight=expression, op=tasks.OP_MIN_MAX, selection=selection)<EOL>self.executor.schedule(task)<EOL>progressbar.add_task(task, "<STR_LIT>" % expression)<EOL>return task<EOL><DEDENT>@delayed<EOL>def finish(*minmax_list):<EOL><INDENT>value = vaex.utils.unlistify(waslist, np.array(minmax_list))<EOL>value = value.astype(dtype0)<EOL>return value<EOL><DEDENT>expression = _ensure_strings_from_expressions(expression)<EOL>binby = _ensure_strings_from_expressions(binby)<EOL>waslist, [expressions, ] = vaex.utils.listify(expression)<EOL>dtypes = [self.dtype(expr) for expr in expressions]<EOL>dtype0 = dtypes[<NUM_LIT:0>]<EOL>if not all([k.kind == dtype0.kind for k in dtypes]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>progressbar = vaex.utils.progressbars(progress, name="<STR_LIT>")<EOL>limits = self.limits(binby, limits, selection=selection, delay=True)<EOL>all_tasks = [calculate(expression, limits) for expression in expressions]<EOL>result = finish(*all_tasks)<EOL>return self._delay(delay, result)<EOL>

Calculate the minimum and maximum for expressions, possibly on a grid defined by binby.

        Example:

        >>> df.minmax("x")
        array([-128.293991,  271.365997])
        >>> df.minmax(["x", "y"])
        array([[-128.293991 ,  271.365997 ],
                   [ -71.5523682,  146.465836 ]])
        >>> df.minmax("x", binby="x", shape=5, limits=[-10, 10])
        array([[-9.99919128, -6.00010443],
                   [-5.99972439, -2.00002384],
                   [-1.99991322,  1.99998057],
                   [ 2.0000093 ,  5.99983597],
                   [ 6.0004878 ,  9.99984646]])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}, the last dimension is of shape (2)


@docsubst<EOL><INDENT>@stat_1d<EOL>def min(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None, edges=False):<DEDENT>

return self._compute_agg('<STR_LIT>', expression, binby, limits, shape, selection, delay, edges, progress)<EOL>@delayed<EOL>def finish(result):<EOL><INDENT>return result[..., <NUM_LIT:0>]<EOL><DEDENT>return self._delay(delay, finish(self.minmax(expression, binby=binby, limits=limits, shape=shape, selection=selection, delay=delay, progress=progress)))<EOL>

Calculate the minimum for given expressions, possibly on a grid defined by binby.

        Example:

        >>> df.min("x")
        array(-128.293991)
        >>> df.min(["x", "y"])
        array([-128.293991 ,  -71.5523682])
        >>> df.min("x", binby="x", shape=5, limits=[-10, 10])
        array([-9.99919128, -5.99972439, -1.99991322,  2.0000093 ,  6.0004878 ])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}, the last dimension is of shape (2)


@docsubst<EOL><INDENT>@stat_1d<EOL>def max(self, expression, binby=[], limits=None, shape=default_shape, selection=False, delay=False, progress=None, edges=False):<DEDENT>

return self._compute_agg('<STR_LIT>', expression, binby, limits, shape, selection, delay, edges, progress)<EOL>@delayed<EOL>def finish(result):<EOL><INDENT>return result[..., <NUM_LIT:1>]<EOL><DEDENT>return self._delay(delay, finish(self.minmax(expression, binby=binby, limits=limits, shape=shape, selection=selection, delay=delay, progress=progress)))<EOL>

Calculate the maximum for given expressions, possibly on a grid defined by binby.

        Example:

        >>> df.max("x")
        array(271.365997)
        >>> df.max(["x", "y"])
        array([ 271.365997,  146.465836])
        >>> df.max("x", binby="x", shape=5, limits=[-10, 10])
        array([-6.00010443, -2.00002384,  1.99998057,  5.99983597,  9.99984646])

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param selection: {selection}
        :param delay: {delay}
        :param progress: {progress}
        :return: {return_stat_scalar}, the last dimension is of shape (2)


@docsubst<EOL><INDENT>@stat_1d<EOL>def median_approx(self, expression, percentage=<NUM_LIT>, binby=[], limits=None, shape=default_shape, percentile_shape=<NUM_LIT>, percentile_limits="<STR_LIT>", selection=False, delay=False):<DEDENT>

return self.percentile_approx(expression, <NUM_LIT:50>, binby=binby, limits=limits, shape=shape, percentile_shape=percentile_shape, percentile_limits=percentile_limits, selection=selection, delay=delay)<EOL>

Calculate the median , possibly on a grid defined by binby.

        NOTE: this value is approximated by calculating the cumulative distribution on a grid defined by
        percentile_shape and percentile_limits

        :param expression: {expression}
        :param binby: {binby}
        :param limits: {limits}
        :param shape: {shape}
        :param percentile_limits: {percentile_limits}
        :param percentile_shape: {percentile_shape}
        :param selection: {selection}
        :param delay: {delay}
        :return: {return_stat_scalar}