Beispiel #1
0
    def __repr__(self):
        """Return ``repr(self)``."""
        weight_str = self.weighting.repr_part
        if self.size == 0:
            posargs = []
            optargs = [('field', self.field, None)]
            oneline = True
        elif self.is_power_space:
            posargs = [self.spaces[0], self.size]
            optargs = []
            oneline = True
        else:
            posargs = self.spaces
            optargs = []
            argstr = ', '.join(repr(s) for s in self.spaces)
            oneline = (len(argstr + weight_str) <= 40
                       and '\n' not in argstr + weight_str)

        if oneline:
            inner_str = signature_string(posargs, optargs, sep=', ', mod='!r')
            if weight_str:
                inner_str = ', '.join([inner_str, weight_str])
            return '{}({})'.format(self.__class__.__name__, inner_str)
        else:
            inner_str = signature_string(posargs, optargs, sep=',\n', mod='!r')
            if weight_str:
                inner_str = ',\n'.join([inner_str, weight_str])
            return '{}(\n{}\n)'.format(self.__class__.__name__,
                                       indent_rows(inner_str))
Beispiel #2
0
    def __repr__(self):
        """Return ``repr(self)``."""
        posargs = [self.motion_partition, self.det_partition]
        optargs = [('det_radius', self.det_radius, -1)]

        if not np.allclose(self.axis, self._default_config['axis']):
            optargs.append(['axis', self.axis.tolist(), None])

        if self._orig_to_det_init_arg is not None:
            optargs.append([
                'orig_to_det_init',
                self._orig_to_det_init_arg.tolist(), None
            ])

        if self._det_axes_init_arg is not None:
            optargs.append([
                'det_axes_init',
                tuple(a.tolist() for a in self._det_axes_init_arg), None
            ])

        if not np.array_equal(self.translation, (0, 0, 0)):
            optargs.append(['translation', self.translation.tolist(), None])

        sig_str = signature_string(posargs, optargs, sep=',\n')
        return '{}(\n{}\n)'.format(self.__class__.__name__,
                                   indent_rows(sig_str))
Beispiel #3
0
    def __repr__(self):
        """Return ``repr(self)``."""
        # Matrix printing itself in an executable way (for dense matrix)
        if self.matrix_issparse:
            # Don't convert to dense, can take forever
            matrix_str = repr(self.matrix)
        else:
            matrix_str = np.array2string(self.matrix, separator=', ')
        posargs = [matrix_str]

        # Optional arguments with defaults, inferred from the matrix
        optargs = []
        # domain
        optargs.append(
            ('domain', self.domain, fn(self.matrix.shape[1],
                                       self.matrix.dtype)))
        # range
        optargs.append(
            ('range', self.range, fn(self.matrix.shape[0], self.matrix.dtype)))

        inner_str = signature_string(posargs,
                                     optargs,
                                     sep=[', ', ', ', ',\n'],
                                     mod=[['!s'], ['!r', '!r']])
        return '{}(\n{}\n)'.format(self.__class__.__name__,
                                   indent_rows(inner_str))
Beispiel #4
0
 def __repr__(self):
     """Return ``repr(self)``."""
     posargs = [self.partition]
     optargs = [('center', self.center.tolist(), None)]
     inner_str = signature_string(posargs, optargs, sep=',\n')
     return '{}(\n{}\n)'.format(self.__class__.__name__,
                                indent_rows(inner_str))
Beispiel #5
0
    def __repr__(self):
        """Return ``repr(self)``."""
        bdry_fracs = np.vstack(self.boundary_cell_fractions)
        default_bdry_fracs = np.all(np.isclose(bdry_fracs, 0.5) |
                                    np.isclose(bdry_fracs, 1.0))

        # Get default shifts of min_pt and max_pt from corresponding
        # grid points
        csizes_l = np.fromiter((s[0] for s in self.cell_sizes_vecs),
                               dtype=float)
        csizes_r = np.fromiter((s[-1] for s in self.cell_sizes_vecs),
                               dtype=float)
        shift_l = ((bdry_fracs[:, 0].astype(float).squeeze() - 0.5) *
                   csizes_l)
        shift_r = ((bdry_fracs[:, 1].astype(float).squeeze() - 0.5) *
                   csizes_r)

        if self.is_uniform and default_bdry_fracs:
            constructor = 'uniform_partition'
            if self.ndim == 1:
                posargs = [self.min_pt[0], self.max_pt[0], self.shape[0]]
            else:
                posargs = [list(self.min_pt), list(self.max_pt), self.shape]

            optargs = [('nodes_on_bdry', self.nodes_on_bdry, False)]

            sig_str = signature_string(posargs, optargs)
            return '{}({})'.format(constructor, sig_str)
        else:
            constructor = 'nonuniform_partition'
            posargs = [list(v) for v in self.coord_vectors]

            optargs = []
            # Defaults with and without nodes_on_bdry option
            nodes_def_min_pt = self.grid.min_pt - shift_l
            nodes_def_max_pt = self.grid.max_pt + shift_r
            def_min_pt = self.grid.min_pt - 0.5 * csizes_l
            def_max_pt = self.grid.max_pt + 0.5 * csizes_r

            # Since min/max_pt and nodes_on_bdry are mutex, we need a
            # couple of cases here
            if (np.allclose(self.min_pt, nodes_def_min_pt) and
                    np.allclose(self.max_pt, nodes_def_max_pt)):
                # Append nodes_on_bdry to list of optional args
                optargs.append(('nodes_on_bdry', self.nodes_on_bdry, False))
            else:
                # Append min/max_pt to list of optional args if not
                # default (need check here because array comparison is
                # ambiguous)
                if not np.allclose(self.min_pt, def_min_pt):
                    p = self.min_pt[0] if self.ndim == 1 else list(self.min_pt)
                    optargs.append((('min_pt', p, None)))
                if not np.allclose(self.max_pt, def_max_pt):
                    p = self.max_pt[0] if self.ndim == 1 else list(self.max_pt)
                    optargs.append((('max_pt', p, None)))

            sig_str = signature_string(posargs, optargs,
                                       sep=[',\n', ', ', ',\n'])
            return '{}(\n{}\n)'.format(constructor, indent_rows(sig_str))
