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"""Dtypes and utilities""" 16 17from ..common.dtype import (int8, int16, int32, int64, uint8, uint16, uint32, uint64, 18 float16, float32, float64, bool_) 19 20# original numpy has int->int64, float->float64, uint->uint64 mapping. we map 21# them to 32 bit, since 64 bit calculation is not supported from mindspore 22# backend for now. 23 24inf = float('inf') 25PINF = float('inf') 26NINF = float('-inf') 27nan = float('nan') 28# all three of inf, PINF, and NINF are defined in the original numpy, and as we aim for 29# consistency same thing is done here 30pi = 3.141592653589793 31 32int_ = int32 33uint = uint32 34float_ = float32 35 36numeric_types = [ 37 'int_', 38 'int8', 39 'int16', 40 'int32', 41 'int64', 42 'uint8', 43 'uint16', 44 'uint32', 45 'uint64', 46 'float_', 47 'float16', 48 'float32', 49 'float64', 50 'bool_'] 51 52dtype_tuple = ( 53 int_, 54 int8, 55 int16, 56 int32, 57 int64, 58 uint, 59 uint8, 60 uint16, 61 uint32, 62 uint64, 63 float_, 64 float16, 65 float32, 66 float64, 67 bool_) 68 69dtype_map = { 70 'int': int_, 71 'int8': int8, 72 'int16': int16, 73 'int32': int32, 74 'int64': int64, 75 'uint': uint, 76 'uint8': uint8, 77 'uint16': uint16, 78 'uint32': uint32, 79 'uint64': uint64, 80 'float': float_, 81 'float16': float16, 82 'float32': float32, 83 'float64': float64, 84 'bool': bool_ 85} 86 87all_types = [ 88 'np.int', 89 'np.int8', 90 'np.int16', 91 'np.int32', 92 'np.int64', 93 'np.uint', 94 'np.uint8', 95 'np.uint16', 96 'np.uint32', 97 'np.uint64', 98 'np.float', 99 'np.float16', 100 'np.float32', 101 'np.float64', 102 'np.bool'] 103 104promotion_rule = { 105 (uint8, uint16): uint16, 106 (uint8, uint32): uint32, 107 (uint8, uint64): uint64, 108 (uint16, uint32): uint32, 109 (uint16, uint64): uint64, 110 (uint32, uint64): uint64, 111 (uint8, int8): int16, 112 (uint8, int16): int16, 113 (uint8, int32): int32, 114 (uint8, int64): int64, 115 (uint16, int8): int32, 116 (uint16, int16): int32, 117 (uint16, int32): int32, 118 (uint16, int64): int64, 119 (uint32, int8): int64, 120 (uint32, int16): int64, 121 (uint32, int32): int64, 122 (uint32, int64): int64, 123 (uint64, int8): float64, 124 (uint64, int16): float64, 125 (uint64, int32): float64, 126 (uint64, int64): float64, 127 (uint8, float16): float16, 128 (uint8, float32): float32, 129 (uint8, float64): float64, 130 (uint16, float16): float16, 131 (uint16, float32): float32, 132 (uint16, float64): float32, 133 (uint32, float16): float16, 134 (uint32, float32): float32, 135 (uint32, float64): float64, 136 (uint64, float16): float16, 137 (uint64, float32): float32, 138 (uint64, float64): float64, 139 (int8, int16): int16, 140 (int8, int32): int32, 141 (int8, int64): int64, 142 (int16, int32): int32, 143 (int16, int64): int64, 144 (int32, int64): int64, 145 (int8, float16): float16, 146 (int8, float32): float32, 147 (int8, float64): float64, 148 (int16, float16): float16, 149 (int16, float32): float32, 150 (int16, float64): float64, 151 (int32, float16): float16, 152 (int32, float32): float32, 153 (int32, float64): float64, 154 (int64, float16): float16, 155 (int64, float32): float32, 156 (int64, float64): float64, 157 (float16, float32): float32, 158 (float16, float64): float64, 159 (float32, float64): float64, 160 (bool_, uint8): uint8, 161 (bool_, uint16): uint16, 162 (bool_, uint32): uint32, 163 (bool_, uint64): uint64, 164 (bool_, int8): int8, 165 (bool_, int16): int16, 166 (bool_, int32): int32, 167 (bool_, int64): int64, 168 (bool_, float16): float16, 169 (bool_, float32): float32, 170 (bool_, float64): float64, 171} 172 173rule_for_trigonometric = {float16: float16, 174 float32: float32, 175 float64: float64, 176 int8: float16, 177 int16: float32, 178 int32: float32, 179 int64: float32, 180 uint8: float16, 181 uint16: float32, 182 uint32: float32, 183 uint64: float32, 184 bool_: float16} 185