Caffe2 - C++ API
A deep learning, cross platform ML framework
Functions.h
1 #pragma once
2 
3 // ${generated_comment}
4 
5 #include <ATen/ATen.h>
6 #include <ATen/core/functional.h>
7 #include <ATen/TensorGeometry.h>
8 
9 #include "torch/csrc/THP_export.h"
10 #include "torch/csrc/autograd/function.h"
11 #include "torch/csrc/autograd/variable.h"
12 #include "torch/csrc/autograd/saved_variable.h"
13 
14 namespace torch { namespace autograd { namespace generated {
15 
16 using at::Scalar;
17 using at::Tensor;
18 using at::IntArrayRef;
19 using at::Type;
20 using at::TensorGeometry;
21 using at::ScalarType;
22 using c10::optional;
23 using c10::fmap;
24 
25 inline std::vector<Tensor> unpack_list(at::ArrayRef<SavedVariable> xs) {
26  // NB: we must explicitly do the conversion in the lambda, otherwise template
27  // deduction will give a Tensor of Variable which is not convertible
28  return fmap(xs, [](const SavedVariable& x) {
29  return static_cast<Tensor>(x.unpack());
30  });
31 }
32 
33 struct TypeAndSize {
34  TypeAndSize() : type(nullptr) {}
35  /* implicit */
36  TypeAndSize(const Tensor & t)
37  : sizes(t.sizes().vec())
38  , type(&t.type()) {}
39 
40  Tensor zeros() { return at::zeros(sizes, *type); }
41 
42 private:
43  std::vector<int64_t> sizes;
44  Type* type;
45 };
46 
47 ${autograd_function_declarations}
48 
49 }}} // namespace torch::autograd::generated
Scalar represents a 0-dimensional tensor which contains a single element.
Definition: Scalar.h:22
Definition: Type.h:107
Definition: jit_type.h:17