Package com.yahoo.tensor.functions
Class Reduce<NAMETYPE extends Name>
- java.lang.Object
-
- com.yahoo.tensor.functions.TensorFunction<NAMETYPE>
-
- com.yahoo.tensor.functions.PrimitiveTensorFunction<NAMETYPE>
-
- com.yahoo.tensor.functions.Reduce<NAMETYPE>
-
public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE>
The reduce tensor operation returns a tensor produced from the argument tensor where some dimensions are collapsed to a single value using an aggregator function.- Author:
- bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Reduce.Aggregator
-
Constructor Summary
Constructors Constructor Description Reduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator)
Creates a reduce function reducing all dimensionsReduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator, java.lang.String dimension)
Creates a reduce function reducing a single dimensionReduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator, java.util.List<java.lang.String> dimensions)
Creates a reduce function.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TensorFunction<NAMETYPE>
argument()
java.util.List<TensorFunction<NAMETYPE>>
arguments()
Returns the function arguments of this node in the order they are appliedTensor
evaluate(EvaluationContext<NAMETYPE> context)
Evaluates this tensor.static TensorType
outputType(TensorType inputType, java.util.List<java.lang.String> reduceDimensions)
PrimitiveTensorFunction<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.TensorType
type(TypeContext<NAMETYPE> context)
Returns the type of the tensor this produces given the input types in the contextTensorFunction<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.TensorFunction
asScalarFunction, evaluate, toString
-
-
-
-
Constructor Detail
-
Reduce
public Reduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator)
Creates a reduce function reducing all dimensions
-
Reduce
public Reduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator, java.lang.String dimension)
Creates a reduce function reducing a single dimension
-
Reduce
public Reduce(TensorFunction<NAMETYPE> argument, Reduce.Aggregator aggregator, java.util.List<java.lang.String> dimensions)
Creates a reduce function.- Parameters:
argument
- the tensor to reduceaggregator
- the aggregator function to usedimensions
- the list of dimensions to remove. If an empty list is given, all dimensions are reduced, producing a dimensionless tensor (a scalar).- Throws:
java.lang.IllegalArgumentException
- if any of the tensor dimensions are not present in the input tensor
-
-
Method Detail
-
outputType
public static TensorType outputType(TensorType inputType, java.util.List<java.lang.String> reduceDimensions)
-
argument
public TensorFunction<NAMETYPE> argument()
-
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
-
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
-
type
public TensorType type(TypeContext<NAMETYPE> context)
Description copied from class:TensorFunction
Returns the type of the tensor this produces given the input types in the context- Specified by:
type
in classTensorFunction<NAMETYPE extends Name>
- Parameters:
context
- a context which must be passed to all nexted functions when evaluating
-
evaluate
public Tensor evaluate(EvaluationContext<NAMETYPE> context)
Description copied from class:TensorFunction
Evaluates this tensor.- Specified by:
evaluate
in classTensorFunction<NAMETYPE extends Name>
- Parameters:
context
- a context which must be passed to all nested functions when evaluating
-
-