Python sympy.Le() Examples

The following are 3 code examples of sympy.Le(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sympy , or try the search function .
Example #1
Source File: relational.py    From devito with MIT License 5 votes vote down vote up
def __new__(cls, lhs, rhs=0, subdomain=None, **kwargs):
        kwargs.update({'evaluate': False})
        obj = sympy.Le.__new__(cls, lhs, rhs, **kwargs)
        obj._subdomain = subdomain
        return obj 
Example #2
Source File: relational.py    From devito with MIT License 5 votes vote down vote up
def subdomain(self):
        """The SubDomain in which the Le is defined."""
        return self._subdomain 
Example #3
Source File: models.py    From symfit with GNU General Public License v2.0 4 votes vote down vote up
def as_constraint(cls, constraint, model, constraint_type=None, **init_kwargs):
        """
        Initiate a Model which should serve as a constraint. Such a
        constraint-model should be initiated with knowledge of another
        ``BaseModel``, from which it will take its parameters::

            model = Model({y: a * x + b})
            constraint = Model.as_constraint(Eq(a, 1), model)

        ``constraint.params`` will be ``[a, b]`` instead of ``[a]``.

        :param constraint: An ``Expr``, a mapping or iterable of ``Expr``, or a
            ``Relational``.
        :param model: An instance of (a subclass of)
            :class:`~symfit.core.models.BaseModel`.
        :param constraint_type: When ``constraint`` is not
            a :class:`~sympy.core.relational.Relational`, a
            :class:`~sympy.core.relational.Relational` has to be provided
            explicitly.
        :param kwargs: Any additional keyword arguments which will be passed on
            to the init method.
        """
        allowed_types = [sympy.Eq, sympy.Ge, sympy.Le]

        if isinstance(constraint, Relational):
            constraint_type = constraint.__class__
            constraint = constraint.lhs - constraint.rhs

        # Initiate the constraint model, in such a way that we take care
        # of any dependencies
        instance = cls.with_dependencies(constraint,
                                         dependency_model=model,
                                         **init_kwargs)

        # Check if the constraint_type is allowed, and flip the sign if needed
        if constraint_type not in allowed_types:
            raise ModelError(
                'Only constraints of the type {} are allowed. A constraint'
                ' of type {} was provided.'.format(allowed_types,
                                                   constraint_type)
            )
        elif constraint_type is sympy.Le:
            # We change this to a Ge and flip the sign
            instance = - instance
            constraint_type = sympy.Ge

        instance.constraint_type = constraint_type

        if len(instance.dependent_vars) != 1:
            raise ModelError('Only scalar models can be used as constraints.')

        # self.params has to be a subset of model.params
        if set(instance.params) <= set(model.params):
            instance.params = model.params
        else:
            raise ModelError('The parameters of ``constraint`` have to be a '
                             'subset of those of ``model``.')

        return instance