Caffe2 - C++ API
A deep learning, cross platform ML framework
input-archive.h
1 #pragma once
2 
3 #include <c10/util/Optional.h>
4 #include <c10/core/Device.h>
5 #include <torch/csrc/WindowsTorchApiMacro.h>
6 #include <torch/types.h>
7 
8 #include <iosfwd>
9 #include <memory>
10 #include <string>
11 #include <utility>
12 
13 namespace at {
14 class Tensor;
15 } // namespace at
16 
17 namespace torch {
18 using at::Tensor;
19 namespace jit {
20 namespace script {
21 struct Module;
22 } // namespace script
23 } // namespace jit
24 } // namespace torch
25 
26 namespace torch {
27 namespace serialize {
28 
32 class TORCH_API InputArchive final {
33  public:
35  InputArchive();
36 
37  // Move is allowed.
38  InputArchive(InputArchive&&) = default;
39  InputArchive& operator=(InputArchive&&) = default;
40 
41  // Copy is disallowed.
42  InputArchive(InputArchive&) = delete;
43  InputArchive& operator=(InputArchive&) = delete;
44 
45  ~InputArchive() = default;
46 
50  void read(const std::string& key, Tensor& tensor, bool is_buffer = false);
51 
55  void read(const std::string& key, InputArchive& archive);
56 
60  void load_from(const std::string& filename,
61  c10::optional<torch::Device> device = c10::nullopt);
62 
66  void load_from(std::istream& stream,
67  c10::optional<torch::Device> device = c10::nullopt);
68 
72  template <typename... Ts>
73  void operator()(Ts&&... ts) {
74  read(std::forward<Ts>(ts)...);
75  }
76 
77  private:
78  std::shared_ptr<jit::script::Module> module_;
79 };
80 } // namespace serialize
81 } // namespace torch
void operator()(Ts &&...ts)
Forwards all arguments to read().
Definition: input-archive.h:73
Definition: jit_type.h:17
Flush-To-Zero and Denormals-Are-Zero mode.
A recursive representation of tensors that can be deserialized from a file or stream.
Definition: input-archive.h:32