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

DONTMERGE: improve repr by a lot #1276

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

kohr-h
Copy link
Member

@kohr-h kohr-h commented Jan 29, 2018

Summary:

  • add helper _separators to determine string
    separators that keep a repr string within a
    given line width
  • split repr string rendering into two functions,
    one to determine the parts to be printed and
    one to compile the final string (with separators)
  • attribute_repr_string helper to class attributes
  • element_repr_string helper to print space
    elements
  • make repr printing of product space elements more
    consistent
  • improve default repr of Operator (now actually
    good by default, but unspecific)
  • use Numpy's print options as a single point to
    configure printing
  • add doctests to lots of __repr__ methods

Further miscellaneous changes:

  • fix bug of uniform_discr_fromdiscr ignoring dtype
  • sort imports using the isort tool (mode -m 4)
  • add asweighted to base_tensors to make weighted
    and unweighted spaces compatible in tensor operators
  • remove base classes for operator and adjoint in
    favor of inner adjoint classes (less code)
  • make most default operators take domain and range
    and implement the corresponding adjoints/inverses etc.
  • implement noise_array for product spaces that
    are not power spaces
  • remove the almost_equal test util
  • improve a number of doctests (use odl. calls,
    better names etc.)
  • make comparison of arrays in tests faster
  • implement broadcasting of shapes (M, N) and (N,)
    in product spaces
  • remove some remaining doc glitches, mostly FnBase

TODO:

  • go through rest of the library
  • replace almost_equal by pytest.approx
  • tests for pspace broadcasting
  • make uniform_discr_fromdiscr respect weighting
  • fix failing unit tests
  • Use better scheme for linewidth

@pep8speaks
Copy link

pep8speaks commented Jan 29, 2018

Checking updated PR...

Line 196:1: E305 expected 2 blank lines after class or function definition, found 1
Line 125:1: E305 expected 2 blank lines after class or function definition, found 1

  • Complete extra results for this file :

print_mrc2014_spec.doc += MRC_2014_SPEC_TABLE^print_fei_ext_header_spec.doc += MRC_FEI_EXT_HEADER_SECTION^---

Line 93:25: E126 continuation line over-indented for hanging indent

  • Complete extra results for this file :
                    self.operator.range.dtype,                        ^---

Line 383:5: E741 ambiguous variable name 'I'

  • Complete extra results for this file :
I = odl.IdentityOperator(space)    ^---

Line 1260:1: E265 block comment should start with '# '
Line 46:1: E265 block comment should start with '# '

  • Complete extra results for this file :

#TODO:^#TODO: continue here^---

Comment last updated on March 11, 2018 at 23:31 Hours UTC

@adler-j
Copy link
Member

adler-j commented Jan 31, 2018

Is this work in progress?

@kohr-h
Copy link
Member Author

kohr-h commented Jan 31, 2018

Is this work in progress?

Yes, but the functionality is all there, I just need to go through the remaining parts of the library (solvers mostly) and fix the failing tests due to almost_equal being gone.

@kohr-h
Copy link
Member Author

kohr-h commented Jan 31, 2018

That said, you can definitely have a look at the tooling and the outcome in, e.g., the default_operators or tensor_ops, and say if you like it or not. I've added doctests for all of their __repr__ methods. Product space printing style may be most subjective place.

Copy link
Member

@adler-j adler-j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements overall!

