| 59 | // We assume this is a row-major matrix. |
| 60 | |
| 61 | void SimpleFloatHelper( |
| 62 | const TensorSliceWriter::CreateBuilderFunction& create_function, |
| 63 | TensorSliceReader::OpenTableFunction open_function) { |
| 64 | const string fname_base = io::JoinPath(testing::TmpDir(), "float_checkpoint"); |
| 65 | |
| 66 | TensorShape shape({4, 5}); |
| 67 | |
| 68 | // File #0 contains a slice that is the top two rows: |
| 69 | // |
| 70 | // 0 1 2 3 4 |
| 71 | // 5 6 7 8 9 |
| 72 | // . . . . . |
| 73 | // . . . . . |
| 74 | { |
| 75 | const string fname = strings::StrCat(fname_base, "_0"); |
| 76 | TensorSliceWriter writer(fname, create_function); |
| 77 | const float data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 78 | TensorSlice slice = TensorSlice::ParseOrDie("0,2:-"); |
| 79 | TF_CHECK_OK(writer.Add("test", shape, slice, data)); |
| 80 | TF_CHECK_OK(writer.Finish()); |
| 81 | } |
| 82 | |
| 83 | // File #1 contains two slices: |
| 84 | // |
| 85 | // slice #0 is the bottom left corner |
| 86 | // . . . . . |
| 87 | // . . . . . |
| 88 | // 10 11 12 . . |
| 89 | // 15 16 17 . . |
| 90 | // |
| 91 | // slice #1 is the bottom right corner |
| 92 | // . . . . . |
| 93 | // . . . . . |
| 94 | // . . . . . |
| 95 | // . . . 18 19 |
| 96 | { |
| 97 | const string fname = strings::StrCat(fname_base, "_1"); |
| 98 | TensorSliceWriter writer(fname, create_function); |
| 99 | // slice #0 |
| 100 | { |
| 101 | const float data[] = {10, 11, 12, 15, 16, 17}; |
| 102 | TensorSlice slice = TensorSlice::ParseOrDie("2,2:0,3"); |
| 103 | TF_CHECK_OK(writer.Add("test", shape, slice, data)); |
| 104 | } |
| 105 | // slice #1 |
| 106 | { |
| 107 | const float data[] = {18, 19}; |
| 108 | TensorSlice slice = TensorSlice::ParseOrDie("3,1:3,2"); |
| 109 | TF_CHECK_OK(writer.Add("test", shape, slice, data)); |
| 110 | } |
| 111 | TF_CHECK_OK(writer.Finish()); |
| 112 | } |
| 113 | |
| 114 | // Notice that we leave a hole in the tensor |
| 115 | // . . . . . |
| 116 | // . . . . . |
| 117 | // . . . (13) (14) |
| 118 | // . . . . . |