Skip to content

Commit

Permalink
MAINT: fix a bunch of minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Holger Kohr committed Oct 2, 2017
1 parent 1d13121 commit 34c0a26
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 224 deletions.
12 changes: 5 additions & 7 deletions doc/source/refs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ References
Imaging*. Journal of Mathematical Imaging and Vision, 40 (2011),
pp 120-145.
.. [CP2011b] Chambolle, A and Pock, T. *Diagonal
preconditioning for first order primal-dual algorithms in convex
optimization*. 2011 IEEE International Conference on Computer Vision
(ICCV), 2011, pp 1762-1769.
.. [CP2011b] Chambolle, A and Pock, T.
*Diagonal preconditioning for first order primal-dual algorithms in convex optimization*.
2011 IEEE International Conference on Computer Vision (ICCV), 2011, pp 1762-1769.
.. [PB2014] Parikh, N, and Boyd, S. *Proximal Algorithms*.
Foundations and Trends in Optimization, 1 (2014), pp 127-239.
Expand All @@ -23,9 +22,8 @@ References
University Press, 1970.
.. [Sid+2012] Sidky, E Y, Jorgensen, J H, and Pan, X.
*Convex optimization problem prototyping for image reconstruction in
computed tomography with the Chambolle-Pock algorithm*. Physics in
Medicine and Biology, 57 (2012), pp 3065-3091.
*Convex optimization problem prototyping for image reconstruction in computed tomography with the Chambolle-Pock algorithm*.
Physics in Medicine and Biology, 57 (2012), pp 3065-3091.
.. [SW1971] Stein, E, and Weiss, G.
*Introduction to Fourier Analysis on Euclidean Spaces*.
Expand Down
2 changes: 1 addition & 1 deletion odl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .set import *
__all__ += set.__all__

# operator must come before space because npy_ntuples imports Operator
# operator must come before space because fspace imports Operator
from .operator import *
__all__ += operator.__all__

Expand Down
14 changes: 7 additions & 7 deletions odl/discr/discr_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ def __init__(self, fspace, partition, dspace, variant='left'):
assumed to be sorted in ascending order in each dimension
for efficiency reasons.
- Nearest neighbor interpolation is the only scheme which works
with data of non-scalar type since it does not involve any
arithmetic operations on the values.
- The distinction between 'left' and 'right' variants is currently
with data of non-numeric data type since it does not involve any
arithmetic operations on the values, in contrast to other
interpolation methods.
- The distinction between left and right variants is currently
made by changing ``<=`` to ``<`` at one place. This difference
may not be noticable in some situations due to rounding errors.
"""
Expand Down Expand Up @@ -398,7 +399,7 @@ def nearest(arg, out=None):
input_type = 'array'

interpolator = _NearestInterpolator(
self.grid.coord_vectors, x.asarray(), variant=self.variant,
self.grid.coord_vectors, x, variant=self.variant,
input_type=input_type)

return interpolator(arg, out=out)
Expand Down Expand Up @@ -454,7 +455,7 @@ def linear(arg, out=None):
input_type = 'array'

interpolator = _LinearInterpolator(
self.grid.coord_vectors, x.asarray(), input_type=input_type)
self.grid.coord_vectors, x, input_type=input_type)

return interpolator(arg, out=out)

Expand Down Expand Up @@ -590,8 +591,7 @@ def per_axis_interp(arg, out=None):
input_type = 'array'

interpolator = _PerAxisInterpolator(
self.grid.coord_vectors,
x.asarray(),
self.grid.coord_vectors, x,
schemes=self.schemes, nn_variants=self.nn_variants,
input_type=input_type)

Expand Down
8 changes: 4 additions & 4 deletions odl/discr/discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def one(self):
@property
def weighting(self):
"""This space's weighting scheme."""
return getattr(self.dspace, 'weighting', None)
return self.dspace.weighting

@property
def is_weighted(self):
Expand Down Expand Up @@ -443,9 +443,9 @@ def interpolation(self):

