@Override
    public TensorType type(TypeContext<NAMETYPE> context) {
        TensorType t1 = arg1.toPrimitive().type(context);
        TensorType t2 = arg2.toPrimitive().type(context);
        var resolvedDimension = context.resolveBinding(dimension);
        var d1 = t1.dimension(resolvedDimension);
        var d2 = t2.dimension(resolvedDimension);
        if (d1.isEmpty() || d2.isEmpty()
            || d1.get().type() != Dimension.Type.indexedBound
            || d2.get().type() != Dimension.Type.indexedBound
            || ! d1.get().size().equals(d2.get().size()))
        {
            throw new IllegalArgumentException("cosine_similarity expects both arguments to have the '"
                                               + resolvedDimension + "' dimension with same size, but input types were "
                                               + t1 + " and " + t2);
        }
        return toPrimitive().type(context);
    }
Convenience for cosine similarity between vectors.
cosine_similarity(a, b, mydim) == sum(a*b, mydim) / sqrt(sum(a*a, mydim) * sum(b*b, mydim)).

@author arnej
vespajlib/src/main/java/com/yahoo/tensor/functions/CosineSimilarity.java