_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q35500 | rotation_matrix_from_to | train | def rotation_matrix_from_to(from_vec, to_vec):
r"""Return a matrix that rotates ``from_vec`` to ``to_vec`` in 2d or 3d.
Since a rotation from one vector to another in 3 dimensions has
(at least) one degree of freedom, this function makes deliberate but
still arbitrary choices to fix these free paramete... | python | {
"resource": ""
} |
q35501 | transform_system | train | def transform_system(principal_vec, principal_default, other_vecs,
matrix=None):
"""Transform vectors with either ``matrix`` or based on ``principal_vec``.
The logic of this function is as follows:
- If ``matrix`` is not ``None``, transform ``principal_vec`` and
all vectors in `... | python | {
"resource": ""
} |
q35502 | perpendicular_vector | train | def perpendicular_vector(vec):
"""Return a vector perpendicular to ``vec``.
Parameters
----------
vec : `array-like`
Vector(s) of arbitrary length. The axis along the vector components
must come last.
Returns
-------
perp_vec : `numpy.ndarray`
Array of same shape as... | python | {
"resource": ""
} |
q35503 | is_inside_bounds | train | def is_inside_bounds(value, params):
"""Return ``True`` if ``value`` is contained in ``params``.
This method supports broadcasting in the sense that for
``params.ndim >= 2``, if more than one value is given, the inputs
are broadcast against each other.
Parameters
----------
value : `array-... | python | {
"resource": ""
} |
q35504 | pyfftw_call | train | def pyfftw_call(array_in, array_out, direction='forward', axes=None,
halfcomplex=False, **kwargs):
"""Calculate the DFT with pyfftw.
The discrete Fourier (forward) transform calcuates the sum::
f_hat[k] = sum_j( f[j] * exp(-2*pi*1j * j*k/N) )
where the summation is taken over all ... | python | {
"resource": ""
} |
q35505 | _pyfftw_destroys_input | train | def _pyfftw_destroys_input(flags, direction, halfcomplex, ndim):
"""Return ``True`` if FFTW destroys an input array, ``False`` otherwise."""
if any(flag in flags or _pyfftw_to_local(flag) in flags
for flag in ('FFTW_MEASURE', 'FFTW_PATIENT', 'FFTW_EXHAUSTIVE',
'FFTW_DESTROY_IN... | python | {
"resource": ""
} |
q35506 | _pyfftw_check_args | train | def _pyfftw_check_args(arr_in, arr_out, axes, halfcomplex, direction):
"""Raise an error if anything is not ok with in and out."""
if len(set(axes)) != len(axes):
raise ValueError('duplicate axes are not allowed')
if direction == 'forward':
out_shape = list(arr_in.shape)
if halfcomp... | python | {
"resource": ""
} |
q35507 | admm_linearized | train | def admm_linearized(x, f, g, L, tau, sigma, niter, **kwargs):
r"""Generic linearized ADMM method for convex problems.
ADMM stands for "Alternating Direction Method of Multipliers" and
is a popular convex optimization method. This variant solves problems
of the form ::
min_x [ f(x) + g(Lx) ]
... | python | {
"resource": ""
} |
q35508 | admm_linearized_simple | train | def admm_linearized_simple(x, f, g, L, tau, sigma, niter, **kwargs):
"""Non-optimized version of ``admm_linearized``.
This function is intended for debugging. It makes a lot of copies and
performs no error checking.
"""
callback = kwargs.pop('callback', None)
z = L.range.zero()
u = L.range.... | python | {
"resource": ""
} |
q35509 | NumericalGradient.derivative | train | def derivative(self, point):
"""Return the derivative in ``point``.
The derivative of the gradient is often called the Hessian.
Parameters
----------
point : `domain` `element-like`
The point that the derivative should be taken in.
Returns
-------
... | python | {
"resource": ""
} |
q35510 | _offset_from_spaces | train | def _offset_from_spaces(dom, ran):
"""Return index offset corresponding to given spaces."""
affected = np.not_equal(dom.shape, ran.shape)
diff_l = np.abs(ran.grid.min() - dom.grid.min())
offset_float = diff_l / dom.cell_sides
offset = np.around(offset_float).astype(int)
for i in range(dom.ndim):... | python | {
"resource": ""
} |
q35511 | Resampling._call | train | def _call(self, x, out=None):
"""Apply resampling operator.
The element ``x`` is resampled using the sampling and interpolation
operators of the underlying spaces.
"""
if out is None:
return x.interpolation
else:
out.sampling(x.interpolation) | python | {
"resource": ""
} |
q35512 | ResizingOperatorBase.axes | train | def axes(self):
"""Dimensions in which an actual resizing is performed."""
return tuple(i for i in range(self.domain.ndim)
if self.domain.shape[i] != self.range.shape[i]) | python | {
"resource": ""
} |
q35513 | ResizingOperator.derivative | train | def derivative(self, point):
"""Derivative of this operator at ``point``.
For the particular case of constant padding with non-zero
constant, the derivative is the corresponding zero-padding
variant. In all other cases, this operator is linear, i.e.
the derivative is equal to ``... | python | {
"resource": ""
} |
q35514 | Strings.contains_all | train | def contains_all(self, other):
"""Return ``True`` if all strings in ``other`` have size `length`."""
dtype = getattr(other, 'dtype', None)
if dtype is None:
dtype = np.result_type(*other)
dtype_str = np.dtype('S{}'.format(self.length))
dtype_uni = np.dtype('<U{}'.form... | python | {
"resource": ""
} |
q35515 | Strings.element | train | def element(self, inp=None):
"""Return an element from ``inp`` or from scratch."""
if inp is not None:
s = str(inp)[:self.length]
s += ' ' * (self.length - len(s))
return s
else:
return ' ' * self.length | python | {
"resource": ""
} |
q35516 | ComplexNumbers.contains_all | train | def contains_all(self, other):
"""Return ``True`` if ``other`` is a sequence of complex numbers."""
dtype = getattr(other, 'dtype', None)
if dtype is None:
dtype = np.result_type(*other)
return is_numeric_dtype(dtype) | python | {
"resource": ""
} |
q35517 | ComplexNumbers.element | train | def element(self, inp=None):
"""Return a complex number from ``inp`` or from scratch."""
if inp is not None:
# Workaround for missing __complex__ of numpy.ndarray
# for Numpy version < 1.12
# TODO: remove when Numpy >= 1.12 is required
if isinstance(inp, n... | python | {
"resource": ""
} |
q35518 | RealNumbers.contains_set | train | def contains_set(self, other):
"""Return ``True`` if ``other`` is a subset of the real numbers.
Returns
-------
contained : bool
``True`` if other is an instance of `RealNumbers` or
`Integers` False otherwise.
Examples
--------
>>> real_n... | python | {
"resource": ""
} |
q35519 | RealNumbers.contains_all | train | def contains_all(self, array):
"""Test if `array` is an array of real numbers."""
dtype = getattr(array, 'dtype', None)
if dtype is None:
dtype = np.result_type(*array)
return is_real_dtype(dtype) | python | {
"resource": ""
} |
q35520 | Integers.contains_all | train | def contains_all(self, other):
"""Return ``True`` if ``other`` is a sequence of integers."""
dtype = getattr(other, 'dtype', None)
if dtype is None:
dtype = np.result_type(*other)
return is_int_dtype(dtype) | python | {
"resource": ""
} |
q35521 | CartesianProduct.element | train | def element(self, inp=None):
"""Create a `CartesianProduct` element.
Parameters
----------
inp : iterable, optional
Collection of input values for the
`LinearSpace.element` methods
of all sets in the Cartesian product.
Returns
-------... | python | {
"resource": ""
} |
q35522 | DiscreteFourierTransformBase.adjoint | train | def adjoint(self):
"""Adjoint transform, equal to the inverse.
See Also
--------
inverse
"""
if self.domain.exponent == 2.0 and self.range.exponent == 2.0:
return self.inverse
else:
raise NotImplementedError(
'no adjoint de... | python | {
"resource": ""
} |
q35523 | FourierTransformBase.create_temporaries | train | def create_temporaries(self, r=True, f=True):
"""Allocate and store reusable temporaries.
Existing temporaries are overridden.
Parameters
----------
r : bool, optional
Create temporary for the real space
f : bool, optional
Create temporary for th... | python | {
"resource": ""
} |
q35524 | FourierTransform._preprocess | train | def _preprocess(self, x, out=None):
"""Return the pre-processed version of ``x``.
C2C: use ``tmp_r`` or ``tmp_f`` (C2C operation)
R2C: use ``tmp_f`` (R2C operation)
HALFC: use ``tmp_r`` (R2R operation)
The result is stored in ``out`` if given, otherwise in
a temporary o... | python | {
"resource": ""
} |
q35525 | FourierTransformInverse.inverse | train | def inverse(self):
"""Inverse of the inverse, the forward FT."""
sign = '+' if self.sign == '-' else '-'
return FourierTransform(
domain=self.range, range=self.domain, impl=self.impl,
axes=self.axes, halfcomplex=self.halfcomplex, shift=self.shifts,
sign=sign, ... | python | {
"resource": ""
} |
q35526 | moveaxis | train | def moveaxis(a, source, destination):
"""Move axes of an array to new positions.
Other axes remain in their original order.
This function is a backport of `numpy.moveaxis` introduced in
NumPy 1.11.
See Also
--------
numpy.moveaxis
"""
import numpy
if hasattr(numpy, 'moveaxis')... | python | {
"resource": ""
} |
q35527 | flip | train | def flip(a, axis):
"""Reverse the order of elements in an array along the given axis.
This function is a backport of `numpy.flip` introduced in NumPy 1.12.
See Also
--------
numpy.flip
"""
if not hasattr(a, 'ndim'):
a = np.asarray(a)
indexer = [slice(None)] * a.ndim
try:
... | python | {
"resource": ""
} |
q35528 | _read_projections | train | def _read_projections(folder, indices):
"""Read mayo projections from a folder."""
datasets = []
# Get the relevant file names
file_names = sorted([f for f in os.listdir(folder) if f.endswith(".dcm")])
if len(file_names) == 0:
raise ValueError('No DICOM files found in {}'.format(folder))
... | python | {
"resource": ""
} |
q35529 | load_projections | train | def load_projections(folder, indices=None):
"""Load geometry and data stored in Mayo format from folder.
Parameters
----------
folder : str
Path to the folder where the Mayo DICOM files are stored.
indices : optional
Indices of the projections to load.
Accepts advanced index... | python | {
"resource": ""
} |
q35530 | load_reconstruction | train | def load_reconstruction(folder, slice_start=0, slice_end=-1):
"""Load a volume from folder, also returns the corresponding partition.
Parameters
----------
folder : str
Path to the folder where the DICOM files are stored.
slice_start : int
Index of the first slice to use. Used for s... | python | {
"resource": ""
} |
q35531 | newtons_method | train | def newtons_method(f, x, line_search=1.0, maxiter=1000, tol=1e-16,
cg_iter=None, callback=None):
r"""Newton's method for minimizing a functional.
Notes
-----
This is a general and optimized implementation of Newton's method
for solving the problem:
.. math::
\min f(x... | python | {
"resource": ""
} |
q35532 | bfgs_method | train | def bfgs_method(f, x, line_search=1.0, maxiter=1000, tol=1e-15, num_store=None,
hessinv_estimate=None, callback=None):
r"""Quasi-Newton BFGS method to minimize a differentiable function.
Can use either the regular BFGS method, or the limited memory BFGS method.
Notes
-----
This is ... | python | {
"resource": ""
} |
q35533 | broydens_method | train | def broydens_method(f, x, line_search=1.0, impl='first', maxiter=1000,
tol=1e-15, hessinv_estimate=None,
callback=None):
r"""Broyden's first method, a quasi-Newton scheme.
Notes
-----
This is a general and optimized implementation of Broyden's method,
a quasi... | python | {
"resource": ""
} |
q35534 | _axis_in_detector | train | def _axis_in_detector(geometry):
"""A vector in the detector plane that points along the rotation axis."""
du, dv = geometry.det_axes_init
axis = geometry.axis
c = np.array([np.vdot(axis, du), np.vdot(axis, dv)])
cnorm = np.linalg.norm(c)
# Check for numerical errors
assert cnorm != 0
... | python | {
"resource": ""
} |
q35535 | _rotation_direction_in_detector | train | def _rotation_direction_in_detector(geometry):
"""A vector in the detector plane that points in the rotation direction."""
du, dv = geometry.det_axes_init
axis = geometry.axis
det_normal = np.cross(dv, du)
rot_dir = np.cross(axis, det_normal)
c = np.array([np.vdot(rot_dir, du), np.vdot(rot_dir, ... | python | {
"resource": ""
} |
q35536 | _fbp_filter | train | def _fbp_filter(norm_freq, filter_type, frequency_scaling):
"""Create a smoothing filter for FBP.
Parameters
----------
norm_freq : `array-like`
Frequencies normalized to lie in the interval [0, 1].
filter_type : {'Ram-Lak', 'Shepp-Logan', 'Cosine', 'Hamming', 'Hann',
cal... | python | {
"resource": ""
} |
q35537 | tam_danielson_window | train | def tam_danielson_window(ray_trafo, smoothing_width=0.05, n_pi=1):
"""Create Tam-Danielson window from a `RayTransform`.
The Tam-Danielson window is an indicator function on the minimal set of
data needed to reconstruct a volume from given data. It is useful in
analytic reconstruction methods such as F... | python | {
"resource": ""
} |
q35538 | parker_weighting | train | def parker_weighting(ray_trafo, q=0.25):
"""Create parker weighting for a `RayTransform`.
Parker weighting is a weighting function that ensures that oversampled
fan/cone beam data are weighted such that each line has unit weight. It is
useful in analytic reconstruction methods such as FBP to give a mor... | python | {
"resource": ""
} |
q35539 | fbp_op | train | def fbp_op(ray_trafo, padding=True, filter_type='Ram-Lak',
frequency_scaling=1.0):
"""Create filtered back-projection operator from a `RayTransform`.
The filtered back-projection is an approximate inverse to the ray
transform.
Parameters
----------
ray_trafo : `RayTransform`
... | python | {
"resource": ""
} |
q35540 | walnut_data | train | def walnut_data():
"""Tomographic X-ray data of a walnut.
Notes
-----
See the article `Tomographic X-ray data of a walnut`_ for further
information.
See Also
--------
walnut_geometry
References
----------
.. _Tomographic X-ray data of a walnut: https://arxiv.org/abs/1502.0... | python | {
"resource": ""
} |
q35541 | lotus_root_data | train | def lotus_root_data():
"""Tomographic X-ray data of a lotus root.
Notes
-----
See the article `Tomographic X-ray data of a lotus root filled with
attenuating objects`_ for further information.
See Also
--------
lotus_root_geometry
References
----------
.. _Tomographic X-ra... | python | {
"resource": ""
} |
q35542 | lotus_root_geometry | train | def lotus_root_geometry():
"""Tomographic geometry for the lotus root dataset.
Notes
-----
See the article `Tomographic X-ray data of a lotus root filled with
attenuating objects`_ for further information.
See Also
--------
lotus_root_geometry
References
----------
.. _Tom... | python | {
"resource": ""
} |
q35543 | poisson_noise | train | def poisson_noise(intensity, seed=None):
r"""Poisson distributed noise with given intensity.
Parameters
----------
intensity : `TensorSpace` or `ProductSpace` element
The intensity (usually called lambda) parameter of the noise.
Returns
-------
poisson_noise : ``intensity.space`` e... | python | {
"resource": ""
} |
q35544 | salt_pepper_noise | train | def salt_pepper_noise(vector, fraction=0.05, salt_vs_pepper=0.5,
low_val=None, high_val=None, seed=None):
"""Add salt and pepper noise to vector.
Salt and pepper noise replaces random elements in ``vector`` with
``low_val`` or ``high_val``.
Parameters
----------
vector : ... | python | {
"resource": ""
} |
q35545 | uniform_partition_fromintv | train | def uniform_partition_fromintv(intv_prod, shape, nodes_on_bdry=False):
"""Return a partition of an interval product into equally sized cells.
Parameters
----------
intv_prod : `IntervalProd`
Interval product to be partitioned
shape : int or sequence of ints
Number of nodes per axis.... | python | {
"resource": ""
} |
q35546 | uniform_partition_fromgrid | train | def uniform_partition_fromgrid(grid, min_pt=None, max_pt=None):
"""Return a partition of an interval product based on a given grid.
This method is complementary to `uniform_partition_fromintv` in that
it infers the set to be partitioned from a given grid and optional
parameters for ``min_pt`` and ``max... | python | {
"resource": ""
} |
q35547 | uniform_partition | train | def uniform_partition(min_pt=None, max_pt=None, shape=None, cell_sides=None,
nodes_on_bdry=False):
"""Return a partition with equally sized cells.
Parameters
----------
min_pt, max_pt : float or sequence of float, optional
Vectors defining the lower/upper limits of the int... | python | {
"resource": ""
} |
q35548 | nonuniform_partition | train | def nonuniform_partition(*coord_vecs, **kwargs):
"""Return a partition with un-equally sized cells.
Parameters
----------
coord_vecs1, ... coord_vecsN : `array-like`
Arrays of coordinates of the mid-points of the partition cells.
min_pt, max_pt : float or sequence of floats, optional
... | python | {
"resource": ""
} |
q35549 | RectPartition.nodes_on_bdry | train | def nodes_on_bdry(self):
"""Encoding of grid points lying on the boundary.
Examples
--------
Using global option (default ``False``):
>>> part = odl.nonuniform_partition([0, 2, 3], [1, 3])
>>> part.nodes_on_bdry
False
>>> part = odl.nonuniform_partition(... | python | {
"resource": ""
} |
q35550 | RectPartition.has_isotropic_cells | train | def has_isotropic_cells(self):
"""``True`` if `grid` is uniform and `cell_sides` are all equal.
Always ``True`` for 1D partitions.
Examples
--------
>>> part = uniform_partition([0, -1], [1, 1], (5, 10))
>>> part.has_isotropic_cells
True
>>> part = unifo... | python | {
"resource": ""
} |
q35551 | RectPartition.boundary_cell_fractions | train | def boundary_cell_fractions(self):
"""Return a tuple of contained fractions of boundary cells.
Since the outermost grid points can have any distance to the
boundary of the partitioned set, the "natural" outermost cell
around these points can either be cropped or extended. This
p... | python | {
"resource": ""
} |
q35552 | RectPartition.cell_sizes_vecs | train | def cell_sizes_vecs(self):
"""Return the cell sizes as coordinate vectors.
Returns
-------
csizes : tuple of `numpy.ndarray`'s
The cell sizes per axis. The length of the vectors is the
same as the corresponding ``grid.coord_vectors``.
For axes with 1 ... | python | {
"resource": ""
} |
q35553 | RectPartition.cell_sides | train | def cell_sides(self):
"""Side lengths of all 'inner' cells of a uniform partition.
Only defined if ``self.grid`` is uniform.
Examples
--------
We create a partition of the rectangle [0, 1] x [-1, 2] into
3 x 3 cells, where the grid points lie on the boundary. This
... | python | {
"resource": ""
} |
q35554 | RectPartition.approx_equals | train | def approx_equals(self, other, atol):
"""Return ``True`` in case of approximate equality.
Returns
-------
approx_eq : bool
``True`` if ``other`` is a `RectPartition` instance with
``self.set == other.set`` up to ``atol`` and
``self.grid == other.other... | python | {
"resource": ""
} |
q35555 | RectPartition.insert | train | def insert(self, index, *parts):
"""Return a copy with ``parts`` inserted before ``index``.
The given partitions are inserted (as a block) into ``self``,
yielding a new partition whose number of dimensions is the sum of
the numbers of dimensions of all involved partitions.
Note ... | python | {
"resource": ""
} |
q35556 | RectPartition.index | train | def index(self, value, floating=False):
"""Return the index of a value in the domain.
Parameters
----------
value : ``self.set`` element
Point whose index to find.
floating : bool, optional
If True, then the index should also give the position inside the
... | python | {
"resource": ""
} |
q35557 | RectPartition.byaxis | train | def byaxis(self):
"""Object to index ``self`` along axes.
Examples
--------
Indexing with integers or slices:
>>> p = odl.uniform_partition([0, 1, 2], [1, 3, 5], (3, 5, 6))
>>> p.byaxis[0]
uniform_partition(0.0, 1.0, 3)
>>> p.byaxis[1]
uniform_pa... | python | {
"resource": ""
} |
q35558 | DivergentBeamGeometry.det_to_src | train | def det_to_src(self, angle, dparam, normalized=True):
"""Vector or direction from a detector location to the source.
The unnormalized version of this vector is computed as follows::
vec = src_position(angle) - det_point_position(angle, dparam)
Parameters
----------
... | python | {
"resource": ""
} |
q35559 | AxisOrientedGeometry.rotation_matrix | train | def rotation_matrix(self, angle):
"""Return the rotation matrix to the system state at ``angle``.
The matrix is computed according to
`Rodrigues' rotation formula
<https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula>`_.
Parameters
----------
angle : float ... | python | {
"resource": ""
} |
q35560 | elekta_icon_geometry | train | def elekta_icon_geometry(sad=780.0, sdd=1000.0,
piercing_point=(390.0, 0.0),
angles=None, num_angles=None,
detector_shape=(780, 720)):
"""Tomographic geometry of the Elekta Icon CBCT system.
See the [whitepaper]_ for specific descriptio... | python | {
"resource": ""
} |
q35561 | elekta_icon_space | train | def elekta_icon_space(shape=(448, 448, 448), **kwargs):
"""Default reconstruction space for the Elekta Icon CBCT.
See the [whitepaper]_ for further information.
Parameters
----------
shape : sequence of int, optional
Shape of the space, in voxels.
kwargs :
Keyword arguments to ... | python | {
"resource": ""
} |
q35562 | elekta_icon_fbp | train | def elekta_icon_fbp(ray_transform,
padding=False, filter_type='Hann', frequency_scaling=0.6,
parker_weighting=True):
"""Approximation of the FDK reconstruction used in the Elekta Icon.
Parameters
----------
ray_transform : `RayTransform`
The ray transform... | python | {
"resource": ""
} |
q35563 | elekta_xvi_space | train | def elekta_xvi_space(shape=(512, 512, 512), **kwargs):
"""Default reconstruction space for the Elekta XVI CBCT.
Parameters
----------
shape : sequence of int, optional
Shape of the space, in voxels.
kwargs :
Keyword arguments to pass to `uniform_discr` to modify the space, e.g.
... | python | {
"resource": ""
} |
q35564 | elekta_xvi_fbp | train | def elekta_xvi_fbp(ray_transform,
padding=False, filter_type='Hann', frequency_scaling=0.6):
"""Approximation of the FDK reconstruction used in the Elekta XVI.
Parameters
----------
ray_transform : `RayTransform`
The ray transform to be used, should have an Elekta XVI geometr... | python | {
"resource": ""
} |
q35565 | _modified_shepp_logan_ellipsoids | train | def _modified_shepp_logan_ellipsoids(ellipsoids):
"""Modify ellipsoids to give the modified Shepp-Logan phantom.
Works for both 2d and 3d.
"""
intensities = [1.0, -0.8, -0.2, -0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
# Add minimal numbers to ensure that the result is nowhere negative.
# This is need... | python | {
"resource": ""
} |
q35566 | shepp_logan_ellipsoids | train | def shepp_logan_ellipsoids(ndim, modified=False):
"""Ellipsoids for the standard Shepp-Logan phantom in 2 or 3 dimensions.
Parameters
----------
ndim : {2, 3}
Dimension of the space the ellipsoids should be in.
modified : bool, optional
True if the modified Shepp-Logan phantom shoul... | python | {
"resource": ""
} |
q35567 | shepp_logan | train | def shepp_logan(space, modified=False, min_pt=None, max_pt=None):
"""Standard Shepp-Logan phantom in 2 or 3 dimensions.
Parameters
----------
space : `DiscreteLp`
Space in which the phantom is created, must be 2- or 3-dimensional.
If ``space.shape`` is 1 in an axis, a corresponding slic... | python | {
"resource": ""
} |
q35568 | _scaling_func_list | train | def _scaling_func_list(bdry_fracs, exponent):
"""Return a list of lists of scaling functions for the boundary."""
def scaling(factor):
def scaling_func(x):
return x * factor
return scaling_func
func_list = []
for frac_l, frac_r in bdry_fracs:
func_list_entry = []
... | python | {
"resource": ""
} |
q35569 | DiscreteLp.interp | train | def interp(self):
"""Interpolation type of this discretization."""
if self.ndim == 0:
return 'nearest'
elif all(interp == self.interp_byaxis[0]
for interp in self.interp_byaxis):
return self.interp_byaxis[0]
else:
return self.interp_by... | python | {
"resource": ""
} |
q35570 | DiscreteLp.tangent_bundle | train | def tangent_bundle(self):
"""The tangent bundle associated with `domain` using `partition`.
The tangent bundle of a space ``X`` of functions ``R^d --> F`` can be
interpreted as the space of vector-valued functions ``R^d --> F^d``.
This space can be identified with the power space ``X^d`... | python | {
"resource": ""
} |
q35571 | DiscreteLp.is_uniformly_weighted | train | def is_uniformly_weighted(self):
"""``True`` if the weighting is the same for all space points."""
try:
is_uniformly_weighted = self.__is_uniformly_weighted
except AttributeError:
bdry_fracs = self.partition.boundary_cell_fractions
is_uniformly_weighted = (
... | python | {
"resource": ""
} |
q35572 | DiscreteLpElement.imag | train | def imag(self, newimag):
"""Set the imaginary part of this element to ``newimag``.
This method is invoked by ``x.imag = other``.
Parameters
----------
newimag : array-like or scalar
Values to be assigned to the imaginary part of this element.
Raises
... | python | {
"resource": ""
} |
q35573 | DiscreteLpElement.conj | train | def conj(self, out=None):
"""Complex conjugate of this element.
Parameters
----------
out : `DiscreteLpElement`, optional
Element to which the complex conjugate is written.
Must be an element of this element's space.
Returns
-------
out :... | python | {
"resource": ""
} |
q35574 | _operator_norms | train | def _operator_norms(L):
"""Get operator norms if needed.
Parameters
----------
L : sequence of `Operator` or float
The operators or the norms of the operators that are used in the
`douglas_rachford_pd` method. For `Operator` entries, the norm
is computed with ``Operator.norm(est... | python | {
"resource": ""
} |
q35575 | douglas_rachford_pd_stepsize | train | def douglas_rachford_pd_stepsize(L, tau=None, sigma=None):
r"""Default step sizes for `douglas_rachford_pd`.
Parameters
----------
L : sequence of `Operator` or float
The operators or the norms of the operators that are used in the
`douglas_rachford_pd` method. For `Operator` entries, t... | python | {
"resource": ""
} |
q35576 | parallel_beam_geometry | train | def parallel_beam_geometry(space, num_angles=None, det_shape=None):
r"""Create default parallel beam geometry from ``space``.
This is intended for simple test cases where users do not need the full
flexibility of the geometries, but simply want a geometry that works.
This default geometry gives a full... | python | {
"resource": ""
} |
q35577 | ParallelBeamGeometry.angles | train | def angles(self):
"""All angles of this geometry as an array.
If ``motion_params.ndim == 1``, the array has shape ``(N,)``,
where ``N`` is the number of angles.
Otherwise, the array shape is ``(ndim, N)``, where ``N`` is the
total number of angles, and ``ndim`` is ``motion_parti... | python | {
"resource": ""
} |
q35578 | ParallelBeamGeometry.det_to_src | train | def det_to_src(self, angle, dparam):
"""Direction from a detector location to the source.
The direction vector is computed as follows::
dir = rotation_matrix(angle).dot(detector.surface_normal(dparam))
Note that for flat detectors, ``surface_normal`` does not depend
on the... | python | {
"resource": ""
} |
q35579 | Parallel2dGeometry.frommatrix | train | def frommatrix(cls, apart, dpart, init_matrix, **kwargs):
"""Create an instance of `Parallel2dGeometry` using a matrix.
This alternative constructor uses a matrix to rotate and
translate the default configuration. It is most useful when
the transformation to be applied is already given ... | python | {
"resource": ""
} |
q35580 | Parallel3dEulerGeometry.det_axes | train | def det_axes(self, angles):
"""Return the detector axes tuple at ``angles``.
Parameters
----------
angles : `array-like` or sequence
Euler angles in radians describing the rotation of the detector.
The length of the provided argument (along the first axis in
... | python | {
"resource": ""
} |
q35581 | Parallel3dEulerGeometry.rotation_matrix | train | def rotation_matrix(self, angles):
"""Return the rotation matrix to the system state at ``angles``.
Parameters
----------
angles : `array-like` or sequence
Euler angles in radians describing the rotation of the detector.
The length of the provided argument (along... | python | {
"resource": ""
} |
q35582 | Parallel3dAxisGeometry.frommatrix | train | def frommatrix(cls, apart, dpart, init_matrix, **kwargs):
"""Create an instance of `Parallel3dAxisGeometry` using a matrix.
This alternative constructor uses a matrix to rotate and
translate the default configuration. It is most useful when
the transformation to be applied is already gi... | python | {
"resource": ""
} |
q35583 | wrap_ufunc_base | train | def wrap_ufunc_base(name, n_in, n_out, doc):
"""Return ufunc wrapper for implementation-agnostic ufunc classes."""
ufunc = getattr(np, name)
if n_in == 1:
if n_out == 1:
def wrapper(self, out=None, **kwargs):
if out is None or isinstance(out, (type(self.elem),
... | python | {
"resource": ""
} |
q35584 | wrap_ufunc_productspace | train | def wrap_ufunc_productspace(name, n_in, n_out, doc):
"""Return ufunc wrapper for `ProductSpaceUfuncs`."""
if n_in == 1:
if n_out == 1:
def wrapper(self, out=None, **kwargs):
if out is None:
result = [getattr(x.ufuncs, name)(**kwargs)
... | python | {
"resource": ""
} |
q35585 | landweber | train | def landweber(op, x, rhs, niter, omega=None, projection=None, callback=None):
r"""Optimized implementation of Landweber's method.
Solves the inverse problem::
A(x) = rhs
Parameters
----------
op : `Operator`
Operator in the inverse problem. ``op.derivative(x).adjoint`` must be
... | python | {
"resource": ""
} |
q35586 | conjugate_gradient | train | def conjugate_gradient(op, x, rhs, niter, callback=None):
"""Optimized implementation of CG for self-adjoint operators.
This method solves the inverse problem (of the first kind)::
A(x) = y
for a linear and self-adjoint `Operator` ``A``.
It uses a minimum amount of memory copies by applying ... | python | {
"resource": ""
} |
q35587 | conjugate_gradient_normal | train | def conjugate_gradient_normal(op, x, rhs, niter=1, callback=None):
"""Optimized implementation of CG for the normal equation.
This method solves the inverse problem (of the first kind) ::
A(x) == rhs
with a linear `Operator` ``A`` by looking at the normal equation ::
A.adjoint(A(x)) == A... | python | {
"resource": ""
} |
q35588 | gauss_newton | train | def gauss_newton(op, x, rhs, niter, zero_seq=exp_zero_seq(2.0),
callback=None):
"""Optimized implementation of a Gauss-Newton method.
This method solves the inverse problem (of the first kind)::
A(x) = y
for a (Frechet-) differentiable `Operator` ``A`` using a
Gauss-Newton it... | python | {
"resource": ""
} |
q35589 | kaczmarz | train | def kaczmarz(ops, x, rhs, niter, omega=1, projection=None, random=False,
callback=None, callback_loop='outer'):
r"""Optimized implementation of Kaczmarz's method.
Solves the inverse problem given by the set of equations::
A_n(x) = rhs_n
This is also known as the Landweber-Kaczmarz's ... | python | {
"resource": ""
} |
q35590 | conjugate_gradient_nonlinear | train | def conjugate_gradient_nonlinear(f, x, line_search=1.0, maxiter=1000, nreset=0,
tol=1e-16, beta_method='FR',
callback=None):
r"""Conjugate gradient for nonlinear problems.
Parameters
----------
f : `Functional`
Functional with ``... | python | {
"resource": ""
} |
q35591 | tspace_type | train | def tspace_type(space, impl, dtype=None):
"""Select the correct corresponding tensor space.
Parameters
----------
space : `LinearSpace`
Template space from which to infer an adequate tensor space. If
it has a ``field`` attribute, ``dtype`` must be consistent with it.
impl : string
... | python | {
"resource": ""
} |
q35592 | DiscretizedSpace._lincomb | train | def _lincomb(self, a, x1, b, x2, out):
"""Raw linear combination."""
self.tspace._lincomb(a, x1.tensor, b, x2.tensor, out.tensor) | python | {
"resource": ""
} |
q35593 | DiscretizedSpace._dist | train | def _dist(self, x1, x2):
"""Raw distance between two elements."""
return self.tspace._dist(x1.tensor, x2.tensor) | python | {
"resource": ""
} |
q35594 | DiscretizedSpace._inner | train | def _inner(self, x1, x2):
"""Raw inner product of two elements."""
return self.tspace._inner(x1.tensor, x2.tensor) | python | {
"resource": ""
} |
q35595 | DiscretizedSpaceElement.sampling | train | def sampling(self, ufunc, **kwargs):
"""Sample a continuous function and assign to this element.
Parameters
----------
ufunc : ``self.space.fspace`` element
The continuous function that should be samplingicted.
kwargs :
Additional arugments for the sampli... | python | {
"resource": ""
} |
q35596 | _normalize_sampling_points | train | def _normalize_sampling_points(sampling_points, ndim):
"""Normalize points to an ndim-long list of linear index arrays.
This helper converts sampling indices for `SamplingOperator` from
integers or array-like objects to a list of length ``ndim``, where
each entry is a `numpy.ndarray` with ``dtype=int``... | python | {
"resource": ""
} |
q35597 | PointwiseNorm.derivative | train | def derivative(self, vf):
"""Derivative of the point-wise norm operator at ``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 ::
x --> N(F)(x)^(1-p) * [ F_j(... | python | {
"resource": ""
} |
q35598 | MatrixOperator.adjoint | train | def adjoint(self):
"""Adjoint operator represented by the adjoint matrix.
Returns
-------
adjoint : `MatrixOperator`
"""
return MatrixOperator(self.matrix.conj().T,
domain=self.range, range=self.domain,
axis=sel... | python | {
"resource": ""
} |
q35599 | MatrixOperator.inverse | train | def inverse(self):
"""Inverse operator represented by the inverse matrix.
Taking the inverse causes sparse matrices to become dense and is
generally very heavy computationally since the matrix is inverted
numerically (an O(n^3) operation). It is recommended to instead
use one of... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.