1#
2# Copyright (C) 2018 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17lookups = 3
18rows = 3
19columns = 2
20features = 4
21
22actual_values = [x for x in range(rows * columns * features)]
23for i in range(rows):
24  for j in range(columns):
25    for k in range(features):
26      actual_values[(i * columns + j) * features + k] = i + j / 10. + k / 100.
27
28model = Model()
29index = Input("index", "TENSOR_INT32", "{%d}"%lookups)
30value = Input("value", "TENSOR_FLOAT32", "{%d, %d, %d}" % (rows, columns, features))
31output = Output("output", "TENSOR_FLOAT32", "{%d, %d, %d}" % (lookups, columns, features))
32model = model.Operation("EMBEDDING_LOOKUP", index, value).To(output)
33model = model.RelaxedExecution(True)
34
35input0 = {index: [1, 0, 2],
36          value: actual_values}
37
38output0 = {output:
39           [
40               1.00, 1.01, 1.02, 1.03, 1.10, 1.11, 1.12, 1.13,  # Row 1
41               0.00, 0.01, 0.02, 0.03, 0.10, 0.11, 0.12, 0.13,  # Row 0
42               2.00, 2.01, 2.02, 2.03, 2.10, 2.11, 2.12, 2.13,  # Row 2
43           ]}
44
45# Instantiate an example
46Example((input0, output0))
47