Multiply a factor elementwise with this one.
@param other The multiplier.
@throws IllegalArgumentException If the two tensors have different sizes.
342776
public void elemMultiply(VTensor other) {
        checkEqualSize(this, other);
        for (int c = 0; c < this.size(); c++) {
            multiplyValue(c, other.getValue(c));
        }
    }
814085
public TableFactor multiply(TableFactor other) {

    // Calculate the result domain

    List<Integer> domain = new ArrayList<>();
    List<Integer> otherDomain = new ArrayList<>();
    List<Integer> resultDomain = new ArrayList<>();

    for (int n : neighborIndices) {
      domain.add(n);
      resultDomain.add(n);
    }
    for (int n : other.neighborIndices) {
      otherDomain.add(n);
      if (!resultDomain.contains(n)) resultDomain.add(n);
    }

    // Create result TableFactor

    int[] resultNeighborIndices = new int[resultDomain.size()];
    int[] resultDimensions = new int[resultNeighborIndices.length];
    for (int i = 0; i < resultDomain.size(); i++) {
      int var = resultDomain.get(i);
      resultNeighborIndices[i] = var;
      // assert consistency about variable size, we can't have the same variable with two different sizes
      assert ((getVariableSize(var) == 0 && other.getVariableSize(var) > 0) ||
          (getVariableSize(var) > 0 && other.getVariableSize(var) == 0) ||
          (getVariableSize(var) == other.getVariableSize(var)));
      resultDimensions[i] = Math.max(getVariableSize(resultDomain.get(i)), other.getVariableSize(resultDomain.get(i)));
    }
    TableFactor result = new TableFactor(resultNeighborIndices, resultDimensions);

    // OPTIMIZATION:
    // If we're a factor of size 2 receiving a message of size 1, then we can optimize that pretty heavily
    // We could just use the general algorithm at the end of this set of special cases, but this is the fastest way
    if (otherDomain.size() == 1 && (resultDomain.size() == domain.size()) && domain.size() == 2) {
      int msgVar = otherDomain.get(0);
      int msgIndex = resultDomain.indexOf(msgVar);

      if (msgIndex == 0) {
        for (int i = 0; i < resultDimensions[0]; i++) {
          double d = other.values[i];
          int k = i * resultDimensions[1];
          for (int j = 0; j < resultDimensions[1]; j++) {
            int index = k + j;
            result.values[index] = values[index] + d;
            assert !Double.isNaN(values[index]);
          }
        }
      } else if (msgIndex == 1) {
        for (int i = 0; i < resultDimensions[0]; i++) {
          int k = i * resultDimensions[1];
          for (int j = 0; j < resultDimensions[1]; j++) {
            int index = k + j;
            result.values[index] = values[index] + other.values[j];
            assert !Double.isNaN(values[index]);
          }
        }
      }
    }
    // OPTIMIZATION:
    // The special case where we're a message of size 1, and the other factor is receiving the message, and of size 2
    else if (domain.size() == 1 && (resultDomain.size() == otherDomain.size()) && resultDomain.size() == 2) {
      return other.multiply(this);
    }
    // Otherwise we follow the big comprehensive, slow general purpose algorithm
    else {

      // Calculate back-pointers from the result domain indices to original indices

      int[] mapping = new int[result.neighborIndices.length];
      int[] otherMapping = new int[result.neighborIndices.length];
      for (int i = 0; i < result.neighborIndices.length; i++) {
        mapping[i] = domain.indexOf(result.neighborIndices[i]);
        otherMapping[i] = otherDomain.indexOf(result.neighborIndices[i]);
      }

      // Do the actual joining operation between the two tables, applying 'join' for each result element.

      int[] assignment = new int[neighborIndices.length];
      int[] otherAssignment = new int[other.neighborIndices.length];

      // OPTIMIZATION:
      // Rather than use the standard iterator, which creates lots of int[] arrays on the heap, which need to be GC'd,
      // we use the fast version that just mutates one array. Since this is read once for us here, this is ideal.
      Iterator<int[]> fastPassByReferenceIterator = result.fastPassByReferenceIterator();
      int[] resultAssignment = fastPassByReferenceIterator.next();
      while (true) {
        // Set the assignment arrays correctly
        for (int i = 0; i < resultAssignment.length; i++) {
          if (mapping[i] != -1) assignment[mapping[i]] = resultAssignment[i];
          if (otherMapping[i] != -1) otherAssignment[otherMapping[i]] = resultAssignment[i];
        }
        result.setAssignmentLogValue(resultAssignment, getAssignmentLogValue(assignment) + other.getAssignmentLogValue(otherAssignment));
        // This mutates the resultAssignment[] array, rather than creating a new one
        if (fastPassByReferenceIterator.hasNext()) fastPassByReferenceIterator.next();
        else break;
      }
    }

    return result;
  }
