Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kohr-h committed Apr 2, 2020
1 parent 4668dd5 commit 6323b0b
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 32 deletions.
5 changes: 4 additions & 1 deletion odl/_ufunc/_ufunc_ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2019 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -16,6 +16,7 @@
'negative', 'degrees', 'rad2deg', 'radians', 'deg2rad', 'add', 'subtract'
}


def _ufunc_op_range(domain, nin, nout, types_dict):
"""Infer the range of a ufunc operator."""
if nin == 1:
Expand Down Expand Up @@ -551,3 +552,5 @@ def _call(self, x):
ufunc_funcs = type(
'ufunc_funcs', (object,), {'__getattr__': staticmethod(ufunc_func_cls)}
)()

# TODO(kohr-h): doctest
4 changes: 2 additions & 2 deletions odl/deform/linearized.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ def __init__(self, domain, displacement, interp='linear'):
)

try:
self.__displacement = (self.domain.tangent_bundle).element(
self.__displacement = self.domain.tangent_bundle.element(
displacement
)
except (ValueError, TypeError):
self.__displacement = (self.domain.tangent_bundle).element(
self.__displacement = self.domain.tangent_bundle.element(
[displacement]
)
self.__interp_byaxis = _normalize_interp(interp, domain.ndim)
Expand Down
3 changes: 1 addition & 2 deletions odl/discr/diff_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def _call(self, x, out=None):
if out is None:
out = self.range.element()

# TODO: this pipes CUDA arrays through NumPy. Write native operator.
finite_diff(x, axis=self.axis, dx=self.dx,
method=self.method, pad_mode=self.pad_mode,
pad_const=self.pad_const, out=out)
Expand Down Expand Up @@ -688,7 +687,7 @@ def __init__(self, domain, range=None, pad_mode='constant', pad_const=0):
''.format(pad_mode_in))
if pad_mode in ('order1', 'order1_adjoint',
'order2', 'order2_adjoint'):
# TODO: Add these pad modes
# TODO: add these pad modes
raise ValueError('`pad_mode` {} not implemented for Laplacian.'
''.format(pad_mode_in))

Expand Down
3 changes: 1 addition & 2 deletions odl/discr/discr_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from odl.discr.partition import uniform_partition
from odl.operator import Operator
from odl.space import tensor_space
from odl.util import (
normalized_scalar_param_list, resize_array, safe_int_conv)
from odl.util import normalized_scalar_param_list, resize_array, safe_int_conv
from odl.util.numerics import _SUPPORTED_RESIZE_PAD_MODES

__all__ = ('Resampling', 'ResizingOperator')
Expand Down
18 changes: 11 additions & 7 deletions odl/discr/partition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2018 The ODL contributors
# Copyright 2014-2020 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -14,17 +14,18 @@
of partitions of intervals.
"""

from __future__ import print_function, division, absolute_import
from __future__ import absolute_import, division, print_function

from builtins import object

import numpy as np

from odl.discr.grid import RectGrid, uniform_grid_fromintv
from odl.set import IntervalProd
from odl.util import (
normalized_index_expression, normalized_nodes_on_bdry,
normalized_scalar_param_list, safe_int_conv,
signature_string, indent, array_str, npy_printoptions)

array_str, indent, normalized_index_expression, normalized_nodes_on_bdry,
normalized_scalar_param_list, npy_printoptions, safe_int_conv,
signature_string)

__all__ = ('RectPartition', 'uniform_partition_fromintv',
'uniform_partition_fromgrid', 'uniform_partition',
Expand Down Expand Up @@ -1295,8 +1296,11 @@ def nonuniform_partition(*coord_vecs, **kwargs):
Parameters
----------
coord_vecs1, ... coord_vecsN : `array-like`
coord_vec1, ... coord_vecN : `array-like`
Arrays of coordinates of the mid-points of the partition cells.
Other Parameters
----------------
min_pt, max_pt : float or sequence of floats, optional
Vectors defining the lower/upper limits of the intervals in an
`IntervalProd` (a rectangular box). ``None`` entries mean
Expand Down
11 changes: 6 additions & 5 deletions odl/solvers/functional/default_functionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,16 +1104,14 @@ def __init__(self, space, prior=None):
Examples
--------
Test that KullbackLeibler(x,x) = 0
Test that KullbackLeibler(x, x) = 0
>>> space = odl.rn(3)
>>> prior = 3 * space.one()
>>> func = odl.solvers.KullbackLeibler(space, prior=prior)
>>> func(prior)
0.0
Test that zeros in the prior are handled correctly
>>> prior = space.zero()
Expand Down Expand Up @@ -1152,7 +1150,10 @@ def _call(self, x):
tmp = self.domain.ufuncs.log(x)
tmp += 1
tmp -= x
res = -self.domain.inner(tmp, self.domain.one())
res = self.domain.inner(tmp, self.domain.one())
if res != 0:
# Avoid -0.0
res = -res
else:
# < x - g + xlogy(g, g/x), one >
g = self.prior
Expand All @@ -1164,7 +1165,7 @@ def _call(self, x):
tmp = scipy.special.xlogy(g, g / x)
tmp -= g
tmp += x
res = -self.domain.inner(tmp, self.domain.one())
res = self.domain.inner(tmp, self.domain.one())

if not np.isfinite(res):
# In this case, some element was less than or equal to zero
Expand Down
3 changes: 0 additions & 3 deletions odl/solvers/nonsmooth/douglas_rachford.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ def douglas_rachford_pd(x, f, g, L, niter, tau=None, sigma=None,
else:
dom.assign(z1, x)

f.proximal(tau)(z1, out=p1)
# End of z1 as temporary

f.proximal(tau)(z1, out=p1)
# Now p1 = prox[tau*f](x - tau/2 * sum(Li^* vi))
# Temporary z1 is no longer needed
Expand Down
5 changes: 4 additions & 1 deletion odl/space/npy_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from future.utils import native

import ctypes
import inspect
from builtins import object
from functools import partial

Expand All @@ -20,10 +21,11 @@
from odl.set.sets import ComplexNumbers, RealNumbers
from odl.space.base_tensors import TensorSpace
from odl.util import (
dtype_str, getargspec, is_numeric_dtype, is_real_dtype, signature_string)
dtype_str, is_numeric_dtype, is_real_dtype, signature_string)

__all__ = ('NumpyTensorSpace',)

getargspec = getattr(inspect, "getfullargspec", inspect.getargspec)
_BLAS_DTYPES = (np.dtype('float32'), np.dtype('float64'),
np.dtype('complex64'), np.dtype('complex128'))

Expand Down Expand Up @@ -639,6 +641,7 @@ class NumpyTensorSpaceReduce(object):
def __getattr__(self, name):
"""Return ``self.name``."""
attr = getattr(np, name, None)
attr = getattr(attr, "_implementation", attr) # for numpy >= 1.16
try:
spec = getargspec(attr)
except (ValueError, TypeError):
Expand Down
6 changes: 1 addition & 5 deletions odl/space/pspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@

__all__ = ('ProductSpace',)


try:
getargspec = inspect.getfullargspec
except AttributeError:
getargspec = inspect.getargspec
getargspec = getattr(inspect, "getfullargspec", inspect.getargspec)


class ProductSpace(LinearSpace):
Expand Down
5 changes: 1 addition & 4 deletions odl/test/operator/operator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
from odl.util.testutils import (
all_almost_equal, noise_element, noise_elements, simple_fixture)

try:
getargspec = inspect.getfullargspec
except AttributeError:
getargspec = inspect.getargspec
getargspec = getattr(inspect, "getfullargspec", inspect.getargspec)


# --- Fixtures --- #
Expand Down

0 comments on commit 6323b0b

Please sign in to comment.