Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation or spacing causing issues with documentation #135

Open
RoyLarson opened this issue Feb 23, 2021 · 1 comment
Open

Indentation or spacing causing issues with documentation #135

RoyLarson opened this issue Feb 23, 2021 · 1 comment
Labels

Comments

@RoyLarson
Copy link

I was reading through the docs at
https://mystic.readthedocs.io/en/latest/mystic.html#module-mystic.constraints

And I noticed that some of the examples are displayed correctly e.g.
the impose_as example

and some of the examples do not display correctly e.g.
with_constraint example

This seems to be related to the indentation in the docstrings where the examples that display correctly are indented compared to the 'For Example:' header or there needs to be an extra line between the example and other text'

Example of extra indentation

def impose_as(mask, offset=None):
    """generate a function, where some input tracks another input
mask should be a set of tuples of positional index and tracked index,
where the tuple should contain two different integers. The mask will be
applied to the input, before the decorated function is called.
The offset is applied to the second member of the tuple, and can accumulate.
For example,
    >>> @impose_as([(0,1),(3,1),(4,5),(5,6),(5,7)])
    ... def same(x):
    ...   return x
    ... 
    >>> same([9,8,7,6,5,4,3,2,1])
    [9, 9, 7, 9, 5, 5, 5, 5, 1]
    >>> same([0,1,0,1])
    [0, 0, 0, 0]
    >>> same([-1,-2,-3,-4,-5,-6,-7])
    [-1, -1, -3, -1, -5, -5, -5]
    >>> 
    >>> @impose_as([(0,1),(3,1),(4,5),(5,6),(5,7)], 10)
    ... def doit(x):
    ...   return x
    ... 
    >>> doit([9,8,7,6,5,4,3,2,1])
    [9, 19, 7, 9, 5, 15, 25, 25, 1]
    >>> doit([0,1,0,1])
    [0, 10, 0, 0]
    >>> doit([-1,-2,-3,-4,-5,-6])
    [-1, 9, -3, -1, -5, 5]
    >>> doit([-1,-2,-3,-4,-5,-6,-7])
    [-1, 9, -3, -1, -5, 5, 15]
    """

example of extra line

def discrete(samples, index=None):
    """impose a discrete set of input values for the selected function
The function's input will be mapped to the given discrete set

>>> @discrete([1.0, 2.0])
... def identity(x):
...     return x

>>> identity([0.123, 1.789, 4.000])
[1.0, 2.0, 2.0]

>>> @discrete([1,3,5,7], index=(0,3))
... def squared(x):
....    return [i**2 for i in x]

>>> squared([0,2,4,6,8,10])
[1, 4, 16, 25, 64, 100]"""

example of failing

def with_constraint(ctype, *args, **kwds): #XXX: is this *at all* useful?
    """convert a set transformation to a constraints solver of the chosen type 

transformation f(x) is a mapping between x and x', where x' = f(x). 
ctype is a mystic.coupler type [inner, outer, inner_proxy, outer_proxy].

    For example:
    >>> @with_constraint(inner, kwds={'target':5.0})
    ... def constraint(x, target):
    ...   return impose_mean(target, x)
    ... 
    >>> x = constraint([1,2,3,4,5])
    >>> print(x)
    [3.0, 4.0, 5.0, 6.0, 7.0]
    >>> mean(x)
    5.0
    """
@mmckerns mmckerns added the bug label Feb 24, 2021
@mmckerns
Copy link
Member

This is a known issue. A while ago, there was an effort to go through all the docs to make them more standards compliant (so they render better). However, not all the docs were processed, so this issue remains on several files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants