1# Copyright 2020-2021 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================ 15 16"""Registry the relation.""" 17 18from __future__ import absolute_import 19from mindspore._c_expression import Tensor as Tensor_ 20 21 22class Registry: 23 """Used for tensor operator registration""" 24 25 def __init__(self): 26 pass 27 28 def get(self, obj_str): 29 """Get property if obj is not vm_compare""" 30 31 if not isinstance(obj_str, str): 32 raise TypeError("key for tensor registry must be string.") 33 if Tensor_._is_test_stub() is True: # pylint: disable=W0212 34 def wrap(*args): 35 new_args = list(args) 36 new_args.append(obj_str) 37 return getattr(self, "vm_compare")(*new_args) 38 39 obj = wrap 40 else: 41 obj = getattr(self, obj_str) 42 return obj 43 44 45tensor_operator_registry = Registry() 46