def __ipow__(self, p):
"""Implement ``self **= p``."""
# Falls back to `LinearSpaceElement.__ipow__` if `self.tensor`
# has no own `__ipow__`. The fallback only works for integer `p`.
# TODO: do we even need this??
# The concrete `tensor` can specialize `__ipow__` for non-integer
# `p` so we want to use it here. Otherwise we get the default
# `LinearSpaceElement.__ipow__` which only works for integer `p`.
self.tensor.__ipow__(p)
return self

Expand Down
3 changes: 2 additions & 1 deletion odl/operator/default_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import numpy as np

from odl.operator.operator import Operator
from odl.set import LinearSpace, Field, RealNumbers
from odl.set.space import LinearSpaceElement
from odl.space import ProductSpace
from odl.set import LinearSpace, LinearSpaceElement, Field, RealNumbers


__all__ = ('ScalingOperator', 'ZeroOperator', 'IdentityOperator',
Expand Down
3 changes: 2 additions & 1 deletion odl/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from numbers import Number, Integral
import sys

from odl.set import LinearSpace, LinearSpaceElement, Set, Field
from odl.set import LinearSpace, Set, Field
from odl.set.space import LinearSpaceElement
from odl.util import cache_arguments


Expand Down
36 changes: 19 additions & 17 deletions odl/operator/tensor_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ class PointwiseNorm(PointwiseTensorFieldOperator):

"""Take the point-wise norm of a vector field.
This operator takes the (weighted) ``p``-norm
This operator computes the (weighted) p-norm in each point of
a vector field, thus producing a scalar-valued function.
It implements the formulas ::
``||F(x)|| = [ sum_j( w_j * |F_j(x)|^p ) ]^(1/p)``
||F(x)|| = [ sum_j( w_j * |F_j(x)|^p ) ]^(1/p)
for ``p`` finite and
for ``p`` finite and ::
``||F(x)|| = max_j( w_j * |F_j(x)| )``
||F(x)|| = max_j( w_j * |F_j(x)| )
for ``p = inf``, where ``F`` is a vector field. This implies that
the `Operator.domain` is a power space of a discretized function
Expand Down Expand Up @@ -300,9 +302,9 @@ def derivative(self, vf):
The derivative at ``F`` of the point-wise norm operator ``N``
with finite exponent ``p`` and weights ``w`` is the pointwise
inner product with the vector field
inner product with the vector field ::
``x --> N(F)(x)^(1-p) * [ F_j(x) * |F_j(x)|^(p-2) ]_j``.
x --> N(F)(x)^(1-p) * [ F_j(x) * |F_j(x)|^(p-2) ]_j
Note that this is not well-defined for ``F = 0``. If ``p < 2``,
any zero component will result in a singularity.
Expand Down Expand Up @@ -442,9 +444,9 @@ class PointwiseInner(PointwiseInnerBase):

"""Take the point-wise inner product with a given vector field.
This operator takes the (weighted) inner product
This operator takes the (weighted) inner product ::
``<F(x), G(x)> = sum_j ( w_j * F_j(x) * conj(G_j(x)) )``
<F(x), G(x)> = sum_j ( w_j * F_j(x) * conj(G_j(x)) )
for a given vector field ``G``, where ``F`` is the vector field
acting as a variable to this operator.
Expand Down Expand Up @@ -548,15 +550,15 @@ class PointwiseInnerAdjoint(PointwiseInnerBase):

"""Adjoint of the point-wise inner product operator.
The adjoint of the inner product operator is a mapping
The adjoint of the inner product operator is a mapping ::
``A^* : X --> X^d``.
A^* : X --> X^d
If the vector field space ``X^d`` is weighted by a vector ``v``,
the adjoint, applied to a function ``h`` from ``X`` is the vector
field
field ::
``x --> h(x) * (w / v) * G(x)``,
x --> h(x) * (w / v) * G(x),
where ``G`` and ``w`` are the vector field and weighting from the
inner product operator, resp., and all multiplications are understood
Expand All @@ -570,7 +572,7 @@ def __init__(self, sspace, vecfield, vfspace=None, weighting=None):
----------
sspace : `LinearSpace`
"Scalar" space on which the operator acts
vecfield : `range` `element-like`
vecfield : range `element-like`
Vector field of the point-wise inner product operator
vfspace : `ProductSpace`, optional
Space of vector fields to which the operator maps. It must
Expand Down Expand Up @@ -637,9 +639,9 @@ class PointwiseSum(PointwiseInner):

"""Take the point-wise sum of a vector field.
This operator takes the (weighted) sum
This operator takes the (weighted) sum ::
``sum(F(x)) = [ sum_j( w_j * F_j(x) ) ]``
sum(F(x)) = [ sum_j( w_j * F_j(x) ) ]
where ``F`` is a vector field. This implies that
the `Operator.domain` is a power space of a discretized function
Expand Down Expand Up @@ -709,8 +711,8 @@ def __init__(self, matrix, domain=None, range=None, axis=0):
----------
matrix : `array-like` or `scipy.sparse.base.spmatrix`
2-dimensional array representing the linear operator.
For Scipy sparse matrices only rank-1 tensor spaces are
allowed as ``domain``.
For Scipy sparse matrices only tensor spaces with
``ndim == 1`` are allowed as ``domain``.
domain : `TensorSpace`, optional
Space of elements on which the operator can act. Its
``dtype`` must be castable to ``range.dtype``.
Expand Down
26 changes: 7 additions & 19 deletions odl/set/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from odl.set.sets import Field, Set, UniversalSet


__all__ = ('LinearSpace', 'LinearSpaceElement', 'UniversalSpace',
'LinearSpaceTypeError')
__all__ = ('LinearSpace', 'UniversalSpace')


class LinearSpace(Set):
Expand Down Expand Up @@ -421,6 +420,10 @@ def __mul__(self, other):

return ProductSpace(self, other)

def __str__(self):
"""Return ``str(self)``."""
return repr(self)


class LinearSpaceElement(object):

Expand All @@ -436,9 +439,6 @@ def __init__(self, space):
All deriving classes must call this method to set the `space`
property.
"""
if not isinstance(space, LinearSpace):
raise TypeError('`space` {!r} is not a `LinearSpace` instance'
''.format(space))
self.__space = space

@property
Expand Down Expand Up @@ -879,20 +879,8 @@ def __ne__(self, other):
__hash__ = None

def __str__(self):
"""Return ``str(self)``.
This is a default implementation that does not print any
information about the contents of the element.
"""
return str(self.space) + 'Element'

def __repr__(self):
"""Return ``repr(self)``.
This is a default implementation that does not print any
information about the contents of the element.
"""
return repr(self.space) + 'Element'
"""Return ``str(self)``."""
return repr(self)

def __copy__(self):
"""Return a copy of this element.
Expand Down
1 change: 0 additions & 1 deletion odl/solvers/functional/derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def __init__(self, functional, method='forward', step=None):
functional : `Functional`
The functional whose gradient should be computed. Its domain must
be a `TensorSpace`.
be an `FnBase` space.
method : {'backward', 'forward', 'central'}, optional
The method to use to compute the gradient.
step : float, optional
Expand Down
2 changes: 1 addition & 1 deletion odl/solvers/functional/example_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RosenbrockFunctional(Functional):
.. math::
\sum_{i=1}^{n - 1} c (x_{i+1} - x_i^2)^2 + (1 - x_i)^2,
where :math:`c` is a constant usually set to 100 which determines how
where :math:`c` is a constant, usually set to 100, which determines how
"ill-behaved" the function should be.
The global minimum lies at :math:`x = (1, \\dots, 1)`, independent
of :math:`c`.
Expand Down
2 changes: 1 addition & 1 deletion odl/solvers/nonsmooth/proximal_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

from odl.operator import (Operator, IdentityOperator, ScalingOperator,
ConstantOperator, DiagonalOperator)
from odl.set.space import LinearSpaceElement
from odl.space import ProductSpace
from odl.set import LinearSpaceElement
from odl.util import cache_arguments


Expand Down
Loading

0 comments on commit 34c0a26

Please sign in to comment.