Class ArrayContext

  • All Implemented Interfaces:
    ContextIndex, com.yahoo.tensor.evaluation.EvaluationContext<Reference>, com.yahoo.tensor.evaluation.TypeContext<Reference>, java.lang.Cloneable

    public class ArrayContext
    extends AbstractArrayContext
    implements java.lang.Cloneable
    Creates a context which supports array index based lookup. This instance may be reused indefinitely for evaluations of a single ranking expression, in a single thread at the time.
    Author:
    bratseth
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.yahoo.tensor.evaluation.TypeContext

        com.yahoo.tensor.evaluation.TypeContext.Name
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ArrayContext clone()
      Creates a clone of this context suitable for evaluating against the same ranking expression in a different thread (i.e, name name to index map, different value set.
      Value get​(int index)
      Perform a fast lookup by index
      Value get​(java.lang.String name)
      Perform a slow lookup by name
      double getDouble​(int index)
      Perform a fast lookup directly of the value as a double.
      com.yahoo.tensor.TensorType getType​(Reference reference)  
      void put​(int index, double value)
      Same as put(index,DoubleValue.frozen(value))
      void put​(int index, Value value)
      Puts a value by index.
      void put​(java.lang.String name, Value value)
      Puts a value by name.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ArrayContext

        public ArrayContext​(RankingExpression expression)
        Create a fast lookup context for an expression. This instance should be reused indefinitely by a single thread. This will fail if unknown values are attempted added.
      • ArrayContext

        public ArrayContext​(RankingExpression expression,
                            boolean ignoreUnknownValues)
        Create a fast lookup context for an expression. This instance should be reused indefinitely by a single thread.
        Parameters:
        expression - the expression to create a context for
        ignoreUnknownValues - whether attempts to put values not present in this expression should fail (false - the default), or be ignored (true)
    • Method Detail

      • put

        public final void put​(java.lang.String name,
                              Value value)
        Puts a value by name. The value will be frozen if it isn't already.
        Overrides:
        put in class Context
        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
        Throws:
        java.lang.IllegalArgumentException - if the name is not present in the ranking expression this was created with, and ignoredUnknownValues is false
      • put

        public final void put​(int index,
                              double value)
        Same as put(index,DoubleValue.frozen(value))
      • put

        public final void put​(int index,
                              Value value)
        Puts a value by index. The value will be frozen if it isn't already.
      • getType

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

        public Value get​(java.lang.String name)
        Perform a slow lookup by name
        Specified by:
        get in class Context
        Parameters:
        name - the name of the variable whose value to return.
        Returns:
        the value of the named variable.
      • get

        public final Value get​(int index)
        Perform a fast lookup by index
        Specified by:
        get in interface ContextIndex
        Overrides:
        get in class Context
        Parameters:
        index - the index of the variable whose value to return.
        Returns:
        the value of the indexed variable.
      • getDouble

        public final double getDouble​(int index)
        Perform a fast lookup directly of the value as a double. This is faster than get(index).asDouble()
        Specified by:
        getDouble in interface ContextIndex
        Overrides:
        getDouble in class AbstractArrayContext
        Parameters:
        index - the index of the variable whose value to return.
        Returns:
        the value of the indexed variable.
      • clone

        public ArrayContext clone()
        Creates a clone of this context suitable for evaluating against the same ranking expression in a different thread (i.e, name name to index map, different value set.
        Overrides:
        clone in class AbstractArrayContext