## org.apache.mahout.math
Class VectorBinaryAssign

    java.lang.Object
      org.apache.mahout.math.VectorBinaryAssign

Direct Known Subclasses:
  VectorBinaryAssign.AssignAllIterateSequentialInplaceUpdates, VectorBinaryAssign.AssignAllIterateSequentialMergeUpdates, VectorBinaryAssign.AssignAllIterateThatLookupThisInplaceUpdates, VectorBinaryAssign.AssignAllIterateThatLookupThisMergeUpdates, VectorBinaryAssign.AssignAllIterateThisLookupThatInplaceUpdates, VectorBinaryAssign.AssignAllIterateThisLookupThatMergeUpdates, VectorBinaryAssign.AssignAllLoopInplaceUpdates, VectorBinaryAssign.AssignAllLoopMergeUpdates, VectorBinaryAssign.AssignIterateIntersection, VectorBinaryAssign.AssignIterateUnionRandomInplaceUpdates, VectorBinaryAssign.AssignIterateUnionRandomMergeUpdates, VectorBinaryAssign.AssignIterateUnionSequentialInplaceUpdates, VectorBinaryAssign.AssignIterateUnionSequentialMergeUpdates, VectorBinaryAssign.AssignNonzerosIterateThatLookupThisInplaceUpdates, VectorBinaryAssign.AssignNonzerosIterateThatLookupThisMergeUpdates, VectorBinaryAssign.AssignNonzerosIterateThisLookupThat

    public abstract class VectorBinaryAssign

extends Object

