Convert a numpy array of float to a numpy array of bf16 in uint16
(arr)
| 116 | num_thread = 8 |
| 117 | |
| 118 | def np_float2np_bf16(arr): |
| 119 | """Convert a numpy array of float to a numpy array |
| 120 | of bf16 in uint16""" |
| 121 | orig = arr.view("<u4") |
| 122 | bias = np.bitwise_and(np.right_shift(orig, 16), 1) + 0x7FFF |
| 123 | return np.right_shift(orig + bias, 16).astype("uint16") |
| 124 | |
| 125 | def np_bf162np_float(arr): |
| 126 | """Convert a numpy array of bf16 (uint16) to a numpy array |
no test coverage detected
searching dependent graphs…