mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Use inline instead of anon namespace for stableivalue from/to (#164882)
Fixes https://github.com/pytorch/pytorch/issues/163343. After some consideration, I propose we remove the anonymous namespace around from/to in favor of: 1. Adding inline to the function implementations, assuming that they will not change in the near future 2. If we decide to change them, we will wrap the code in inline versioned namespaces such that the implementations within any versioned namespace will be guaranteed identical. Note that: - We eventually intend to abstract away usage of `from`/`to` (related: @lw's TORCH_BOX work) - The from/to implementations are now powered through class template specializations, where adding a specialization does not change the from/to signatures. I do plan to deprecate top-level from/to in favor of torch::stable::details::from/to consequently. This way we can stop polluting the global namespace. Pull Request resolved: https://github.com/pytorch/pytorch/pull/164882 Approved by: https://github.com/lw, https://github.com/albanD
This commit is contained in:
parent
b20deec3d1
commit
4c963a68d7
|
|
@ -9,10 +9,6 @@
|
|||
|
||||
#include <optional>
|
||||
|
||||
// use anonymous namespace to avoid collisions between differing
|
||||
// versions of this file that may be included by different sources
|
||||
namespace {
|
||||
|
||||
// forward declare so that the from/to() implementations in the detail
|
||||
// namespace of library.h where the real work is done can compile.
|
||||
template <typename T>
|
||||
|
|
@ -322,28 +318,26 @@ struct ToImpl<torch::stable::Tensor> {
|
|||
|
||||
// Expose the partially templated class functions through single functions
|
||||
template <typename T>
|
||||
StableIValue from(T val) {
|
||||
inline StableIValue from(T val) {
|
||||
return detail::FromImpl<T>::call(val);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
StableIValue from(const std::optional<T>& val) {
|
||||
inline StableIValue from(const std::optional<T>& val) {
|
||||
return detail::FromImpl<std::optional<T>>::call(val);
|
||||
}
|
||||
|
||||
// The below overload is used! See https://godbolt.org/z/859cshxrW
|
||||
// We are suppressing the warning for versions clang12- and gcc11-
|
||||
[[maybe_unused]] StableIValue from(const torch::stable::Tensor& val) {
|
||||
[[maybe_unused]] inline StableIValue from(const torch::stable::Tensor& val) {
|
||||
return detail::FromImpl<torch::stable::Tensor>::call(val);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T to(StableIValue val) {
|
||||
inline T to(StableIValue val) {
|
||||
return detail::ToImpl<T>::call(val);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// end to helpers for converting between StableIValue and T
|
||||
// =============================================================================
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user