Exemplo n.º 1
0
 def __new__(cls, *args, **hints):
     if not len(args) == 6:
         raise ValueError('6 parameters expected, got %s' % args)
     evaluate = hints.get('evaluate', False)
     if evaluate:
         return AtomicExpr.__new__(cls, *args)._eval_wignerd()
     return AtomicExpr.__new__(cls, *args, **{'evaluate': False})
Exemplo n.º 2
0
 def __new__(cls, *args, **hints):
     if not len(args) == 6:
         raise ValueError("6 parameters expected, got %s" % args)
     evaluate = hints.get("evaluate", False)
     if evaluate:
         return AtomicExpr.__new__(cls, *args)._eval_wignerd()
     return AtomicExpr.__new__(cls, *args, **{"evaluate": False})
Exemplo n.º 3
0
    def __new__(cls, name, dimension, scale_factor=S.One, abbrev=None, **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        if not isinstance(dimension, dimensions.Dimension):
            if dimension == 1:
                dimension = Dimension(1)
            else:
                raise ValueError("expected dimension or 1")
        scale_factor = sympify(scale_factor)

        dimex = Quantity.get_dimensional_expr(scale_factor)
        if dimex != 1:
            if dimension != Dimension(dimex):
                raise ValueError("quantity value and dimension mismatch")

        # replace all prefixes by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Prefix), lambda x: x.scale_factor)
        # replace all quantities by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Quantity), lambda x: x.scale_factor)

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, dimension, scale_factor, abbrev)
        obj._name = name
        obj._dimension = dimension
        obj._scale_factor = scale_factor
        obj._abbrev = abbrev
        return obj
Exemplo n.º 4
0
    def __new__(cls, name, dimension, scale_factor=S.One, abbrev=None, **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        if not isinstance(dimension, dimensions.Dimension):
            if dimension == 1:
                dimension = Dimension(1)
            else:
                raise ValueError("expected dimension or 1")
        scale_factor = sympify(scale_factor)

        dimex = Quantity.get_dimensional_expr(scale_factor)
        if dimex != 1:
            if dimension != Dimension(dimex):
                raise ValueError("quantity value and dimension mismatch")

        # replace all prefixes by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Prefix), lambda x: x.scale_factor)
        # replace all quantities by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Quantity), lambda x: x.scale_factor)

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, dimension, scale_factor, abbrev)
        obj._name = name
        obj._dimension = dimension
        obj._scale_factor = scale_factor
        obj._abbrev = abbrev
        return obj
Exemplo n.º 5
0
    def __new__(cls, value, name, latex="", pretty=""):
        """
        Parameters
        ----------
            value : float
                The numerical value of the constant
            name : string
                Used to render the symbol when calling print()
            latex (optional) : string
                Latex code representing representing this constant. If not
                provided, `name` will be used instead.
            pretty (optional) : string
                Used to render the symbol when calling pprint(). Unicode strings
                are admissible. If not provided, `name` will be used instead.
        """
        if isinstance(value, Integer):
            value = value.p
        if not isinstance(value, (int, float)):
            raise TypeError("'value' must be a Python's int or float. \n" +
                            "Instead, got {}".format(type(value)))
        if not all([isinstance(a, str) for a in [name, latex, pretty]]):
            raise TypeError(
                "Parameters name, latex, pretty must be of type string")

        obj = AtomicExpr.__new__(cls)
        obj._value = value
        obj._name = name
        obj._latex_str = latex
        obj._pretty_str = pretty
        return obj
Exemplo n.º 6
0
    def __new__(cls,
                name,
                abbrev=None,
                dimension=None,
                scale_factor=None,
                latex_repr=None,
                pretty_unicode_repr=None,
                pretty_ascii_repr=None,
                mathml_presentation_repr=None,
                **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        # For Quantity(name, dim, scale, abbrev) to work like in the
        # old version of Sympy:
        if not isinstance(abbrev, string_types) and not \
                   isinstance(abbrev, Symbol):
            dimension, scale_factor, abbrev = abbrev, dimension, scale_factor

        if dimension is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_dimension_map",
            ).warn()

        if scale_factor is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_scale_factors",
            ).warn()

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, abbrev)
        obj._name = name
        obj._abbrev = abbrev
        obj._latex_repr = latex_repr
        obj._unicode_repr = pretty_unicode_repr
        obj._ascii_repr = pretty_ascii_repr
        obj._mathml_repr = mathml_presentation_repr

        if dimension is not None:
            # TODO: remove after deprecation:
            obj.set_dimension(dimension)

        if scale_factor is not None:
            # TODO: remove after deprecation:
            obj.set_scale_factor(scale_factor)
        return obj
