The commit 2e2b576 breaks this piece of code.
I implemented a pyo3 function that uses a template to generate code for different numpy data types.
I used a match expression based on the value of a numpy::DataType variable:
[pyfunction]
pub fn generic_test(input: &PyAny) -> PyResult<PyObject> {
let (dtype, shape) = pick_array_info(input)?;
if shape.len() > 1 {
return Err(PyValueError::new_err(
"`input` must have only one dimension",
));
}
macro_rules! implementation {
($dtype:ident) => {{
let array: &PyArray1<$dtype> = convert_to_array(input);
println!("Got {}", stringify!($dtype));
let result = my_reduce(array);
let gil = Python::acquire_gil();
let py = gil.python();
let result_to_py = PyArray1::from_slice(py, &[result]);
Ok(result_to_py.to_object(py))
}};
}
return match dtype {
DataType::Bool => implementation!(u8),
DataType::Int8 => implementation!(i8),
[ . . . ]
DataType::Float64 => implementation!(f64)
};
Since the numpy::DataType has been dropped in v0.16, I wonder what's the best way achieve this behavior.
The commit 2e2b576 breaks this piece of code.
I implemented a
pyo3function that uses a template to generate code for different numpy data types.I used a match expression based on the value of a
numpy::DataTypevariable:Since the
numpy::DataTypehas been dropped in v0.16, I wonder what's the best way achieve this behavior.