posargs = [self.domain]
optargs = [('range', self.range, self.domain ** self.domain.ndim),
optargs = [('range', self.range, self.domain),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, what?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wrong

@@ -68,10 +70,27 @@ def __init__(self, space, exponent):
Domain of the functional.
exponent : float
Exponent for the norm (``p``).


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blankrows

--------
>>> space = odl.rn(2)
>>> l1norm = odl.solvers.LpNorm(space, exponent=1)
>>> l1norm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this extra line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was guessing that already 😉

--------
>>> pspace = odl.ProductSpace(odl.rn(2), 2)
>>> l1_2_norm = odl.solvers.GroupL1Norm(pspace, exponent=2)
>>> l1_2_norm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per above (and in the future) I think this line is redundant



class IndicatorGroupL1UnitBall(Functional):

"""The convex conjugate to the mixed L1--Lp norm on `ProductSpace`.
"""Indicator functional of the unit ball in the Group-L1 norm.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these, we should perhaps be more clear in what we mean by "indicator function" since this has different meanings in different contexts.


This functional maps all elements in the domain to a given, constant value.
"""
"""Functional mapping all inputs to the same constant."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add the word "scalar" before constant

Examples
--------
>>> space = odl.rn(2)
>>> op = odl.solvers.ConstantFunctional(space, 1.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just squeeze these to one line, e.g.

>>> odl.solvers.ConstantFunctional(odl.rn(2), 1.5)
ConstantFunctional(rn(2), constant=1.5)

>>> space = odl.rn(3)
>>> func = odl.solvers.IndicatorBox(space, 0, 2)
>>> func
IndicatorBox(rn(3), lower=0, upper=2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of named arguments per default, this is much easier to read!

"""
posargs = [self.domain]
with npy_printoptions(precision=REPR_PRECISION):
inner_parts = signature_string_parts(posargs, [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short thought here, shouldn't the "[]" be a default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could make that the default.

allow_mixed_seps=False)


#TODO: continue here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yupp :D

@adler-j
Copy link
Member

adler-j commented Mar 13, 2018

Any chance to get this done, improved reprs is always welcome :)

@kohr-h
Copy link
Member Author

kohr-h commented Mar 13, 2018

I'm working my way through it, slowly. Still stuff left to do. Will look into it this week.

Holger Kohr and others added 12 commits April 13, 2018 00:51
- add helper `_separators` to determine string
  separators that keep a `repr` string within a
  given line width
- split repr string rendering into two functions,
  one to determine the parts to be printed and
  one to compile the final string (with separators)
- `attribute_repr_string` helper to class attributes
- `element_repr_string` helper to print space
  elements
- make repr printing of product space elements more
  consistent
- improve default repr of `Operator` (now actually
  good by default, but unspecific)
- use Numpy's print options as a single point to
  configure printing
- add doctests to lots of `__repr__` methods

Further miscellaneous changes:
- fix bug of `uniform_discr_fromdiscr` ignoring dtype
- sort imports using the `isort` tool (mode `-m 4`)
- add `asweighted` to base_tensors to make weighted
  and unweighted spaces compatible in tensor operators
- remove base classes for operator and adjoint in
  favor of inner adjoint classes (less code)
- make most default operators take `domain` and `range`
  and implement the corresponding adjoints/inverses etc.
- implement `noise_array` for product spaces that
  are not power spaces
- remove the `almost_equal` test util
- improve a number of doctests (use `odl.` calls,
  better names etc.)
- make comparison of arrays in tests faster
- implement broadcasting of shapes (M, N) and (N,)
  in product spaces
- remove some remaining doc glitches, mostly `FnBase`

TODO:
- go through rest of the library
- replace `almost_equal` by `pytest.approx`
- tests for pspace broadcasting
- make `uniform_discr_fromdiscr` respect weighting
- fix failing unit tests
"""Return ``str(self)``."""
dom_ran_str = '\n-->\n'.join([repr(self.domain), repr(self.range)])
return '{}:\n{}'.format(self.__class__.__name__, indent(dom_ran_str))
optmod = ['!r', '', '', '']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary

@kohr-h kohr-h changed the title WIP: improve repr by a lot DONTMERGE: improve repr by a lot Jun 19, 2018
@kohr-h kohr-h mentioned this pull request Jun 25, 2018
3 tasks
@adler-j adler-j mentioned this pull request Sep 11, 2018
20 tasks
@kohr-h kohr-h added this to In Progress in Release 1.0.0 Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PR Status
In revision
Release 1.0.0
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

3 participants