Caffe2 - C++ API
A deep learning, cross platform ML framework
output-archive.h
1 #pragma once
2 
3 #include <torch/csrc/WindowsTorchApiMacro.h>
4 
5 #include <iosfwd>
6 #include <memory>
7 #include <string>
8 #include <utility>
9 
10 namespace at {
11 class Tensor;
12 } // namespace at
13 
14 namespace torch {
15 using at::Tensor;
16 namespace jit {
17 namespace script {
18 struct Module;
19 } // namespace script
20 } // namespace jit
21 } // namespace torch
22 
23 namespace torch {
24 namespace serialize {
25 class TORCH_API OutputArchive final {
26  public:
28  OutputArchive();
29 
30  // Move is allowed.
31  OutputArchive(OutputArchive&&) = default;
32  OutputArchive& operator=(OutputArchive&&) = default;
33 
34  // Copy is disallowed.
35  OutputArchive(OutputArchive&) = delete;
36  OutputArchive& operator=(OutputArchive&) = delete;
37 
40  void write(
41  const std::string& key,
42  const Tensor& tensor,
43  bool is_buffer = false);
44 
47  void write(const std::string& key, OutputArchive& nested_archive);
48 
51  void save_to(const std::string& filename);
52 
55  void save_to(std::ostream& stream);
56 
60  template <typename... Ts>
61  void operator()(Ts&&... ts) {
62  write(std::forward<Ts>(ts)...);
63  }
64 
65  private:
66  std::shared_ptr<jit::script::Module> module_;
67 };
68 } // namespace serialize
69 } // namespace torch
void operator()(Ts &&...ts)
Forwards all arguments to write().
Definition: jit_type.h:17
Flush-To-Zero and Denormals-Are-Zero mode.