apply Class — pytorch Architecture
Architecture documentation for the apply class in Variadic.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/core/Variadic.h lines 18–90
template <typename F>
struct IterArgs {
template <typename... Args>
inline F& apply() {
return self();
}
// NB: Use perfect forwarding here, otherwise we'll make value
// copies of all arguments!
template <typename T, typename... Args>
inline F& apply(T&& arg, Args&&... args) {
self()(std::forward<T>(arg));
if (self().short_circuit()) {
return self();
} else {
return apply(std::forward<Args>(args)...);
}
}
// Here are some handy overloads which provide sensible
// defaults for container-like structures that one might
// be interested in recursing into. You can enable them
// by adding:
//
// using IterArgs<YourStructName>::operator()
//
// to your struct. These are not enabled by default because
// you may be able to process these structures more efficiently
// than handling them one-by-one.
template <typename T>
void operator()(c10::IListRef<T> args) {
for (const auto& arg : args) {
self()(arg);
if (self().short_circuit())
return;
}
}
template <typename T>
void operator()(at::ArrayRef<T> args) {
for (const auto& arg : args) {
self()(arg);
if (self().short_circuit())
return;
}
}
template <typename T>
void operator()(const torch::List<T>& args) {
for (const auto& arg : args) {
self()(arg);
if (self().short_circuit())
return;
}
}
// NB: we need to specify std::vector manually as C++ won't
// do an implicit conversion to make a template deduction go through.
template <typename T>
void operator()(const std::vector<T>& args) {
self()(at::ArrayRef<T>{args});
}
constexpr bool short_circuit() const {
return false;
}
private:
inline F& self() {
return *static_cast<F*>(this);
}
};
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free