Package com.yahoo.tensor.functions
Class ReduceJoin<NAMETYPE extends Name>
- java.lang.Object
-
- com.yahoo.tensor.functions.TensorFunction<NAMETYPE>
-
- com.yahoo.tensor.functions.CompositeTensorFunction<NAMETYPE>
-
- com.yahoo.tensor.functions.ReduceJoin<NAMETYPE>
-
public class ReduceJoin<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYPE>
An optimization for tensor expressions where a join immediately follows a reduce. Evaluating this as one operation is significantly more efficient than evaluating each separately. This implementation optimizes the case where the reduce is done on the same dimensions as the join. A particularly efficient evaluation is done if there is one common dimension that is joined and reduced on, which is a common case as it covers vector and matrix like multiplications.- Author:
- lesters
-
-
Constructor Summary
Constructors Constructor Description ReduceJoin(Reduce<NAMETYPE> reduce, Join<NAMETYPE> join)
ReduceJoin(TensorFunction<NAMETYPE> argumentA, TensorFunction<NAMETYPE> argumentB, java.util.function.DoubleBinaryOperator combinator, Reduce.Aggregator aggregator, java.util.List<java.lang.String> dimensions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<TensorFunction<NAMETYPE>>
arguments()
Returns the function arguments of this node in the order they are appliedboolean
canOptimize(Tensor a, Tensor b)
Tests whether or not the reduce is over the join dimensions.Tensor
evaluate(EvaluationContext<NAMETYPE> context)
Evaluates this by first converting it to a primitive functionPrimitiveTensorFunction<NAMETYPE>
toPrimitive()
Translate this function - and all of its arguments recursively - to a tree of primitive functions only.java.lang.String
toString(ToStringContext context)
Return a string representation of this context.TensorFunction<NAMETYPE>
withArguments(java.util.List<TensorFunction<NAMETYPE>> arguments)
Returns a copy of this tensor function with the arguments replaced by the given list of arguments.-
Methods inherited from class com.yahoo.tensor.functions.CompositeTensorFunction
type
-
Methods inherited from class com.yahoo.tensor.functions.TensorFunction
asScalarFunction, evaluate, toString
-
-
-
-
Constructor Detail
-
ReduceJoin
public ReduceJoin(TensorFunction<NAMETYPE> argumentA, TensorFunction<NAMETYPE> argumentB, java.util.function.DoubleBinaryOperator combinator, Reduce.Aggregator aggregator, java.util.List<java.lang.String> dimensions)
-
-
Method Detail
-
arguments
public java.util.List<TensorFunction<NAMETYPE>> arguments()
Description copied from class:TensorFunction
Returns the function arguments of this node in the order they are applied- Specified by:
arguments
in classTensorFunction<NAMETYPE extends Name>
-
withArguments
public TensorFunction<NAMETYPE> withArguments(java.util.List<TensorFunction<NAMETYPE>> arguments)
Description copied from class:TensorFunction
Returns a copy of this tensor function with the arguments replaced by the given list of arguments.- Specified by:
withArguments
in classTensorFunction<NAMETYPE extends Name>
-
toPrimitive
public PrimitiveTensorFunction<NAMETYPE> toPrimitive()
Description copied from class:TensorFunction
Translate this function - and all of its arguments recursively - to a tree of primitive functions only.- Specified by:
toPrimitive
in classTensorFunction<NAMETYPE extends Name>
- Returns:
- a tree of primitive functions implementing this
-
evaluate
public final Tensor evaluate(EvaluationContext<NAMETYPE> context)
Description copied from class:CompositeTensorFunction
Evaluates this by first converting it to a primitive function- Overrides:
evaluate
in classCompositeTensorFunction<NAMETYPE extends Name>
- Parameters:
context
- a context which must be passed to all nested functions when evaluating
-
canOptimize
public boolean canOptimize(Tensor a, Tensor b)
Tests whether or not the reduce is over the join dimensions. The remaining logic in this class assumes this to be true. If no dimensions are given, the join must be on all tensor dimensions.- Returns:
true
if the implementation can optimize evaluation given the two tensors.
-
toString
public java.lang.String toString(ToStringContext context)
Description copied from class:TensorFunction
Return a string representation of this context.- Specified by:
toString
in classTensorFunction<NAMETYPE extends Name>
- Parameters:
context
- a context which must be passed to all nested functions when requesting the string value
-
-