Exemplo n.º 7
0
    def __new__(cls,
                name,
                dimension,
                scale_factor=S.One,
                abbrev=None,
                dim_sys=dimsys_default,
                **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        if not isinstance(dim_sys, DimensionSystem):
            raise TypeError("%s is not a DimensionSystem" % dim_sys)

        if not isinstance(dimension, dimensions.Dimension):
            if dimension == 1:
                dimension = Dimension(1)
            else:
                raise ValueError("expected dimension or 1")
        else:
            for dim_sym in dimension.name.atoms(Dimension):
                if dim_sym not in [
                        i.name for i in dim_sys._dimensional_dependencies
                ]:
                    raise ValueError("Dimension %s is not registered in the "
                                     "dimensional dependency tree." % dim_sym)

        scale_factor = sympify(scale_factor)

        dimex = Quantity.get_dimensional_expr(scale_factor)
        if dimex != 1:
            if not dim_sys.equivalent_dims(dimension, Dimension(dimex)):
                raise ValueError("quantity value and dimension mismatch")

        # replace all prefixes by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Prefix),
                                            lambda x: x.scale_factor)
        # replace all quantities by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Quantity),
                                            lambda x: x.scale_factor)

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, dimension, scale_factor, abbrev)
        obj._name = name
        obj._dimension = dimension
        obj._scale_factor = scale_factor
        obj._dim_sys = dim_sys
        obj._abbrev = abbrev
        return obj
Exemplo n.º 8
0
    def __new__(cls, name, abbrev=None, dimension=None, scale_factor=None,
                latex_repr=None, pretty_unicode_repr=None,
                pretty_ascii_repr=None, mathml_presentation_repr=None,
                **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        # For Quantity(name, dim, scale, abbrev) to work like in the
        # old version of Sympy:
        if not isinstance(abbrev, string_types) and not \
                   isinstance(abbrev, Symbol):
            dimension, scale_factor, abbrev = abbrev, dimension, scale_factor

        if dimension is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_dimension_map",
            ).warn()

        if scale_factor is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_scale_factors",
            ).warn()

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, abbrev)
        obj._name = name
        obj._abbrev = abbrev
        obj._latex_repr = latex_repr
        obj._unicode_repr = pretty_unicode_repr
        obj._ascii_repr = pretty_ascii_repr
        obj._mathml_repr = mathml_presentation_repr

        if dimension is not None:
            # TODO: remove after deprecation:
            obj.set_dimension(dimension)

        if scale_factor is not None:
            # TODO: remove after deprecation:
            obj.set_scale_factor(scale_factor)
        return obj
Exemplo n.º 9
0
    def __new__(cls, name, dimension, scale_factor=S.One, abbrev=None, dim_sys=dimsys_default, **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        if not isinstance(dim_sys, DimensionSystem):
            raise TypeError("%s is not a DimensionSystem" % dim_sys)

        if not isinstance(dimension, dimensions.Dimension):
            if dimension == 1:
                dimension = Dimension(1)
            else:
                raise ValueError("expected dimension or 1")
        else:
            for dim_sym in dimension.name.atoms(Dimension):
                if dim_sym not in [i.name for i in dim_sys._dimensional_dependencies]:
                    raise ValueError("Dimension %s is not registered in the "
                                     "dimensional dependency tree." % dim_sym)

        scale_factor = sympify(scale_factor)

        dimex = Quantity.get_dimensional_expr(scale_factor)
        if dimex != 1:
            if not dim_sys.equivalent_dims(dimension, Dimension(dimex)):
                raise ValueError("quantity value and dimension mismatch")

        # replace all prefixes by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Prefix), lambda x: x.scale_factor)
        # replace all quantities by their ratio to canonical units:
        scale_factor = scale_factor.replace(lambda x: isinstance(x, Quantity), lambda x: x.scale_factor)

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, dimension, scale_factor, abbrev)
        obj._name = name
        obj._dimension = dimension
        obj._scale_factor = scale_factor
        obj._dim_sys = dim_sys
        obj._abbrev = abbrev
        return obj
Exemplo n.º 10
0
    def __new__(cls, name, abbrev=None, dimension=None, scale_factor=None, **assumptions):

        if not isinstance(name, Symbol):
            name = Symbol(name)

        if dimension is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_dimension_map",
            ).warn()

        if scale_factor is not None:
            SymPyDeprecationWarning(
                deprecated_since_version="1.3",
                issue=14319,
                feature="Quantity arguments",
                useinstead="SI_quantity_scale_factors",
            ).warn()

        if abbrev is None:
            abbrev = name
        elif isinstance(abbrev, string_types):
            abbrev = Symbol(abbrev)

        obj = AtomicExpr.__new__(cls, name, abbrev)
        obj._name = name
        obj._abbrev = abbrev

        if dimension is not None:
            # TODO: remove after deprecation:
            obj.set_dimension(dimension)

        if scale_factor is not None:
            # TODO: remove after deprecation:
            obj.set_scale_factor(scale_factor)
        return obj