Caffe2 - C++ API
A deep learning, cross platform ML framework
serialize.cpp
1 #include <torch/optim/serialize.h>
2 
3 #include <torch/serialize/archive.h>
4 #include <torch/types.h>
5 
6 #include <cstddef>
7 #include <cstdint>
8 #include <deque>
9 #include <string>
10 #include <vector>
11 
12 namespace torch {
13 namespace optim {
14 void serialize(
15  serialize::OutputArchive& archive,
16  const std::string& key,
17  const std::vector<int64_t>& steps) {
18  std::vector<torch::Tensor> tensors;
19  tensors.reserve(steps.size());
20  for (const auto& step : steps) {
21  tensors.push_back(torch::tensor(static_cast<int64_t>(step)));
22  }
23  serialize(archive, key, tensors);
24 }
25 
26 void serialize(
27  serialize::InputArchive& archive,
28  const std::string& key,
29  std::vector<int64_t>& steps) {
30  steps.clear();
31  std::vector<torch::Tensor> tensors;
32  serialize(archive, key, tensors);
33  for (const auto& step : tensors) {
34  steps.push_back(step.item<int64_t>());
35  }
36 }
37 } // namespace optim
38 } // namespace torch
Definition: jit_type.h:17