| 717 | // Performs a NumPy array cast from type 'From' to 'To'. |
| 718 | template <typename From, typename To> |
| 719 | void NPyCast(void* from_void, void* to_void, npy_intp n, void* fromarr, |
| 720 | void* toarr) { |
| 721 | const auto* from = |
| 722 | reinterpret_cast<typename TypeDescriptor<From>::T*>(from_void); |
| 723 | auto* to = reinterpret_cast<typename TypeDescriptor<To>::T*>(to_void); |
| 724 | for (npy_intp i = 0; i < n; ++i) { |
| 725 | to[i] = |
| 726 | static_cast<typename TypeDescriptor<To>::T>(static_cast<To>(from[i])); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // Registers a cast between bfloat16 and type 'T'. 'numpy_type' is the NumPy |
| 731 | // type corresponding to 'T'. If 'cast_is_safe', registers that bfloat16 can be |