tensorflow/cc/experimental/base/tests/tensorhandle_test.cc
// This test constructs a scalar tensor for each of the types in "SimpleTypes",
// then wraps it in a TensorHandle. We then unwrap it back into a Tensor, and
// verify the expected dims, dtype, value, num bytes, and num elements.
This test constructs a scalar tensor for each of the types in "SimpleTypes",
then wraps it in a TensorHandle. We then unwrap it back into a Tensor, and
verify the expected dims, dtype, value, num bytes, and num elements.
This test constructs a scalar tensor for each of the types in " SimpleTypes " then wraps it in a TensorHandle . We then unwrap it back into a Tensor and verify the expected dims dtype value num bytes and num elements .
TYPED_TEST(ConstructScalarTensorHandleTest,
           ValidTensorAttributesAfterConstruction) {
  Status status;
  RuntimeBuilder runtime_builder;
  std::unique_ptr<Runtime> runtime = runtime_builder.Build(&status);
  ASSERT_TRUE(status.ok()) << status.message();
  TF_DataType dtype = TypeParam::kDType;
  typename TypeParam::type value = 42;
  Tensor original_tensor =
      Tensor::FromBuffer(dtype, {},
                         &value,
                         sizeof(value),
                         [](void*, size_t) {}, &status);
  ASSERT_TRUE(status.ok()) << status.message();
  TensorHandle handle =
      TensorHandle::FromTensor(original_tensor, *runtime, &status);
  ASSERT_TRUE(status.ok()) << status.message();
  Tensor tensor = handle.Resolve(&status);
  ASSERT_TRUE(status.ok()) << status.message();
  EXPECT_EQ(tensor.dims(), 0);
  EXPECT_EQ(tensor.dtype(), dtype);
  EXPECT_EQ(*reinterpret_cast<typename TypeParam::type*>(tensor.data()), 42);
  EXPECT_EQ(tensor.num_bytes(), sizeof(typename TypeParam::type));
  EXPECT_EQ(tensor.num_elements(), 1);
}
TYPED_TEST ( ConstructScalarTensorHandleTest , ValidTensorAttributesAfterConstruction ) { Status status ; RuntimeBuilder runtime_builder ; std :: unique_ptr < Runtime > runtime = runtime_builder . Build ( & status ) ; ASSERT_TRUE ( status . ok ( ) ) << status . message ( ) ; TF_DataType dtype = TypeParam :: kDType ; typename TypeParam :: type value = 42 ; Tensor original_tensor = Tensor :: FromBuffer ( dtype , { } , & value , sizeof ( value ) , [ ] ( void * , size_t ) { } , & status ) ; ASSERT_TRUE ( status . ok ( ) ) << status . message ( ) ; TensorHandle handle = TensorHandle :: FromTensor ( original_tensor , * runtime , & status ) ; ASSERT_TRUE ( status . ok ( ) ) << status . message ( ) ; Tensor tensor = handle . Resolve ( & status ) ; ASSERT_TRUE ( status . ok ( ) ) << status . message ( ) ; EXPECT_EQ ( tensor . dims ( ) , 0 ) ; EXPECT_EQ ( tensor . dtype ( ) , dtype ) ; EXPECT_EQ ( * reinterpret_cast < typename TypeParam :: type * > ( tensor . data ( ) ) , 42 ) ; EXPECT_EQ ( tensor . num_bytes ( ) , sizeof ( typename TypeParam :: type ) ) ; EXPECT_EQ ( tensor . num_elements ( ) , 1 ) ; }
This test constructs a scalar tensor for each of the types in "SimpleTypes",
then wraps it in a TensorHandle.
This test constructs a scalar tensor for each of the types in " SimpleTypes " then wraps it in a TensorHandle .
/*dtype=*/ /*shape=*/ /*data=*/ /*len=*/ /*deleter=*/