Class AbstractArrayContext

  • All Implemented Interfaces:
    ContextIndex, com.yahoo.tensor.evaluation.EvaluationContext<Reference>, com.yahoo.tensor.evaluation.TypeContext<Reference>, Cloneable
    Direct Known Subclasses:
    ArrayContext, DoubleOnlyArrayContext

    public abstract class AbstractArrayContext
    extends Context
    implements Cloneable, ContextIndex
    Superclass of contexts which supports array index based lookup. Instances may be reused indefinitely for evaluations of a single ranking expression, in a single thread at the time.
    Author:
    bratseth
    • Constructor Detail

      • AbstractArrayContext

        protected AbstractArrayContext​(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.
      • AbstractArrayContext

        protected AbstractArrayContext​(RankingExpression expression,
                                       boolean ignoreUnknownValues)
      • AbstractArrayContext

        protected AbstractArrayContext​(RankingExpression expression,
                                       boolean ignoreUnknownValues,
                                       Value missingValue)
        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

      • doubleValues

        protected final double[] doubleValues()
      • ignoreUnknownValues

        protected final boolean ignoreUnknownValues()
      • names

        public Set<String> names()
        Description copied from class: Context
        Returns all the names available in this, or throws an UnsupportedOperationException if this operation is not supported. This default implementation does the latter.
        Overrides:
        names in class Context
        Returns:
        the set of all variable names.
      • size

        public int size()
        Returns the max number of variables which may be set in this
        Specified by:
        size in interface ContextIndex
      • getDouble

        public 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 Context
        Parameters:
        index - the index of the variable whose value to return.
        Returns:
        the value of the indexed variable.
      • clone

        public AbstractArrayContext 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 Object