1311609
private void repmatIncrement(TensorBase other, double multiplier) {
    // Maps a key of other into a partial key of this.
    int[] dimensionMapping = getDimensionMapping(other.getDimensionNumbers());
    int[] partialKey = ArrayUtils.copyOf(getDimensionSizes(), getDimensionSizes().length);
    for (int i = 0; i < dimensionMapping.length; i++) {
      partialKey[dimensionMapping[i]] = 1;
    }

    int numValues = 1;
    for (int i = 0; i < partialKey.length; i++) {
      numValues *= partialKey[i];
    }
    int[] keyOffsets = new int[numValues];
    Iterator<int[]> myKeyIterator = new IntegerArrayIterator(partialKey, new int[0]);
    int ind = 0;
    while (myKeyIterator.hasNext()) {
      keyOffsets[ind] = dimKeyToIndex(myKeyIterator.next());
      ind++;
    }
    Preconditions.checkState(ind == keyOffsets.length);

    Iterator<KeyValue> otherKeyValues = other.keyValueIterator();
    while (otherKeyValues.hasNext()) {
      KeyValue otherKeyValue = otherKeyValues.next();
      int baseOffset = 0;
      for (int i = 0; i < otherKeyValue.getKey().length; i++) {
        baseOffset += otherKeyValue.getKey()[i] * indexOffsets[dimensionMapping[i]];
      }

      for (int i = 0; i < keyOffsets.length; i++) {
        values[baseOffset + keyOffsets[i]] += otherKeyValue.getValue() * multiplier;
      }
    }
  }
830542
public Matrix4f fma4x3(Matrix4fc other, float otherFactor, Matrix4f dest) {
        dest._m00(m00 + other.m00() * otherFactor);
        dest._m01(m01 + other.m01() * otherFactor);
        dest._m02(m02 + other.m02() * otherFactor);
        dest._m03(m03);
        dest._m10(m10 + other.m10() * otherFactor);
        dest._m11(m11 + other.m11() * otherFactor);
        dest._m12(m12 + other.m12() * otherFactor);
        dest._m13(m13);
        dest._m20(m20 + other.m20() * otherFactor);
        dest._m21(m21 + other.m21() * otherFactor);
        dest._m22(m22 + other.m22() * otherFactor);
        dest._m23(m23);
        dest._m30(m30 + other.m30() * otherFactor);
        dest._m31(m31 + other.m31() * otherFactor);
        dest._m32(m32 + other.m32() * otherFactor);
        dest._m33(m33);
        dest._properties(0);
        return dest;
    }
372823
public D multipliedBy(int factor) {

        switch (factor) {
            case -1:
                return this.inverse();
            case 1:
                return this.self();
            default:
                return this.with(MathUtils.safeMultiply(this.amount, factor));
        }

    }
566987
public static void multiplyInPlace(double[] a, double b) {
    for (int i = 0; i < a.length; i++) {
      a[i] = a[i] * b;
    }
  }
1278877
private final SparseTensor doElementwise(Tensor other, boolean useSum) {
    // TODO(jayantk): This method could be generalized by taking a
    // Function
    // instead of a boolean flag. However, it's unclear how this
    // change
    // affects performance.
    Preconditions.checkArgument(Arrays.equals(getDimensionNumbers(), other.getDimensionNumbers()));
    long[] resultKeyInts = new long[size() + other.size()];
    double[] resultValues = new double[size() + other.size()];

    int resultInd = 0;
    int myInd = 0;
    int otherInd = 0;

    int mySize = size();
    int otherSize = other.size();
    long otherKeyNum = 1;
    while (myInd < mySize && otherInd < otherSize) {
      otherKeyNum = other.indexToKeyNum(otherInd);
      if (keyNums[myInd] < otherKeyNum) {
        resultKeyInts[resultInd] = keyNums[myInd];
        resultValues[resultInd] = values[myInd];
        resultInd++;
        myInd++;
      } else if (keyNums[myInd] > otherKeyNum) {
        resultKeyInts[resultInd] = otherKeyNum;
        resultValues[resultInd] = other.getByIndex(otherInd);
        resultInd++;
        otherInd++;
      } else {
        // Keys are equal.
        if (useSum) {
          resultValues[resultInd] = values[myInd] + other.getByIndex(otherInd);
        } else {
          resultValues[resultInd] = Math.max(values[myInd], other.getByIndex(otherInd));
        }

        if (resultValues[resultInd] != 0.0) {
          // Ignore the resulting value if it is zero.
          resultKeyInts[resultInd] = keyNums[myInd];
          resultInd++;
        }
        myInd++;
        otherInd++;
      }
    }

    // One of the two lists might not be done yet. Finish it off.
    for (; myInd < size(); myInd++) {
      resultKeyInts[resultInd] = keyNums[myInd];
      resultValues[resultInd] = values[myInd];
      resultInd++;
    }

    for (; otherInd < other.size(); otherInd++) {
      resultKeyInts[resultInd] = other.indexToKeyNum(otherInd);
      resultValues[resultInd] = other.getByIndex(otherInd);
      resultInd++;
    }

    return resizeIntoTable(getDimensionNumbers(), getDimensionSizes(), resultKeyInts, resultValues, resultInd);
  }
