Quantities must be of the same dimension in order to operate. If they are
 represented by different units (but represent the same physical quantity)
 the second quantity is converted into the unit belonging to the first unit
 and the addition is completed
346756
def add_or_subtract!(operator,other)
      if other.is_a? Quantity
        other = other.to(@unit) if other.unit.is_alternative_for?(@unit)

        if @unit.is_equivalent_to? other.unit
          @value = @value.send operator, other.value

          return self
        else
          raise Quantify::Exceptions::InvalidObjectError, "Cannot add or subtract Quantities with different dimensions"
        end
      else
        raise Quantify::Exceptions::InvalidObjectError, "Cannot add or subtract non-Quantity objects"
      end
    end
1298214
def combine(self):
        
        self.pair, setup = self.combining_setup()
        self.cube(setup)
        actual = self.combining_search()
        self.cube(actual)
        return setup + actual
1062815
def _multiply(self, x1, x2, out):
        """"""
        for spc, xp, yp, outp in zip(self.spaces, x1.parts, x2.parts,
                                     out.parts):
            spc._multiply(xp, yp, outp)
20745
def _maybe_make_dimension(self, dimension):
    """"""
    # For backwards compatibility the argument can be either a Dimension, a
    # string or a `units.UnitDescriptor`.
    if isinstance(dimension, Dimension):
      return dimension
    if isinstance(dimension, units.UnitDescriptor):
      return Dimension.from_unit_descriptor(dimension)
    if isinstance(dimension, str):
      return Dimension.from_string(dimension)

    raise TypeError('Cannot convert %s to a dimension', dimension)
207754
def unit(self, value):
        

        if isinstance(value, TimeUnit):
            self._unit = value
        else:
            self._unit = TimeUnit(value)
342776
public void elemMultiply(VTensor other) {
        checkEqualSize(this, other);
        for (int c = 0; c < this.size(); c++) {
            multiplyValue(c, other.getValue(c));
        }
    }
810352
function Amount(value, unit) {
  if (!(this instanceof Amount))
    return new Amount(value, unit);

  this.value = 0;
  this.unit = null;

  if (value != null)
    this.fromOptions(value, unit);
}
61111
private void _quantity() throws
      IOException,
      CssException
  {

    if (debug)
    {
      int ch = reader.peek();
      checkState(QNTSTART.matches((char) ch) || isNextEscape());
      checkState(builder.getLength() > 0
          && NUM.matches(builder.getLast()));
    }

    /*
       * Assume we have a {num}{ident} instance (DIMEN), and then override
       * that if a specific quantity literal is found.
       */
    builder.type = Type.QNTY_DIMEN;
    TokenBuilder suffix = new TokenBuilder(reader, errHandler, locale);
    append(QNTSTART, suffix);
    if (suffix.getLast() != '%')
    { // QNTSTART = NMSTART | '%'
      append(NMCHAR, suffix);
    }

    if (suffix.getLength() > QNT_TOKEN_MAXLENGTH)
    {
      // longer than max length in quantities map
      builder.append(suffix.toString());
      return;
    }

    // shorter or equal to max length in quantities map
    // we might have a more specific match
    final int[] ident = suffix.toArray();
    int[] match = null;

    for (int[] test : quantities.keySet())
    {
      if (equals(ident, test, true))
      {
        builder.type = quantities.get(test);
        match = test;
        break;
      }
    }

    if (builder.type == Type.QNTY_DIMEN)
    {
      builder.append(ident);
    }
    else
    {
      if (debug)
      {
        checkState(match != null);
      }
      builder.append(match);
    }

  }
1224087
def to_si
      if @unit.is_compound_unit?
        Quantity.new(@value,@unit).convert_compound_unit_to_si!
      elsif @unit.is_dimensionless?
        return self.clone
      elsif @value.nil?
        return Quantity.new(nil, @unit.si_unit)
      else
        self.to(@unit.si_unit)
      end
    end
1005983
def add_quantity(self,
                     quantities,
                     value,
                     source,
                     check_for_dupes=True,
                     compare_to_existing=True,
                     **kwargs):
        """"""
        success = True
        for quantity in listify(quantities):
            kwargs.update({QUANTITY.VALUE: value, QUANTITY.SOURCE: source})
            cat_dict = self._add_cat_dict(
                Quantity,
                quantity,
                compare_to_existing=compare_to_existing,
                check_for_dupes=check_for_dupes,
                **kwargs)
            if isinstance(cat_dict, CatDict):
                self._append_additional_tags(quantity, source, cat_dict)
                success = False

        return success
