Example usage for org.apache.mahout.math.function DoubleDoubleFunction apply

List of usage examples for org.apache.mahout.math.function DoubleDoubleFunction apply

Introduction

In this page you can find the example usage for org.apache.mahout.math.function DoubleDoubleFunction apply.

Prototype

public abstract double apply(double arg1, double arg2);

Source Link

Document

Apply the function to the arguments and return the result

Usage

From source file:org.qcri.pca.NormalizeJob.java

static void sparseVectorAssign(Vector mainV, final Vector otherV, DoubleDoubleFunction function) {
    java.util.Vector<IndexValue> newZeroElements = new java.util.Vector<IndexValue>();
    Iterator<Vector.Element> nonZeroElements = mainV.nonZeroes().iterator();
    while (nonZeroElements.hasNext()) {
        Vector.Element e = nonZeroElements.next();
        double res = function.apply(e.get(), otherV.getQuick(e.index()));
        if (res != 0)
            mainV.setQuick(e.index(), res);
        else //Don't affect the iterator
            newZeroElements.add(new IndexValue(e.index(), res));
    }//from   ww  w . j a va 2s.  c  om
    for (IndexValue iv : newZeroElements)
        mainV.setQuick(iv.index, iv.value);
}