1297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#
2297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# Copyright (C) 2017 The Android Open Source Project
3297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#
4297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# Licensed under the Apache License, Version 2.0 (the "License");
5297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# you may not use this file except in compliance with the License.
6297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# You may obtain a copy of the License at
7297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#
8297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#      http://www.apache.org/licenses/LICENSE-2.0
9297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#
10297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# Unless required by applicable law or agreed to in writing, software
11297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# distributed under the License is distributed on an "AS IS" BASIS,
12297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# See the License for the specific language governing permissions and
14297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# limitations under the License.
15297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung#
16297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
17297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungnum_input = 3
18297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungnum_hash = 4
19297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungnum_bits = 2
20297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
21297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungmodel = Model()
22297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
23297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sunghhash = Parameter("hash", "TENSOR_FLOAT32", "{%d, %d}" % (num_hash, num_bits),
24297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung                  [0.123, 0.456, -0.321, -0.654, 1.234, 5.678, -4.321, -8.765])
25297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sunglookup = Input("lookup", "TENSOR_INT32", "{%d, %d}" % (num_input, num_bits))
26297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungweight = Input("weight", "TENSOR_FLOAT32", "{%d}" % (num_input))
27297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungtype_param = Int32Scalar("type_param", 1)  # SPARSE
28bee07f73a5f998a2dd6dc581e7776557c21f9684Miao Wangoutput = Output("output", "TENSOR_INT32", "{%d}" % (num_hash))
29297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungmodel = model.Operation("LSH_PROJECTION", hhash, lookup, weight,
30297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung                        type_param).To(output)
31297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
32297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# Omit weight, since this is a sparse projection, for which the optional weight
33297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung# input should be left unset.
34297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sunginput0 = {
35297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung    lookup: [12345, 54321, 67890, 9876, -12345678, -87654321],
36297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung    weight: [],
37297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung}
38297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
39297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungoutput0 = {output: [1, 2, 2, 0]}
40297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung
41297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) SungExample((input0, output0))
42