|
22 | 22 | /// This file defines functions of dpctl.tensor._tensor_impl extensions,
|
23 | 23 | /// specifically functions for elementwise operations.
|
24 | 24 | //===----------------------------------------------------------------------===//
|
25 |
| - |
26 | 25 | #pragma once
|
27 | 26 |
|
28 | 27 | #include "dpctl4pybind11.hpp"
|
|
38 | 37 | #include "utils/offset_utils.hpp"
|
39 | 38 | #include "utils/type_dispatch.hpp"
|
40 | 39 |
|
| 40 | +namespace td_ns = dpctl::tensor::type_dispatch; |
| 41 | + |
| 42 | +static inline py::dtype _dtype_from_typenum(td_ns::typenum_t dst_typenum_t) |
| 43 | +{ |
| 44 | + switch (dst_typenum_t) { |
| 45 | + case td_ns::typenum_t::BOOL: |
| 46 | + return py::dtype("?"); |
| 47 | + case td_ns::typenum_t::INT8: |
| 48 | + return py::dtype("i1"); |
| 49 | + case td_ns::typenum_t::UINT8: |
| 50 | + return py::dtype("u1"); |
| 51 | + case td_ns::typenum_t::INT16: |
| 52 | + return py::dtype("i2"); |
| 53 | + case td_ns::typenum_t::UINT16: |
| 54 | + return py::dtype("u2"); |
| 55 | + case td_ns::typenum_t::INT32: |
| 56 | + return py::dtype("i4"); |
| 57 | + case td_ns::typenum_t::UINT32: |
| 58 | + return py::dtype("u4"); |
| 59 | + case td_ns::typenum_t::INT64: |
| 60 | + return py::dtype("i8"); |
| 61 | + case td_ns::typenum_t::UINT64: |
| 62 | + return py::dtype("u8"); |
| 63 | + case td_ns::typenum_t::HALF: |
| 64 | + return py::dtype("f2"); |
| 65 | + case td_ns::typenum_t::FLOAT: |
| 66 | + return py::dtype("f4"); |
| 67 | + case td_ns::typenum_t::DOUBLE: |
| 68 | + return py::dtype("f8"); |
| 69 | + case td_ns::typenum_t::CFLOAT: |
| 70 | + return py::dtype("c8"); |
| 71 | + case td_ns::typenum_t::CDOUBLE: |
| 72 | + return py::dtype("c16"); |
| 73 | + default: |
| 74 | + throw py::value_error("Unrecognized dst_typeid"); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +static inline int _result_typeid(int arg_typeid, const int *fn_output_id) |
| 79 | +{ |
| 80 | + if (arg_typeid < 0 || arg_typeid >= td_ns::num_types) { |
| 81 | + throw py::value_error("Input typeid " + std::to_string(arg_typeid) + |
| 82 | + " is outside of expected bounds."); |
| 83 | + } |
| 84 | + |
| 85 | + return fn_output_id[arg_typeid]; |
| 86 | +} |
| 87 | + |
41 | 88 | namespace dpctl
|
42 | 89 | {
|
43 | 90 | namespace tensor
|
44 | 91 | {
|
45 | 92 | namespace py_internal
|
46 | 93 | {
|
47 | 94 |
|
48 |
| -namespace td_ns = dpctl::tensor::type_dispatch; |
49 |
| - |
50 |
| -extern py::dtype _dtype_from_typenum(td_ns::typenum_t dst_typenum_t); |
51 |
| -extern int _result_typeid(int arg_typeid, const int *fn_output_id); |
52 |
| - |
53 | 95 | template <typename output_typesT,
|
54 | 96 | typename contig_dispatchT,
|
55 | 97 | typename strided_dispatchT>
|
@@ -825,8 +867,6 @@ py_binary_inplace_ufunc(const dpctl::tensor::usm_ndarray &lhs,
|
825 | 867 | strided_fn_ev);
|
826 | 868 | }
|
827 | 869 |
|
828 |
| -extern void init_elementwise_functions(py::module_ m); |
829 |
| - |
830 | 870 | } // namespace py_internal
|
831 | 871 | } // namespace tensor
|
832 | 872 | } // namespace dpctl
|
0 commit comments