Use a macro to handle the dtype pattern matching. (#215)

This commit is contained in:
Laurent Mazare
2023-07-21 17:03:51 +02:00
committed by GitHub
parent a6bcdfb269
commit 4a100875bf
2 changed files with 26 additions and 57 deletions

View File

@ -1660,3 +1660,13 @@ impl BackendDevice for CpuDevice {
Ok(storage)
}
}
#[macro_export]
macro_rules! map_dtype {
($name:expr, $storage:ident, $fn:expr, ($($dtypes:ident),+)) => {
match $storage {
$(CpuStorage::$dtypes(__e) => CpuStorage::$dtypes($fn(__e)),)*
s => Err(Error::UnsupportedDTypeForOp(s.dtype(), $name).bt())?,
}
};
}