tensorflow/cc/experimental/base/tests/tensorhandle_test.cc
// This test constructs a 1D tensor for each of the types in "SimpleTypes",
// and verifies the expected dimensions, dtype, value, number of bytes, and
// number of elements.
This test constructs a 1D tensor for each of the types in "SimpleTypes",
and verifies the expected dimensions, dtype, value, number of bytes, and
number of elements.
This test constructs a 1D tensor for each of the types in " SimpleTypes " and verifies the expected dimensions dtype value number of bytes and number of elements .
TYPED_TEST(Construct1DTensorHandleTest,
           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;
  std::vector<typename TypeParam::type> value = {42, 100, 0, 1, 4, 29};
  std::vector<int64_t> shape;
  shape.push_back(value.size());
  Tensor original_tensor = Tensor::FromBuffer(
      dtype, shape,
      value.data(),
      value.size() * sizeof(typename TypeParam::type),
      [](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(), 1);
  EXPECT_EQ(tensor.dtype(), dtype);
  tensorflow::gtl::ArraySlice<typename TypeParam::type> tensor_view(
      reinterpret_cast<typename TypeParam::type*>(tensor.data()), value.size());
  EXPECT_EQ(tensor_view[0], 42);
  EXPECT_EQ(tensor_view[1], 100);
  EXPECT_EQ(tensor_view[2], 0);
  EXPECT_EQ(tensor_view[3], 1);
  EXPECT_EQ(tensor_view[4], 4);
  EXPECT_EQ(tensor_view[5], 29);
  EXPECT_EQ(tensor.num_bytes(),
            value.size() * sizeof(typename TypeParam::type));
  EXPECT_EQ(tensor.num_elements(), value.size());
}
TYPED_TEST ( Construct1DTensorHandleTest , 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 ; std :: vector < typename TypeParam :: type > value = { 42 , 100 , 0 , 1 , 4 , 29 } ; std :: vector < int64_t > shape ; shape . push_back ( value . size ( ) ) ; Tensor original_tensor = Tensor :: FromBuffer ( dtype , shape , value . data ( ) , value . size ( ) * sizeof ( typename TypeParam :: type ) , [ ] ( 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 ( ) , 1 ) ; EXPECT_EQ ( tensor . dtype ( ) , dtype ) ; tensorflow :: gtl :: ArraySlice < typename TypeParam :: type > tensor_view ( reinterpret_cast < typename TypeParam :: type * > ( tensor . data ( ) ) , value . size ( ) ) ; EXPECT_EQ ( tensor_view [ 0 ] , 42 ) ; EXPECT_EQ ( tensor_view [ 1 ] , 100 ) ; EXPECT_EQ ( tensor_view [ 2 ] , 0 ) ; EXPECT_EQ ( tensor_view [ 3 ] , 1 ) ; EXPECT_EQ ( tensor_view [ 4 ] , 4 ) ; EXPECT_EQ ( tensor_view [ 5 ] , 29 ) ; EXPECT_EQ ( tensor . num_bytes ( ) , value . size ( ) * sizeof ( typename TypeParam :: type ) ) ; EXPECT_EQ ( tensor . num_elements ( ) , value . size ( ) ) ; }
This test constructs a 1D tensor for each of the types in "SimpleTypes",
and verifies the expected dimensions, dtype, value, number of bytes, and
number of elements.
This test constructs a 1D tensor for each of the types in " SimpleTypes " and verifies the expected dimensions dtype value number of bytes and number of elements .
// This is our 1D tensor of varying dtype. // Shape is Rank 1 vector. /*dtype=*/ /*shape=*/ /*data=*/ /*len=*/ /*deleter=*/