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