Abstract class encapsulating different algorithms that perform the Vector operations assign(). x.assign(y, f), for x and y Vectors and f a DoubleDouble function: - applies the function f to every element in x and y, f(xi, yi) - assigns xi = f(xi, yi) for all indices i The names of variables, methods and classes used here follow the following conventions: The vector being assigned to (the left hand side) is called this or x. The right hand side is called that or y. The function to be applied is called f. The different algorithms take into account the different characteristics of vector classes: - whether the vectors support sequential iteration (isSequential()) - whether the vectors support constant-time additions (isAddConstantTime()) - what the lookup cost is (getLookupCost()) - what the iterator advancement cost is (getIteratorAdvanceCost()) The names of the actual classes (they're nested in VectorBinaryAssign) describe the used for assignment. The most important optimization is iterating just through the nonzeros (only possible if f(0, 0) = 0). There are 4 main possibilities: - iterating through the nonzeros of just one vector and looking up the corresponding elements in the other - iterating through the intersection of nonzeros (those indices where both vectors have nonzero values) - iterating through the union of nonzeros (those indices where at least one of the vectors has a nonzero value) - iterating through all the elements in some way (either through both at the same time, both one after the other, looking up both, looking up just one). Then, there are two additional sub-possibilities: - if a new value can be added to x in constant time (isAddConstantTime()), the *Inplace updates are used - otherwise (really just for SequentialAccessSparseVectors right now), the *Merge updates are used, where a sorted list of (index, value) pairs is merged into the vector at the end. The internal details are not important and a particular algorithm should generally not be called explicitly. The best one will be selected through assignBest(), which is itself called through Vector.assign(). See https://docs.google.com/document/d/1g1PjUuvjyh2LBdq2_rKLIcUiDbeOORA1sCJiSsz-JVU/edit# for a more detailed explanation.

Nested Class Summary
`static class` `VectorBinaryAssign.AssignAllIterateSequentialInplaceUpdates`
`static class` `VectorBinaryAssign.AssignAllIterateSequentialMergeUpdates`
`static class` `VectorBinaryAssign.AssignAllIterateThatLookupThisInplaceUpdates`
`static class` `VectorBinaryAssign.AssignAllIterateThatLookupThisMergeUpdates`
`static class` `VectorBinaryAssign.AssignAllIterateThisLookupThatInplaceUpdates`
`static class` `VectorBinaryAssign.AssignAllIterateThisLookupThatMergeUpdates`
`static class` `VectorBinaryAssign.AssignAllLoopInplaceUpdates`
`static class` `VectorBinaryAssign.AssignAllLoopMergeUpdates`
`static class` `VectorBinaryAssign.AssignIterateIntersection` If f(x, 0) = x and f(0, y) = 0 the zeros in x and y don't matter and we can iterate through the nonzeros in both x and y.
`static class` `VectorBinaryAssign.AssignIterateUnionRandomInplaceUpdates` If f(0, 0) = 0 we can iterate through the nonzeros in either x or y.
`static class` `VectorBinaryAssign.AssignIterateUnionRandomMergeUpdates` If f(0, 0) = 0 we can iterate through the nonzeros in either x or y.
`static class` `VectorBinaryAssign.AssignIterateUnionSequentialInplaceUpdates` If f(0, 0) = 0 we can iterate through the nonzeros in either x or y.
`static class` `VectorBinaryAssign.AssignIterateUnionSequentialMergeUpdates` If f(0, 0) = 0 we can iterate through the nonzeros in either x or y.
`static class` `VectorBinaryAssign.AssignNonzerosIterateThatLookupThisInplaceUpdates` If f(x, 0) = x, the zeros in y don't matter and we can simply iterate through the nonzeros of y.
`static class` `VectorBinaryAssign.AssignNonzerosIterateThatLookupThisMergeUpdates` If f(x, 0) = x, the zeros in y don't matter and we can simply iterate through the nonzeros of y.
`static class` `VectorBinaryAssign.AssignNonzerosIterateThisLookupThat` If f(0, y) = 0, the zeros in x don't matter and we can simply iterate through the nonzeros of x.

Field Summary
`static VectorBinaryAssign[]` `OPERATIONS`

Constructor Summary
`VectorBinaryAssign()`

Method Summary
`abstract Vector` `assign(Vector x, Vector y, DoubleDoubleFunction f)` Main method that applies f to x and y component-wise assigning the results to x.
`static Vector` `assignBest(Vector x, Vector y, DoubleDoubleFunction f)` This is the method that should be used when assigning.
`abstract double` `estimateCost(Vector x, Vector y, DoubleDoubleFunction f)` Estimates the cost of using this algorithm to compute the assignment.
`static VectorBinaryAssign` `getBestOperation(Vector x, Vector y, DoubleDoubleFunction f)` The best operation is the least expensive valid one.
`abstract boolean` `isValid(Vector x, Vector y, DoubleDoubleFunction f)` Returns true iff we can use this algorithm to apply f to x and y component-wise and assign the result to x.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### OPERATIONS

    public static final VectorBinaryAssign[] OPERATIONS

Constructor Detail

### VectorBinaryAssign

    public VectorBinaryAssign()

Method Detail

### isValid

    public abstract boolean isValid(Vector x,
                                    Vector y,
                                    DoubleDoubleFunction f)

  Returns true iff we can use this algorithm to apply f to x and y component-wise and assign the result to x.

### estimateCost

    public abstract double estimateCost(Vector x,
                                        Vector y,
                                        DoubleDoubleFunction f)

  Estimates the cost of using this algorithm to compute the assignment. The algorithm is assumed to be valid.

### assign

    public abstract Vector assign(Vector x,
                                  Vector y,
                                  DoubleDoubleFunction f)

  Main method that applies f to x and y component-wise assigning the results to x. It returns the modified vector, x.

### getBestOperation

    public static VectorBinaryAssign getBestOperation(Vector x,
                                                      Vector y,
                                                      DoubleDoubleFunction f)

  The best operation is the least expensive valid one.

### assignBest

    public static Vector assignBest(Vector x,
                                    Vector y,
                                    DoubleDoubleFunction f)

  This is the method that should be used when assigning. It selects the best algorithm and applies it. Note that it does NOT invalidate the cached length of the Vector and should only be used through the wrapprs in AbstractVector.

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.