aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunction.java
blob: cbb0094c196c7e96ee72375121ed0b5c19a8a651 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.tensor.functions;

import com.yahoo.tensor.evaluation.EvaluationContext;
import com.yahoo.tensor.evaluation.Name;

import java.util.Optional;
import java.util.function.Function;

/**
 * A function which returns a scalar
 *
 * @author bratseth
 */
public interface ScalarFunction<NAMETYPE extends Name> extends Function<EvaluationContext<NAMETYPE>, Double> {

    @Override
    Double apply(EvaluationContext<NAMETYPE> context);

    /** Returns this as a tensor function, or empty if it cannot be represented as a tensor function */
    default Optional<TensorFunction<NAMETYPE>> asTensorFunction() { return Optional.empty(); }

    default String toString(ToStringContext<NAMETYPE> context) { return toString(); }

}