Home | History | Annotate | Download | only in V1_0
      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 * 10 + j
     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_QUANT8_ASYMM", "{%d, %d}, 0.5f, 0" % (rows, features))
     32 output = Output("output", "TENSOR_QUANT8_ASYMM", "{%d, %d}, 0.5f, 0" % (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:  [123, 250, 255, 0],
     37           key: [0, 123, 255],
     38           value: table}
     39 
     40 output0 = {output:
     41            [
     42                10, 11, # 2nd item
     43                0, 0,   # Not found
     44                20, 21, # 1st item
     45                0, 1,   # 0th item
     46            ],
     47            hits:
     48            [
     49                1, 0, 1, 1,
     50            ]
     51 }
     52 
     53 # Instantiate an example
     54 Example((input0, output0))
     55