diff --git a/odl/discr/lp_discr.py b/odl/discr/lp_discr.py index ed4d4d3819e..235f88fff4f 100644 --- a/odl/discr/lp_discr.py +++ b/odl/discr/lp_discr.py @@ -1920,9 +1920,11 @@ def uniform_discr_frompartition(partition, dtype=None, impl='numpy', **kwargs): weighting = kwargs.pop('weighting', None) exponent = kwargs.pop('exponent', 2.0) - if (weighting is None and - is_numeric_dtype(dtype) and - exponent != float('inf')): + if ( + weighting is None and + is_numeric_dtype(dtype) and + exponent not in (float('inf'), -float('inf')) + ): weighting = np.concatenate([np.ones(len(fspace.shape_out)), partition.cell_sides]) diff --git a/odl/space/npy_tensors.py b/odl/space/npy_tensors.py index a2e52a8c654..1ba7b36554c 100644 --- a/odl/space/npy_tensors.py +++ b/odl/space/npy_tensors.py @@ -76,7 +76,7 @@ class NumpyTensorSpace(TensorSpace): """ def __init__(self, shape, dtype=None, **kwargs): - """Initialize a new instance. + r"""Initialize a new instance. Parameters ---------- @@ -165,39 +165,39 @@ def __init__(self, shape, dtype=None, **kwargs): ----- - A distance function or metric on a space :math:`X` is a mapping - :math:`d:X \\times X \\to \mathbb{R}` + :math:`d:X \times X \to \mathbb{R}` satisfying the following conditions for all space elements :math:`x, y, z`: * :math:`d(x, y) \geq 0`, * :math:`d(x, y) = 0 \Leftrightarrow x = y`, * :math:`d(x, y) = d(y, x)`, - * :math:`d(x, y) \\leq d(x, z) + d(z, y)`. + * :math:`d(x, y) \leq d(x, z) + d(z, y)`. - A norm on a space :math:`X` is a mapping - :math:`\| \cdot \|:X \\to \mathbb{R}` + :math:`\| \cdot \|:X \to \mathbb{R}` satisfying the following conditions for all space elements :math:`x, y`: and scalars :math:`s`: * :math:`\| x\| \geq 0`, * :math:`\| x\| = 0 \Leftrightarrow x = 0`, * :math:`\| sx\| = |s| \cdot \| x \|`, - * :math:`\| x+y\| \\leq \| x\| + + * :math:`\| x+y\| \leq \| x\| + \| y\|`. - An inner product on a space :math:`X` over a field :math:`\mathbb{F} = \mathbb{R}` or :math:`\mathbb{C}` is a mapping - :math:`\\langle\cdot, \cdot\\rangle: X \\times - X \\to \mathbb{F}` + :math:`\langle\cdot, \cdot\rangle: X \times + X \to \mathbb{F}` satisfying the following conditions for all space elements :math:`x, y, z`: and scalars :math:`s`: - * :math:`\\langle x, y\\rangle = - \overline{\\langle y, x\\rangle}`, - * :math:`\\langle sx + y, z\\rangle = s \\langle x, z\\rangle + - \\langle y, z\\rangle`, - * :math:`\\langle x, x\\rangle = 0 \Leftrightarrow x = 0`. + * :math:`\langle x, y\rangle = + \overline{\langle y, x\rangle}`, + * :math:`\langle sx + y, z\rangle = s \langle x, z\rangle + + \langle y, z\rangle`, + * :math:`\langle x, x\rangle = 0 \Leftrightarrow x = 0`. Examples -------- @@ -2116,8 +2116,9 @@ def _pnorm_diagweight_impl(x, p, w): # BLAS dot or nrm2 xp = np.abs(x.ravel(order)) if p == float('inf'): - xp *= w.ravel(order) return np.max(xp) + elif p == -float('inf'): + return np.min(xp) else: xp = np.power(xp, p, out=xp) xp *= w.ravel(order) @@ -2242,7 +2243,7 @@ class NumpyTensorSpaceArrayWeighting(ArrayWeighting): """ def __init__(self, array, exponent=2.0): - """Initialize a new instance. + r"""Initialize a new instance. Parameters ---------- @@ -2260,9 +2261,9 @@ def __init__(self, array, exponent=2.0): :math:`W` is defined as .. math:: - \\langle A, B\\rangle_W := - \\langle W \odot A, B\\rangle = - \\langle w \odot a, b\\rangle = + \langle A, B\rangle_W := + \langle W \odot A, B\rangle = + \langle w \odot a, b\rangle = b^{\mathrm{H}} (w \odot a), where :math:`a, b, w` are the "flattened" counterparts of @@ -2270,29 +2271,27 @@ def __init__(self, array, exponent=2.0): stands for transposed complex conjugate and :math:`w \odot a` for element-wise multiplication. - - For other exponents, only norm and dist are defined. In the - case of exponent :math:`\\infty`, the weighted norm is + - For other exponents, only norm and dist are defined. In the case + of finite exponent, it is (using point-wise exponentiation) .. math:: - \| A\|_{W, \\infty} := - \| W \odot A\|_{\\infty} = - \| w \odot a\|_{\\infty}, + \| A\|_{W, p} := + \| W^{1/p} \odot A\|_p = + \| w^{1/p} \odot a\|_p, - otherwise it is (using point-wise exponentiation) + and for :math:`\pm \infty` we have .. math:: - \| A\|_{W, p} := - \| W^{1/p} \odot A\|_{p} = - \| w^{1/p} \odot a\|_{\\infty}. + \| A\|_{W, \pm \infty} := + \| W \odot A\|_{\pm \infty} = + \| w \odot a\|_{\pm \infty}. - - Note that this definition does **not** fulfill the limit - property in :math:`p`, i.e. + Note that this definition is chosen such that the limit + property in :math:`p` holds, i.e. .. math:: - \| A\|_{W, p} \\not\\to - \| A\|_{W, \\infty} \quad (p \\to \\infty) - - unless all weights are equal to 1. + \| A\|_{W, p} \to + \| A\|_{W, \infty} \quad (p \to \infty). - The array :math:`W` may only have positive entries, otherwise it does not define an inner product or norm, respectively. This @@ -2369,7 +2368,7 @@ class NumpyTensorSpacePerAxisWeighting(PerAxisWeighting): """ def __init__(self, factors, exponent=2.0): - """Initialize a new instance. + r"""Initialize a new instance. Parameters ---------- @@ -2396,31 +2395,30 @@ def __init__(self, factors, exponent=2.0): - For exponent 2.0, a new weighted inner product is given as .. math:: - \\langle a, b\\rangle_v := - \\langle v \odot a, b\\rangle = + \langle a, b\rangle_v := + \langle v \odot a, b\rangle = b^{\mathrm{H}} (v \odot a), where :math:`b^{\mathrm{H}}` stands for transposed complex conjugate and ":math:`\odot`" for pointwise product. - - For other exponents, only norm and dist are defined. In the - case of exponent :math:`\\infty`, the weighted norm is defined - as + - For other exponents, only norm and dist are defined. In the case + of finite exponent, it is (using point-wise exponentiation) .. math:: - \| a \|_{v, \\infty} := \| a \|_{\\infty}, + \| a \|_{v, p} := \| v^{1/p} \odot a \|_{p}, - otherwise it is + and for :math:`\pm \infty` we have .. math:: - \| a \|_{v, p} := \| v^{1/p} \odot a \|_{p}. + \| a \|_{v, \pm \infty} := \| a \|_{\pm \infty}, Note that this definition is chosen such that the limit property in :math:`p` holds, i.e. .. math:: - \| a\|_{v, p} \\to - \| a \|_{v, \\infty} \quad (p \\to \\infty). + \| a\|_{v, p} \to + \| a \|_{v, \infty} \quad (p \to \infty). """ # TODO: allow 3-tuples for `bdry, inner, bdry` type factors conv_factors = [] @@ -2635,7 +2633,7 @@ class NumpyTensorSpaceConstWeighting(ConstWeighting): """ def __init__(self, const, exponent=2.0): - """Initialize a new instance. + r"""Initialize a new instance. Parameters ---------- @@ -2651,35 +2649,32 @@ def __init__(self, const, exponent=2.0): :math:`c` is defined as .. math:: - \\langle a, b\\rangle_c := - c \, \\langle a, b\\rangle_c = + \langle a, b\rangle_c := + c \, \langle a, b\rangle_c = c \, b^{\mathrm{H}} a, where :math:`b^{\mathrm{H}}` standing for transposed complex conjugate. - - For other exponents, only norm and dist are defined. In the - case of exponent :math:`\\infty`, the weighted norm is defined - as + - For other exponents, only norm and dist are defined. In the case + of finite exponent, it is .. math:: - \| a \|_{c, \\infty} := - c\, \| a \|_{\\infty}, + \| a \|_{c, p} := + c^{1/p}\, \| a \|_{p}, - otherwise it is + and for :math:`\pm \infty` we have .. math:: - \| a \|_{c, p} := - c^{1/p}\, \| a \|_{p}. + \| a \|_{c, \pm \infty} := + \| a \|_{\pm \infty}. - - Note that this definition does **not** fulfill the limit - property in :math:`p`, i.e. + Note that this definition is chosen such that the limit + property in :math:`p` holds, i.e. .. math:: - \| a\|_{c, p} \\not\\to - \| a \|_{c, \\infty} \quad (p \\to \\infty) - - unless :math:`c = 1`. + \| a\|_{c, p} \to + \| a \|_{c, \infty} \quad (p \to \infty) - The constant must be positive, otherwise it does not define an inner product or norm, respectively.