29424
def add(item, quantity: 1, unique: true)
      raise 'expecting an acts_as_purchasable object' unless item.kind_of?(ActsAsPurchasable)

      existing = (
        if unique.kind_of?(Proc)
          cart_items.find { |cart_item| instance_exec(item, cart_item.purchasable, &unique) }
        elsif unique.kind_of?(Symbol) || (unique.kind_of?(String) && unique != 'true')
          raise "expected item to respond to unique #{unique}" unless item.respond_to?(unique)
          cart_items.find { |cart_item| cart_item.purchasable.respond_to?(unique) && item.send(unique) == cart_item.purchasable.send(unique) }
        elsif unique.present?
          find(item)
        end
      )

      if existing
        if unique || (existing.unique.present?)
          existing.assign_attributes(purchasable: item, quantity: quantity, unique: existing.unique)
        else
          existing.quantity = existing.quantity + quantity
        end
      end

      if item.quantity_enabled? && (existing ? existing.quantity : quantity) > item.quantity_remaining
        raise EffectiveOrders::SoldOutException, "#{item.purchasable_name} is sold out"
      end

      existing ||= cart_items.build(purchasable: item, quantity: quantity, unique: (unique.to_s unless unique.kind_of?(Proc)))
      save!
    end
402761
def _expand_if_needed(self, dims, write_dims, start, offset):
        
        from operator import mul

        if numpy.isscalar(start):
            start_is_scalar = True
        else:
            start_is_scalar = False

        existing_size = reduce(mul, dims, 1)
        required_size = offset + reduce(mul, write_dims, 1)

        if required_size > existing_size:
            print(
                "    required size:", required_size,
                "existing size:", existing_size)
            # we need to expand the image
            ndim = len(dims)
            idim = len(write_dims)

            if start_is_scalar:
                if start == 0:
                    start = [0]*ndim
                else:
                    raise ValueError(
                        "When expanding "
                        "an existing image while writing, the start keyword "
                        "must have the same number of dimensions "
                        "as the image or be exactly 0, got %s " % start)

            if idim != ndim:
                raise ValueError(
                    "When expanding "
                    "an existing image while writing, the input image "
                    "must have the same number of dimensions "
                    "as the original.  "
                    "Got %d instead of %d" % (idim, ndim))
            new_dims = []
            for i in xrange(ndim):
                required_dim = start[i] + write_dims[i]

                if required_dim < dims[i]:
                    # careful not to shrink the image!
                    dimsize = dims[i]
                else:
                    dimsize = required_dim

                new_dims.append(dimsize)

            print("    reshaping image to:", new_dims)
            self.reshape(new_dims)
49173
def has_same_sumformula(self, other):
        
        same_atoms = True
        for atom in set(self['atom']):
            own_atom_number = len(self[self['atom'] == atom])
            other_atom_number = len(other[other['atom'] == atom])
            same_atoms = (own_atom_number == other_atom_number)
            if not same_atoms:
                break
        return same_atoms
234087
def add(self, quantity):
        
        newvalue = self._value + quantity
        self.set(newvalue.deg)
736928
def add(substance,feature,value)
      substance = substance.id if substance.is_a? Substance
      feature = feature.id if feature.is_a? Feature
      data_entries[substance.to_s] ||= {}
      data_entries[substance.to_s][feature.to_s] ||= []
      data_entries[substance.to_s][feature.to_s] << value
      #data_entries[substance.to_s][feature.to_s].uniq! if value.numeric? # assuming that identical values come from the same source
    end
520836
def quantity(self):
        
        if not _has_astropy:
            raise ImportError("astropy must be installed for unit/quantity support")

        if self.unit is None:
            raise ValueError("unit is not set, cannot convert to quantity")

        return self.array * self.unit
756028
def measure
      cnt = Measure.new(@id.with_stat('count'), @count.get_and_set(0))
      tot = Measure.new(@id.with_stat('totalAmount'),
                        @total_amount.get_and_set(0))
      tot_sq = Measure.new(@id.with_stat('totalOfSquares'),
                           @total_sq.get_and_set(0))
      mx = Measure.new(@id.with_stat('max'), @max.get_and_set(Float::NAN))

      [cnt, tot, tot_sq, mx]
    end