133028
public void add(IntLongVector other) {
        if (other instanceof IntLongUnsortedVector) {
            IntLongUnsortedVector vec = (IntLongUnsortedVector) other;
            for (int i=0; i<vec.top; i++) {
                this.add(vec.idx[i], vec.vals[i]);
            }
        } else {
            //  TODO: Add special case for IntLongDenseVector.
            other.iterate(new SparseBinaryOpApplier(this, new Lambda.LongAdd()));
        }
    }
1172747
public void product(IntIntVector other) {
        // TODO: Add special case for IntIntDenseVector.
        for (int i=0; i<size; i++) {
            elements[i + start] *= other.get(i);
        }
    }
606027
public IntBiMap union(IntBiMap other) {
    int newLength = keys.length + other.keys.length;

    int[] newKeys = Arrays.copyOf(keys, newLength);
    ArrayUtils.copy(other.keys, 0, newKeys, keys.length, other.keys.length);
    int[] newValues = Arrays.copyOf(values, newLength);
    ArrayUtils.copy(other.values, 0, newValues, values.length, other.values.length);

    return IntBiMap.fromUnsortedKeyValues(newKeys, newValues);
  }
874463
public void merge(final KllFloatsSketch other) {
    if ((other == null) || other.isEmpty()) { return; }
    if (m_ != other.m_) {
      throw new SketchesArgumentException("incompatible M: " + m_ + " and " + other.m_);
    }
    final long finalN = n_ + other.n_;
    for (int i = other.levels_[0]; i < other.levels_[1]; i++) {
      update(other.items_[i]);
    }
    if (other.numLevels_ >= 2) {
      mergeHigherLevels(other, finalN);
    }
    if (Float.isNaN(minValue_) || (other.minValue_ < minValue_)) { minValue_ = other.minValue_; }
    if (Float.isNaN(maxValue_) || (other.maxValue_ > maxValue_)) { maxValue_ = other.maxValue_; }
    n_ = finalN;
    assertCorrectTotalWeight();
    if (other.isEstimationMode()) {
      minK_ = min(minK_, other.minK_);
    }
  }
1093499
private double denseTensorInnerProduct(DenseTensor other) {
    double[] otherValues = other.values;
    int length = values.length;
    Preconditions.checkArgument(otherValues.length == length);
    
    double innerProduct = 0.0;
    for (int i = 0; i < length; i++) {
      innerProduct += values[i] * otherValues[i];
    }
    return innerProduct;
  }
398009
@Override
  public void incrementWithMultiplier(TensorBase other, double multiplier) {
    if (Arrays.equals(other.getDimensionNumbers(), getDimensionNumbers())) {
      simpleIncrement(other, multiplier);
    } else {
      repmatIncrement(other, multiplier);
    }
  }
58817
public void add(ScalableStatistics other) {
    count += other.count;
    min = Math.min(min, other.min);
    max = Math.max(max, other.max);
    sum += other.sum;
    sumOfSquares += other.sumOfSquares;
    tdigest.add(other.tdigest);
    if (other.exactValues != null) {
      for (int i = 0; i < other.numExactValues; i++) {
        addQuantileValue(other.exactValues[i]);
      }
    }
  }
1214474
public void product(IntLongVector other) {
        // TODO: Add special case for IntLongDenseVector.
        for (int i=0; i<size; i++) {
            elements[i + start] *= other.get(i);
        }
    }
562776
public void elemDivide(Tensor other) {
        checkEqualSize(this, other);
        for (int c = 0; c < this.values.length; c++) {
            divideValue(c, other.values[c]);
        }
    }
32812
public synchronized void add(ConfusionMatrix<T> other) {
        for (T actual : other.matrix.keySet()) {
            Multiset<T> counts = other.matrix.get(actual);
            for (T predicted : counts.elementSet()) {
                int count = counts.count(predicted);
                this.add(actual, predicted, count);
            }
        }
    }