Home | History | Annotate | Download | only in xla
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/compiler/xla/text_literal_writer.h"
     17 
     18 #include <memory>
     19 #include <string>
     20 
     21 #include "tensorflow/compiler/xla/literal_util.h"
     22 #include "tensorflow/compiler/xla/test.h"
     23 #include "tensorflow/compiler/xla/test_helpers.h"
     24 #include "tensorflow/compiler/xla/types.h"
     25 #include "tensorflow/core/lib/io/path.h"
     26 #include "tensorflow/core/platform/env.h"
     27 #include "tensorflow/core/platform/logging.h"
     28 
     29 namespace xla {
     30 namespace {
     31 
     32 TEST(TextLiteralWriterTest, WritesFloatLiteral) {
     33   auto literal = Literal::CreateR2<float>({
     34       {3.14, 2.17}, {1.23, 4.56},
     35   });
     36   string path =
     37       tensorflow::io::JoinPath(tensorflow::testing::TmpDir(), "/whatever");
     38   ASSERT_IS_OK(TextLiteralWriter::WriteToPath(*literal, path));
     39   string contents;
     40   TF_CHECK_OK(tensorflow::ReadFileToString(tensorflow::Env::Default(), path,
     41                                            &contents));
     42   const string expected = R"(f32[2,2]
     43 (0, 0): 3.14
     44 (0, 1): 2.17
     45 (1, 0): 1.23
     46 (1, 1): 4.56
     47 )";
     48   EXPECT_EQ(expected, contents);
     49 }
     50 
     51 }  // namespace
     52 }  // namespace xla
     53