Class Context

  • All Implemented Interfaces:
    com.yahoo.tensor.evaluation.EvaluationContext<Reference>, com.yahoo.tensor.evaluation.TypeContext<Reference>
    Direct Known Subclasses:
    AbstractArrayContext, MapContext

    public abstract class Context
    extends java.lang.Object
    implements com.yahoo.tensor.evaluation.EvaluationContext<Reference>
    The context providing value bindings for an expression evaluation.
    Author:
    bratseth
    • Constructor Summary

      Constructors 
      Constructor Description
      Context()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Value get​(int index)
      Lookup by index rather than name.
      abstract Value get​(java.lang.String name)
      Returns the value of a simple variable name.
      Value get​(java.lang.String name, Arguments arguments, java.lang.String output)
      Returns the value of a structured variable on the form name(argument*)(.output)?, where argument is any string.
      double getDouble​(int index)
      Lookup by index rather than name directly to a double.
      com.yahoo.tensor.Tensor getTensor​(java.lang.String name)
      Returns a variable as a tensor
      com.yahoo.tensor.TensorType getType​(java.lang.String reference)  
      java.util.Set<java.lang.String> names()
      Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported.
      void put​(java.lang.String name, double value)
      Same as put(name,DoubleValue.frozen(value))
      void put​(java.lang.String name, Value value)
      Sets a value to this, or throws an UnsupportedOperationException if this is not supported.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.yahoo.tensor.evaluation.TypeContext

        getType
    • Constructor Detail

      • Context

        public Context()
    • Method Detail

      • get

        public abstract Value get​(java.lang.String name)
        Returns the value of a simple variable name.
        Parameters:
        name - the name of the variable whose value to return.
        Returns:
        the value of the named variable.
      • getType

        public com.yahoo.tensor.TensorType getType​(java.lang.String reference)
        Specified by:
        getType in interface com.yahoo.tensor.evaluation.TypeContext<Reference>
      • getTensor

        public com.yahoo.tensor.Tensor getTensor​(java.lang.String name)
        Returns a variable as a tensor
        Specified by:
        getTensor in interface com.yahoo.tensor.evaluation.EvaluationContext<Reference>
      • get

        public Value get​(java.lang.String name,
                         Arguments arguments,
                         java.lang.String output)

        Returns the value of a structured variable on the form name(argument*)(.output)?, where argument is any string. This may be used to implement more advanced variables whose values are calculated at runtime from arguments. Supporting this in a context is optional.

        This default implementation generates a name on the form name(argument1, argument2, ...argumentN).output. If there are no arguments the parenthesis are omitted. If there is no output, the dot is omitted.

        Parameters:
        name - the name of this variable.
        arguments - the parsed arguments as given in the textual expression.
        output - the name of the value to output (to enable one named calculation to output several), or null to output the "main" (or only) value.
      • get

        public Value get​(int index)

        Lookup by index rather than name. This is supported by some optimized context subclasses. This default implementation throws UnsupportedOperationException.

        Parameters:
        index - the index of the variable whose value to return.
        Returns:
        the value of the indexed variable.
      • getDouble

        public double getDouble​(int index)
        Lookup by index rather than name directly to a double. This is supported by some optimized context subclasses. This default implementation throws UnsupportedOperationException.
        Parameters:
        index - the index of the variable whose value to return.
        Returns:
        the value of the indexed variable.
      • put

        public final void put​(java.lang.String name,
                              double value)
        Same as put(name,DoubleValue.frozen(value))
      • put

        public void put​(java.lang.String name,
                        Value value)
        Sets a value to this, or throws an UnsupportedOperationException if this is not supported. This default implementation does the latter.
        Parameters:
        name - the name of the variable to set.
        value - the value to set. Ownership of this value is transferred to this - if it is mutable (not frozen) it may be modified during execution
      • names

        public java.util.Set<java.lang.String> names()
        Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported. This default implementation does the latter.
        Returns:
        the set of all variable names.