Package com.yahoo.tensor.functions
Class TensorFunction<NAMETYPE extends Name>
- java.lang.Object
-
- com.yahoo.tensor.functions.TensorFunction<NAMETYPE>
-
- Direct Known Subclasses:
CompositeTensorFunction
,PrimitiveTensorFunction
public abstract class TensorFunction<NAMETYPE extends Name> extends java.lang.Object
A representation of a tensor function which is able to be translated to a set of primitive tensor functions if necessary. All tensor functions are immutable.- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description TensorFunction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.util.List<TensorFunction<NAMETYPE>>
arguments()
Returns the function arguments of this node in the order they are appliedjava.util.Optional<ScalarFunction<NAMETYPE>>
asScalarFunction()
Returns this as a scalar function, or empty if it cannot be represented as a scalar functionTensor
evaluate()
Evaluate with no contextabstract Tensor
evaluate(EvaluationContext<NAMETYPE> context)
Evaluates this tensor.abstract PrimitiveTensorFunction<NAMETYPE>
toPrimitive()
Translate this function - and all of its arguments recursively - to a tree of primitive functions only.java.lang.String
toString()
abstract java.lang.String
toString(ToStringContext context)
Return a string representation of this context.abstract TensorType
type(TypeContext<NAMETYPE> context)
Returns the type of the tensor this produces given the input types in the contextabstract 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.
-
-
-
Method Detail
-
arguments
public abstract java.util.List<TensorFunction<NAMETYPE>> arguments()
Returns the function arguments of this node in the order they are applied
-
withArguments
public abstract 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.- Throws:
java.lang.IllegalArgumentException
- if the argument list has the wrong size for this function
-
toPrimitive
public abstract PrimitiveTensorFunction<NAMETYPE> toPrimitive()
Translate this function - and all of its arguments recursively - to a tree of primitive functions only.- Returns:
- a tree of primitive functions implementing this
-
evaluate
public abstract Tensor evaluate(EvaluationContext<NAMETYPE> context)
Evaluates this tensor.- Parameters:
context
- a context which must be passed to all nested functions when evaluating
-
type
public abstract TensorType type(TypeContext<NAMETYPE> context)
Returns the type of the tensor this produces given the input types in the context- Parameters:
context
- a context which must be passed to all nexted functions when evaluating
-
evaluate
public final Tensor evaluate()
Evaluate with no context
-
toString
public abstract java.lang.String toString(ToStringContext context)
Return a string representation of this context.- Parameters:
context
- a context which must be passed to all nested functions when requesting the string value
-
asScalarFunction
public java.util.Optional<ScalarFunction<NAMETYPE>> asScalarFunction()
Returns this as a scalar function, or empty if it cannot be represented as a scalar function
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-