2019-08-13 19:03:22 +00:00
|
|
|
#include <c10/core/TensorOptions.h>
|
2018-06-25 04:15:09 +00:00
|
|
|
|
2019-01-11 00:06:27 +00:00
|
|
|
#include <c10/core/Device.h>
|
2018-12-04 05:48:47 +00:00
|
|
|
#include <c10/core/Layout.h>
|
2018-11-27 20:43:22 +00:00
|
|
|
#include <c10/util/Optional.h>
|
2018-06-25 04:15:09 +00:00
|
|
|
|
2018-07-23 22:06:10 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2018-12-06 23:52:15 +00:00
|
|
|
namespace c10 {
|
2018-06-25 04:15:09 +00:00
|
|
|
|
2020-04-03 21:57:24 +00:00
|
|
|
// Note: TensorOptions properties are all optional, but (almost) all have
|
|
|
|
|
// getters that supply a default when the corresponding property is missing.
|
|
|
|
|
// Here we print the values returned by the default-supplying getters for
|
|
|
|
|
// properties that have them, along with an annotation if the value is
|
|
|
|
|
// returned by default. This gives the full picture of both the object's
|
|
|
|
|
// internal state and what its getters will return.
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& stream, const TensorOptions& options) {
|
|
|
|
|
auto print = [&](const char* label, auto prop, bool has_prop) {
|
|
|
|
|
stream << label << std::boolalpha << prop << (has_prop ? "" : " (default)");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
print("TensorOptions(dtype=", options.dtype(), options.has_dtype());
|
|
|
|
|
print(", device=", options.device(), options.has_device());
|
|
|
|
|
print(", layout=", options.layout(), options.has_layout());
|
|
|
|
|
print(
|
|
|
|
|
", requires_grad=", options.requires_grad(), options.has_requires_grad());
|
|
|
|
|
print(
|
|
|
|
|
", pinned_memory=", options.pinned_memory(), options.has_pinned_memory());
|
|
|
|
|
|
|
|
|
|
// note: default-supplying memory_format() getter not provided; no canonical
|
|
|
|
|
// default
|
|
|
|
|
stream << ", memory_format=";
|
|
|
|
|
if (options.has_memory_format()) {
|
2023-11-30 00:56:06 +00:00
|
|
|
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
|
2020-04-03 21:57:24 +00:00
|
|
|
stream << *options.memory_format_opt();
|
|
|
|
|
} else {
|
|
|
|
|
stream << "(nullopt)";
|
|
|
|
|
}
|
|
|
|
|
stream << ")";
|
|
|
|
|
|
|
|
|
|
return stream;
|
2018-07-23 22:06:10 +00:00
|
|
|
}
|
2018-08-31 21:16:53 +00:00
|
|
|
|
2018-12-06 23:52:15 +00:00
|
|
|
} // namespace c10
|