static */
| 30 | namespace xla { |
| 31 | |
| 32 | /* static */ Status TextLiteralWriter::WriteToPath(const Literal& literal, |
| 33 | absl::string_view path) { |
| 34 | std::unique_ptr<tensorflow::WritableFile> f; |
| 35 | auto s = tensorflow::Env::Default()->NewWritableFile(string(path), &f); |
| 36 | if (!s.ok()) { |
| 37 | return s; |
| 38 | } |
| 39 | |
| 40 | s = f->Append(ShapeUtil::HumanString(literal.shape()) + "\n"); |
| 41 | if (!s.ok()) { |
| 42 | return s; |
| 43 | } |
| 44 | |
| 45 | Status status; |
| 46 | tensorflow::WritableFile* f_ptr = f.get(); |
| 47 | literal.EachCellAsString( |
| 48 | [f_ptr, &status](absl::Span<const int64> indices, const string& value) { |
| 49 | if (!status.ok()) { |
| 50 | return; |
| 51 | } |
| 52 | string coordinates = |
| 53 | absl::StrCat("(", absl::StrJoin(indices, ", "), ")"); |
| 54 | |
| 55 | status = f_ptr->Append(absl::StrCat(coordinates, ": ", value, "\n")); |
| 56 | }); |
| 57 | auto ignored = f->Close(); |
| 58 | return status; |
| 59 | } |
| 60 | |
| 61 | } // namespace xla |
nothing calls this directly
no test coverage detected