1 | #include <c10/core/TensorOptions.h> |
2 | |
3 | #include <c10/core/Device.h> |
4 | #include <c10/core/Layout.h> |
5 | #include <c10/core/ScalarType.h> |
6 | #include <c10/util/Optional.h> |
7 | |
8 | #include <iostream> |
9 | |
10 | namespace c10 { |
11 | |
12 | // Note: TensorOptions properties are all optional, but (almost) all have |
13 | // getters that supply a default when the corresponding property is missing. |
14 | // Here we print the values returned by the default-supplying getters for |
15 | // properties that have them, along with an annotation if the value is |
16 | // returned by default. This gives the full picture of both the object's |
17 | // internal state and what its getters will return. |
18 | |
19 | std::ostream& operator<<(std::ostream& stream, const TensorOptions& options) { |
20 | auto print = [&](const char* label, auto prop, bool has_prop) { |
21 | stream << label << std::boolalpha << prop << (has_prop ? "" : " (default)" ); |
22 | }; |
23 | |
24 | print("TensorOptions(dtype=" , options.dtype(), options.has_dtype()); |
25 | print(", device=" , options.device(), options.has_device()); |
26 | print(", layout=" , options.layout(), options.has_layout()); |
27 | print( |
28 | ", requires_grad=" , options.requires_grad(), options.has_requires_grad()); |
29 | print( |
30 | ", pinned_memory=" , options.pinned_memory(), options.has_pinned_memory()); |
31 | |
32 | // note: default-supplying memory_format() getter not provided; no canonical |
33 | // default |
34 | stream << ", memory_format=" ; |
35 | if (options.has_memory_format()) { |
36 | stream << *options.memory_format_opt(); |
37 | } else { |
38 | stream << "(nullopt)" ; |
39 | } |
40 | stream << ")" ; |
41 | |
42 | return stream; |
43 | } |
44 | |
45 | } // namespace c10 |
46 | |