Beispiel #6
0
    def __repr__(self):
        """Return ``repr(self)``."""
        bdry_fracs = np.vstack(self.boundary_cell_fractions)
        default_bdry_fracs = np.all(
            np.isclose(bdry_fracs, 0.5) | np.isclose(bdry_fracs, 1.0))

        # Get default shifts of min_pt and max_pt from corresponding
        # grid points
        csizes_l = np.fromiter((s[0] for s in self.cell_sizes_vecs),
                               dtype=float)
        csizes_r = np.fromiter((s[-1] for s in self.cell_sizes_vecs),
                               dtype=float)
        shift_l = ((bdry_fracs[:, 0].astype(float).squeeze() - 0.5) * csizes_l)
        shift_r = ((bdry_fracs[:, 1].astype(float).squeeze() - 0.5) * csizes_r)

        if self.is_uniform and default_bdry_fracs:
            constructor = 'uniform_partition'
            if self.ndim == 1:
                posargs = [self.min_pt[0], self.max_pt[0], self.shape[0]]
            else:
                posargs = [list(self.min_pt), list(self.max_pt), self.shape]

            optargs = [('nodes_on_bdry', self.nodes_on_bdry, False)]

            sig_str = signature_string(posargs, optargs)
            return '{}({})'.format(constructor, sig_str)
        else:
            constructor = 'nonuniform_partition'
            posargs = [list(v) for v in self.coord_vectors]

            optargs = []
            # Defaults with and without nodes_on_bdry option
            nodes_def_min_pt = self.grid.min_pt - shift_l
            nodes_def_max_pt = self.grid.max_pt + shift_r
            def_min_pt = self.grid.min_pt - 0.5 * csizes_l
            def_max_pt = self.grid.max_pt + 0.5 * csizes_r

            # Since min/max_pt and nodes_on_bdry are mutex, we need a
            # couple of cases here
            if (np.allclose(self.min_pt, nodes_def_min_pt)
                    and np.allclose(self.max_pt, nodes_def_max_pt)):
                # Append nodes_on_bdry to list of optional args
                optargs.append(('nodes_on_bdry', self.nodes_on_bdry, False))
            else:
                # Append min/max_pt to list of optional args if not
                # default (need check here because array comparison is
                # ambiguous)
                if not np.allclose(self.min_pt, def_min_pt):
                    p = self.min_pt[0] if self.ndim == 1 else list(self.min_pt)
                    optargs.append((('min_pt', p, None)))
                if not np.allclose(self.max_pt, def_max_pt):
                    p = self.max_pt[0] if self.ndim == 1 else list(self.max_pt)
                    optargs.append((('max_pt', p, None)))

            sig_str = signature_string(posargs,
                                       optargs,
                                       sep=[',\n', ', ', ',\n'])
            return '{}(\n{}\n)'.format(constructor, indent_rows(sig_str))
Beispiel #7
0
 def __repr__(self):
     """Return ``repr(self)``."""
     posargs = [self.array]
     optargs = [('exponent', self.exponent, 2.0),
                ('dist_using_inner', self.dist_using_inner, False)]
     inner_str = signature_string(posargs,
                                  optargs,
                                  sep=[', ', ', ', ',\n'],
                                  mod=['!r', ''])
     return '{}(\n{}\n)'.format(self.__class__.__name__,
                                indent_rows(inner_str))
Beispiel #8
0
 def __repr__(self):
     """Return ``repr(self)``."""
     if self.is_uniform:
         constructor = 'uniform_grid'
         posargs = [list(self.min_pt), list(self.max_pt), self.shape]
         inner_str = signature_string(posargs, [])
         return '{}({})'.format(constructor, inner_str)
     else:
         constructor = self.__class__.__name__
         posargs = [array1d_repr(v) for v in self.coord_vectors]
         inner_str = signature_string(posargs, [], sep=[',\n', ', ', ', '],
                                      mod=['!s', ''])
         return '{}(\n{}\n)'.format(constructor, indent_rows(inner_str))
Beispiel #9
0
Datei: grid.py Projekt: hmpku/odl
 def __repr__(self):
     """Return ``repr(self)``."""
     if self.is_uniform:
         constructor = 'uniform_grid'
         posargs = [list(self.min_pt), list(self.max_pt), self.shape]
         inner_str = signature_string(posargs, [])
         return '{}({})'.format(constructor, inner_str)
     else:
         constructor = self.__class__.__name__
         posargs = [array1d_repr(v) for v in self.coord_vectors]
         inner_str = signature_string(posargs, [], sep=[',\n', ', ', ', '],
                                      mod=['!s', ''])
         return '{}(\n{}\n)'.format(constructor, indent_rows(inner_str))
Beispiel #10
0
 def __repr__(self):
     """Return ``repr(self)``."""
     posargs = [self.left, self.right]
     inner_str = signature_string(posargs, [], sep=',\n')
     return '{}(\n{}\n)'.format(self.__class__.__name__,
                                indent_rows(inner_str))
Beispiel #11
0
 def __repr__(self):
     """Return ``repr(self)``."""
     posargs = [self.partition, self.axis]
     inner_str = signature_string(posargs, [], sep=[',\n', ', ', ', '])
     return '{}({})'.format(self.__class__.__name__, indent_rows(inner_str))