예제 #1
0
파일: fspace.py 프로젝트: iceseismic/odl
        def one_vec(x, out=None):
            """The one function, vectorized."""
            if is_valid_input_meshgrid(x, self.domain.ndim):
                order = meshgrid_input_order(x)
            else:
                order = 'C'

            out_shape = out_shape_from_meshgrid(x)
            if out is None:
                return np.ones(out_shape, dtype=dtype, order=order)
            else:
                out.fill(1)
예제 #2
0
def test_meshgrid_input_order():

    # 1d
    x = np.zeros(2)

    mg = sparse_meshgrid(x, order='C')
    assert meshgrid_input_order(mg) == 'C'

    # Both 'C' and 'F' contiguous, defaults to 'C'
    mg = sparse_meshgrid(x, order='F')
    assert meshgrid_input_order(mg) == 'C'

    # 3d
    x, y, z = np.zeros(2), np.zeros(3), np.zeros(4)

    mg = sparse_meshgrid(x, y, z, order='C')
    assert meshgrid_input_order(mg) == 'C'

    mg = sparse_meshgrid(x, y, z, order='F')
    assert meshgrid_input_order(mg) == 'F'

    # 3d, fleshed out meshgrids
    x, y, z = np.zeros(2), np.zeros(3), np.zeros(4)
    mg = np.meshgrid(x, y, z, sparse=False, indexing='ij', copy=True)
    assert meshgrid_input_order(mg) == 'C'

    mg = np.meshgrid(x, y, z, sparse=False, indexing='ij', copy=True)
    mg = [np.asfortranarray(arr) for arr in mg]
    assert meshgrid_input_order(mg) == 'F'

    # non-contiguous --> error
    mg = np.meshgrid(x, y, z, sparse=False, indexing='ij', copy=False)
    with pytest.raises(ValueError):
        meshgrid_input_order(mg)

    # messed up tuple
    mg = list(sparse_meshgrid(x, y, z, order='C'))
    mg[1] = mg[0]
    with pytest.raises(ValueError):
        meshgrid_input_order(mg)
예제 #3
0
파일: domain.py 프로젝트: iceseismic/odl
    def contains_all(self, other):
        """Test if all points defined by ``other`` are contained.

        Parameters
        ----------
        other : object
            Can be a single point, a ``(d, N)`` array where ``d`` is the
            number of dimensions or a length-``d`` meshgrid sequence

        Returns
        -------
        contains : `bool`
            `True` if all points are contained, `False` otherwise

        Examples
        --------
        >>> b, e = [-1, 0, 2], [-0.5, 0, 3]
        >>> rbox = IntervalProd(b, e)
        ...
        ... # Arrays are expected in (ndim, npoints) shape
        >>> arr = np.array([[-1, 0, 2],   # defining one point at a time
        ...                 [-0.5, 0, 2]])
        >>> rbox.contains_all(arr.T)
        True
        >>> # Implicit meshgrids defined by coordinate vectors
        >>> from odl.discr.grid import sparse_meshgrid
        >>> vec1 = (-1, -0.9, -0.7)
        >>> vec2 = (0, 0, 0)
        >>> vec3 = (2.5, 2.75, 3)
        >>> mg = sparse_meshgrid(vec1, vec2, vec3)
        >>> rbox.contains_all(mg)
        True
        """
        if other in self:
            return True
        elif is_valid_input_meshgrid(other, self.ndim):
            order = meshgrid_input_order(other)
            vecs = vecs_from_meshgrid(other, order)
            mins = np.fromiter((np.min(vec) for vec in vecs), dtype=float)
            maxs = np.fromiter((np.max(vec) for vec in vecs), dtype=float)
            return np.all(mins >= self.begin) and np.all(maxs <= self.end)
        elif is_valid_input_array(other, self.ndim):
            if self.ndim == 1:
                mins = np.min(other)
                maxs = np.max(other)
            else:
                mins = np.min(other, axis=1)
                maxs = np.max(other, axis=1)
            return np.all(mins >= self.begin) and np.all(maxs <= self.end)
        else:
            return False