Test 1: Basic slice then contiguous
| 98 | |
| 99 | // Test 1: Basic slice then contiguous |
| 100 | TEST_F(SliceMMBugTest, SliceContiguous_3x3_From_4x4) { |
| 101 | // Create a 4x4 matrix with known values |
| 102 | // Row-major: [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]] |
| 103 | std::vector<float> data(16); |
| 104 | for (int i = 0; i < 16; i++) { |
| 105 | data[i] = static_cast<float>(i + 1); |
| 106 | } |
| 107 | |
| 108 | auto custom = Tensor::from_vector(data, {4, 4}, Device::CPU); |
| 109 | auto torch_t = torch::tensor(data).reshape({4, 4}); |
| 110 | |
| 111 | // Extract 3x3 submatrix: [:3, :3] |
| 112 | auto custom_slice = custom.slice(0, 0, 3).slice(1, 0, 3); |
| 113 | auto torch_slice = torch_t.slice(0, 0, 3).slice(1, 0, 3); |
| 114 | |
| 115 | LOG_INFO("Custom slice shape: {}x{}", custom_slice.shape()[0], custom_slice.shape()[1]); |
| 116 | LOG_INFO("Custom slice strides: [{}, {}]", custom_slice.stride(0), custom_slice.stride(1)); |
| 117 | LOG_INFO("Custom slice is_contiguous: {}", custom_slice.is_contiguous()); |
| 118 | |
| 119 | // Make contiguous |
| 120 | auto custom_contiguous = custom_slice.contiguous(); |
| 121 | auto torch_contiguous = torch_slice.contiguous(); |
| 122 | |
| 123 | LOG_INFO("Custom contiguous strides: [{}, {}]", custom_contiguous.stride(0), custom_contiguous.stride(1)); |
| 124 | LOG_INFO("Custom contiguous is_contiguous: {}", custom_contiguous.is_contiguous()); |
| 125 | |
| 126 | // Verify values |
| 127 | auto custom_vec = custom_contiguous.to_vector(); |
| 128 | |
| 129 | LOG_INFO("Custom values: [{}, {}, {}, {}, {}, {}, {}, {}, {}]", |
| 130 | custom_vec[0], custom_vec[1], custom_vec[2], |
| 131 | custom_vec[3], custom_vec[4], custom_vec[5], |
| 132 | custom_vec[6], custom_vec[7], custom_vec[8]); |
| 133 | |
| 134 | // Expected: [[1,2,3], [5,6,7], [9,10,11]] |
| 135 | std::vector<float> expected = {1, 2, 3, 5, 6, 7, 9, 10, 11}; |
| 136 | for (size_t i = 0; i < expected.size(); i++) { |
| 137 | EXPECT_FLOAT_EQ(custom_vec[i], expected[i]) |
| 138 | << "Mismatch at index " << i << ": got " << custom_vec[i] << ", expected " << expected[i]; |
| 139 | } |
| 140 | |
| 141 | compare_tensors(custom_contiguous, torch_contiguous, 1e-5f, 1e-6f, "Slice3x3"); |
| 142 | } |
| 143 | |
| 144 | // Test 2: Extract column slice (translation vector) |
| 145 | TEST_F(SliceMMBugTest, SliceColumn_3x1_From_4x4) { |
nothing calls this directly
no test coverage detected