Caffe2 - C++ API
A deep learning, cross platform ML framework
edge.h
1 #pragma once
2 
3 #include <cstdint>
4 #include <functional>
5 #include <memory>
6 
7 #include <torch/csrc/utils/hash.h>
8 
9 namespace torch { namespace autograd {
10 
11 struct Function;
12 
14 struct Edge {
15  Edge() noexcept : function(nullptr), input_nr(0) {}
16 
17  Edge(std::shared_ptr<Function> function_, uint32_t input_nr_) noexcept
18  : function(std::move(function_)), input_nr(input_nr_) {}
19 
21  bool is_valid() const noexcept {
22  return function != nullptr;
23  }
24 
25  // Required for use in associative containers.
26  bool operator==(const Edge& other) const noexcept {
27  return this->function == other.function && this->input_nr == other.input_nr;
28  }
29 
30  bool operator!=(const Edge& other) const noexcept {
31  return !(*this == other);
32  }
33 
35  std::shared_ptr<Function> function;
36 
38  uint32_t input_nr;
39 };
40 }} // namespace torch::autograd
41 
42 // The idiomatic way of enabling use of a custom type as the key of hash
43 // containers in C++11. This method removes the requirement of having to pass
44 // a custom hasher to std::unordered_{map, set}.
45 // See http://en.cppreference.com/w/cpp/utility/hash for more information.
46 namespace std {
47 template <>
48 struct hash<torch::autograd::Edge> {
49  // These type aliases are required by the standard.
51  using return_type = size_t;
52  return_type operator()(const argument_type& edge) const noexcept {
53  return torch::get_hash(edge.function, edge.input_nr);
54  }
55 };
56 } // namespace std
bool is_valid() const noexcept
Convenience method to test if an edge is valid.
Definition: edge.h:21
Represents a particular input of a function.
Definition: edge.h:14
uint32_t input_nr
The identifier of a particular input to the function.
Definition: edge.h:38
std::shared_ptr< Function > function
The function this Edge points to.
Definition: edge.h:35
Definition: jit_type.h:17