@@ -65,39 +65,45 @@ Tensor type spec
dimension-name[size] - an indexed dimension
The tensor type for a tensor<float> with two mapped dimensions x and y looks like:
-
-tensor<float>(x{},y{})
-
+{% highlight vespa-ranking-expression %}
+tensor(x{},y{})
+{% endhighlight %}
Example tensor with this type:
-{% raw %}
+{% highlight vespa-ranking-expression %}
+{% raw %}
{{x:a,y:b}:10.0, {x:c,y:d}:20.1}
-{% endraw %}
+{% endraw %}
+{% endhighlight %}
The tensor type for a tensor<float> with two indexed dimensions x and y
with sizes 3 and 2 respectively looks like:
-
-tensor<float>(x[3],y[2])
-
+{% highlight vespa-ranking-expression %}
+tensor(x[3],y[2])
+{% endhighlight %}
Example tensor with this type (representing a matrix):
-{% raw %}
+{% highlight vespa-ranking-expression %}
+{% raw %}
{{x:0,y:0}:1, {x:0,y:1}:2.1,
{x:1,y:0}:3, {x:1,y:1}:5,
{x:2,y:0}:7, {x:2,y:1}:11}
-{% endraw %}
+{% endraw %}
+{% endhighlight %}
Note that the labels are indexes in the range [0,dimension-size>
A tensor<double> with both mapped and indexed dimensions is mixed:
-
-tensor<double>(key{},x[2])
-
+{% highlight vespa-ranking-expression %}
+tensor(key{},x[2])
+{% endhighlight %}
Example:
-{% raw %}
+{% highlight vespa-ranking-expression %}
+{% raw %}
{{key:a,x:0}:10, {key:b,x:0}:2.7,
{key:a,x:1}:5.3, {key:b,x:1}:-7 }
-{% endraw %}
+{% endraw %}
+{% endhighlight %}
@@ -139,25 +145,25 @@
An empty tensor:
-
+{% highlight vespa-ranking-expression %}
{}
-
+{% endhighlight %}
A single value tensor with a single mapped dimension x:
-
+{% highlight vespa-ranking-expression %}
{ {x:foo}:5.0 }
-
+{% endhighlight %}
A tensor with multiple values and mapped dimensions x and y:
-
+{% highlight vespa-ranking-expression %}
{ {x:foo, y:bar}:5.0, {x:foo, y:baz}:7.0 }
-
+{% endhighlight %}
A tensor where type is specified explicitly with a single indexed dimension x representing a vector:
-
-tensor<float>(x[3]):{ {x:0}:3.0, {x:1}:5.0, {x:2}:7.0 }
-
+{% highlight vespa-ranking-expression %}
+tensor(x[3]):{ {x:0}:3.0, {x:1}:5.0, {x:2}:7.0 }
+{% endhighlight %}
A tensor with a type using the default value type (double) and quoted labels:
-
+{% highlight vespa-ranking-expression %}
tensor(key{}):{ {key:'key.1'}:3.0, {key:'key 2'}:5.0, {key:"key's"}:7.0 }
-
+{% endhighlight %}
@@ -176,23 +182,23 @@
A float 1d tensor in indexed form:
-
-tensor<float>(x[3]):[3.0, 5.0, 7.0]
-
+{% highlight vespa-ranking-expression %}
+tensor(x[3]):[3.0, 5.0, 7.0]
+{% endhighlight %}
A matrix in indexed form. Since the values for the right-most dimension (y) are adjacent,
the value 3 is here assigned to the cell {x:0,y:2}:
-
-tensor<float>(x[2],y[3]):[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
-
+{% highlight vespa-ranking-expression %}
+tensor(x[2],y[3]):[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
+{% endhighlight %}
Deprecated:
Since inner brackets can be omitted, the above is equivalent to
-
-tensor<float>(x[2],y[3]):[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
-
+{% highlight vespa-ranking-expression %}
+tensor(x[2],y[3]):[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
+{% endhighlight %}
@@ -207,9 +213,9 @@
0B22038405FF
which would be equivalent to:
-
+{% highlight vespa-ranking-expression %}
[[11, 34, 3], [-124, 5, -1]]
-
+{% endhighlight %}
@@ -220,9 +226,9 @@
-
-tensor<float>(key{}):{ key1:1.0, key2:2.0 }
-
+{% highlight vespa-ranking-expression %}
+tensor(key{}):{ key1:1.0, key2:2.0 }
+{% endhighlight %}
@@ -234,10 +240,10 @@
A map of matrices:
-
-tensor<float>(key{},x[2],y[3]):{ key1:[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
+{% highlight vespa-ranking-expression %}
+tensor(key{},x[2],y[3]):{ key1:[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
key2:[[1.1, 2.1, 3.1], [4.1, 5.1, 6.1]] }
-
+{% endhighlight %}
This may even be combined with a hexadecimal format for the dense subspace:
tensor<int8>(key{},x[5]):{ key1: 0102030405, key2: fffefdfcfb }
@@ -250,16 +256,17 @@
in alphabetic order, so the nesting will follow a consistent
ordering.
-
+{% highlight vespa-ranking-expression %}
tensor(category{},key{},x[2],y[3]):{
cat1:{key1:[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
key2:[[1.1, 2.1, 3.1], [4.1, 5.1, 6.1]]},
cat2:{key1:[[7.3, 8.3, 9.3], [7.0, 8.0, 9.0]],
key3:[[7.5, 8.5, 9.5], [7.9, 8.9, 9.9]]}
}
-
+{% endhighlight %}
the equivalent fully-specified literal form would be
-{% raw %}
+{% highlight vespa-ranking-expression %}
+{% raw %}
tensor(category{},key{},x[2],y[3]):{{category:cat1, key:key1, x:0, y:0}: 1.0,
{category:cat1, key:key1, x:0, y:1}: 2.0,
{category:cat1, key:key1, x:0, y:2}: 3.0,
@@ -284,7 +291,8 @@
{category:cat2, key:key3, x:1, y:0}: 7.9,
{category:cat2, key:key3, x:1, y:1}: 8.9,
{category:cat2, key:key3, x:1, y:2}: 9.9}
-{% endraw %}
+{% endraw %}
+{% endhighlight %}
Tensor functions