1# Lint as: python2, python3 2# Copyright 2020 The TensorFlow Authors. All Rights Reserved. 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"""Schema utilities to get builtin code from operator code.""" 17 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import print_function 21 22from tensorflow.python.util import all_util 23 24 25def get_builtin_code_from_operator_code(opcode): 26 """Return the builtin code of the given operator code. 27 28 The following method is introduced to resolve op builtin code shortage 29 problem. The new builtin operator will be assigned to the extended builtin 30 code field in the flatbuffer schema. Those methods helps to hide builtin code 31 details. 32 33 Args: 34 opcode: Operator code. 35 36 Returns: 37 The builtin code of the given operator code. 38 """ 39 # Access BuiltinCode() method first if available. 40 if hasattr(opcode, 'BuiltinCode') and callable(opcode.BuiltinCode): 41 return max(opcode.BuiltinCode(), opcode.DeprecatedBuiltinCode()) 42 43 return max(opcode.builtinCode, opcode.deprecatedBuiltinCode) 44 45 46_allowed_symbols = [ 47 'get_builtin_code_from_operator_code', 48] 49 50all_util.remove_undocumented(__name__, _allowed_symbols) 51