1 # 2 # Copyright (C) 2017 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 17 lookups = 4 18 keys = 3 19 rows = 3 20 features = 2 21 22 table = [x for x in range(rows * features)] 23 for i in range(rows): 24 for j in range(features): 25 table[i * features + j] = i + j / 10. 26 27 model = Model() 28 29 lookup = Input("lookup", "TENSOR_INT32", "{%d}" % lookups) 30 key = Input("key", "TENSOR_INT32", "{%d}" % (keys)) 31 value = Input("value", "TENSOR_FLOAT32", "{%d, %d}" % (rows, features)) 32 output = Output("output", "TENSOR_FLOAT32", "{%d, %d}" % (lookups, features)) 33 hits = Output("hits", "TENSOR_QUANT8_ASYMM", "{%d}, 1.f, 0" % (lookups)) 34 model = model.Operation("HASHTABLE_LOOKUP", lookup, key, value).To([output, hits]) 35 36 input0 = {lookup: [1234, -292, -11, 0], 37 key: [-11, 0, 1234], 38 value: table} 39 40 output0 = {output: 41 [ 42 2.0, 2.1, # 2-rd item 43 0, 0, # Not found 44 0.0, 0.1, # 0-th item 45 1.0, 1.1, # 1-st item 46 ], 47 hits: 48 [ 49 1, 0, 1, 1, 50 ] 51 } 52 53 # Instantiate an example 54 Example((input0, output0)) 55