TypeMeta

See

struct TypeMeta contains only a single int16_t data member:

./code/type-meta/main.cc (Check size)
1static void TestSize() {
2  static_assert(sizeof(caffe2::TypeMeta) == sizeof(int16_t), "");
3}

Constructors

./code/type-meta/main.cc (Make)
 1static void TestConstructor() {
 2  caffe2::TypeMeta t = caffe2::TypeMeta::Make<int32_t>();
 3  TORCH_CHECK(t.Match<int32_t>());
 4
 5  TORCH_CHECK(t.isScalarType());
 6
 7  TORCH_CHECK(t.isScalarType(torch::kInt));
 8  TORCH_CHECK(t.isScalarType(torch::kFloat) == false);
 9
10  TORCH_CHECK(t.name() == "int");
11}

Operations with ScalarType

./code/type-meta/main.cc (Operations with ScalarType)
 1static void TestFromScalarType() {
 2  caffe2::TypeMeta t = caffe2::TypeMeta::fromScalarType(torch::kDouble);
 3
 4  TORCH_CHECK(t.isScalarType(torch::kDouble));
 5  TORCH_CHECK(t.name() == "double");
 6
 7  TORCH_CHECK(t.toScalarType() == torch::kDouble);
 8  TORCH_CHECK(t == torch::kDouble);
 9  TORCH_CHECK(t != torch::kFloat);
10  TORCH_CHECK(torch::kInt != t);