diff --git a/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp b/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp index 65ec0eb33d..75588f9d8c 100644 --- a/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp +++ b/src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp @@ -506,6 +506,55 @@ PYBIND11_MODULE(simplnx, mod) }, "Convert numpy dtype to simplnx DataType", "dtype"_a); + mod.def( + "convert_np_dtype_to_numerictype", + [](const py::dtype& dtype) { + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::int8; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::uint8; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::int16; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::uint16; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::int32; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::uint32; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::int64; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::uint64; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::float32; + } + if((dtype.attr("__eq__")(py::dtype::of())).cast()) + { + return NumericType::float64; + } + + std::string dtypeStr = py::str(static_cast(dtype)); + throw std::invalid_argument(fmt::format("Unable to convert dtype to NumericType: Unsupported dtype '{}'.", dtypeStr)); + }, + "Convert numpy dtype to simplnx NumericType", "dtype"_a); + py::enum_ arrayHandlingType(mod, "ArrayHandlingType"); arrayHandlingType.value("Copy", ArrayHandlingType::Copy); arrayHandlingType.value("Move", ArrayHandlingType::Move); @@ -1530,6 +1579,7 @@ PYBIND11_MODULE(simplnx, mod) mod.def("get_all_data_types", &GetAllDataTypes); mod.def("convert_numeric_type_to_data_type", &ConvertNumericTypeToDataType); + mod.def("convert_data_type_to_numeric_type", &ConvertDataTypeToNumericType); mod.def("get_filters", [corePlugin]() { auto filterHandles = corePlugin->getFilterHandles();