Remove a particular factor from a tensor product space.
178232
def remove(self, other):
        """"""
        if other is FullSpace:
            return TrivialSpace
        if other is TrivialSpace:
            return self
        if isinstance(other, ProductSpace):
            oops = set(other.operands)
        else:
            oops = {other}
        return ProductSpace.create(
                *sorted(set(self.operands).difference(oops)))
1054809
def __separate_scalar_factor(monomial):
    
    scalar_factor = 1
    if is_number_type(monomial):
        return S.One, monomial
    if monomial == 0:
        return S.One, 0
    comm_factors, _ = split_commutative_parts(monomial)
    if len(comm_factors) > 0:
        if isinstance(comm_factors[0], Number):
            scalar_factor = comm_factors[0]
    if scalar_factor != 1:
        return monomial / scalar_factor, scalar_factor
    else:
        return monomial, scalar_factor
776212
def clean(self,x):
        """"""
        return x[~np.any(np.isnan(x) | np.isinf(x),axis=1)]
879325
def reduce_prod(attrs, inputs, proto_obj):
    """"""
    new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})
    return 'prod', new_attrs, inputs
970242
public void removeLRU() {
        int removeCount = (int) Math.max((size() * trimFactor), 1);

        Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
        while ((removeCount--) > 0 && entries.hasNext()) {
            entries.next();
            entries.remove();
        }
    }
598048
def remove_variable(self, name):
        """"""
        index = self._get_var_index(name)
        # Remove from matrix
        self._A = np.delete(self.A, index, 1)
        # Remove from bounds
        del self.bounds[name]
        # Remove from var list
        del self._variables[name]
        self._update_variable_indices()
        self._reset_solution()
774074
def _divide(self, x1, x2, out):
        """"""
        self.tspace._divide(x1.tensor, x2.tensor, out.tensor)
1365090
def empty_trivial(cls, ops, kwargs):
    """"""
    from qnet.algebra.core.hilbert_space_algebra import TrivialSpace
    if len(ops) == 0:
        return TrivialSpace
    else:
        return ops, kwargs
251378
def remove(self, x):
    
    with tf.name_scope("pad_reduce/remove"):
      x_shape = x.get_shape().as_list()
      x = tf.gather_nd(
          x,
          indices=self.nonpad_ids,
      )
      if not tf.executing_eagerly():
        # This is a hack but for some reason, gather_nd return a tensor of
        # undefined shape, so the shape is set up manually
        x.set_shape([None] + x_shape[1:])
    return x
1331441
def as_proto(self):
        """"""
        if self._dims is None:
            return tensor_shape_pb2.TensorShapeProto(unknown_rank=True)
        else:
            return tensor_shape_pb2.TensorShapeProto(
                dim=[
                    tensor_shape_pb2.TensorShapeProto.Dim(
                        size=-1 if d.value is None else d.value
                    )
                    for d in self._dims
                ]
            )
1142227
def semiflatten(multi):
    """"""
    if multi:
        result = multi.to_dict(flat=False)
        for k, v in result.items():
            if len(v) == 1:
                result[k] = v[0]
        return result
    else:
        return multi
1334895
def normalise_tensor(tensor):
    '''
    
    '''
    tensor_norm = np.linalg.norm(tensor)
    return tensor / tensor_norm, tensor_norm
630566
def left(X, i):
    """"""
    if i < 0:
        return np.ones([1, 1])
    answ = np.ones([1, 1])
    cores = tt.tensor.to_list(X)
    for dim in xrange(i+1):
        answ = np.tensordot(answ, cores[dim], 1)
    answ = reshape(answ, (-1, X.r[i+1]))
    return answ
659719
def separate_scalar_factor(element):
    
    coeff = 1.0
    monomial = S.One
    if isinstance(element, (int, float, complex)):
        coeff *= element
        return monomial, coeff
    for var in element.as_coeff_mul()[1]:
        if not (var.is_Number or var.is_imaginary):
            monomial = monomial * var
        else:
            if var.is_Number:
                coeff = float(var)
            # If not, then it is imaginary
            else:
                coeff = 1j * coeff
    coeff = float(element.as_coeff_mul()[0]) * coeff
    return monomial, coeff
415142
def shrink (self):
        """"""
        trim = int(0.05*len(self))
        if trim:
            items = super(LFUCache, self).items()
            # sorting function for items
            keyfunc = lambda x: x[1][0]
            values = sorted(items, key=keyfunc)
            for item in values[0:trim]:
                del self[item[0]]
637882
def _reduce_mean_ignore_inf(x, axis):
    """"""
    mask = tf.not_equal(x, tf.float32.min)
    x_zeroed = tf.where(mask, x, tf.zeros_like(x))
    return (tf.reduce_sum(x_zeroed, axis) / tf.reduce_sum(
        tf.cast(mask, tf.float32), axis))
1033486
def _uncamelize(self, s):
        '''  '''
        res = ''
        if s:
            for i in range(len(s)): 
                if i > 0 and s[i].lower() != s[i]:
                    res += '_'
                res += s[i].lower()
        return res