How to use the expression.cast_other function in Expression

To help you get started, we’ve selected a few Expression examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __rmul__(self, other):
        return other * self
github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __radd__(self, other):
        return other + self
github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __mul__(self, other):
        # Get new attributes and verify that dimensions are valid.
        dcp_attr = self._dcp_attr() * other._dcp_attr()
        # Multiply all coefficients by the constant.
        lh_blocks = self.coefficients()[s.CONSTANT]
        constant_term = self.merge_cols(lh_blocks)
        new_coeffs = {}
        for var_id,blocks in other.coefficients().items():
            block_product = []
            for block in blocks:
                block_product.append(constant_term * block)
            new_coeffs[var_id] = block_product
        return AffExpression(new_coeffs, dcp_attr)
github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __rsub__(self, other):
        return other - self
github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __add__(self, other):
        new_dcp_attr = self._dcp_attr() + other._dcp_attr()
        new_shape = new_dcp_attr.shape
        # Get the coefficients of the two expressions.
        # Promote the coefficients if necessary.
        self_coeffs = self.coefficients()
        other_coeffs = other.coefficients()
        if new_shape.size > self.size:
            self_coeffs = self.promote(self_coeffs, new_shape)
        elif new_shape.size > other.size:
            other_coeffs = self.promote(other_coeffs, new_shape)
        # Merge the dicts, summing common variables.
        new_coeffs = self_coeffs.copy()
        for var_id,blocks in other_coeffs.items():
            if var_id in new_coeffs:
                block_sum = []
github cvxgrp / cvxpy / cvxpy / expressions / affine.py View on Github external
    @cast_other
    def __sub__(self, other):
        return self + -other