MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / TEST_F

Function TEST_F

tests/test_tensor_debug.cpp:133–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131// ============================================================================
132
133TEST_F(TensorDebugTest, Sort_Float32_Ascending) {
134 std::cout << "\n=== TEST: Sort Float32 Ascending ===" << std::endl;
135
136 auto torch_data = torch::tensor({3.0f, 1.0f, 4.0f, 1.0f, 5.0f}, torch::kCUDA);
137 auto gs_data = torch_to_tensor(torch_data);
138
139 std::cout << "Input: [3.0, 1.0, 4.0, 1.0, 5.0]" << std::endl;
140
141 // LibTorch
142 auto [torch_vals, torch_idx] = torch::sort(torch_data);
143 std::cout << "LibTorch result:" << std::endl;
144 std::cout << " Values: " << torch_vals << std::endl;
145 std::cout << " Indices: " << torch_idx << std::endl;
146 std::cout << " Index dtype: " << torch_idx.dtype() << std::endl;
147
148 // lfs::core::Tensor
149 std::cout << "lfs::core::Tensor result:" << std::endl;
150 try {
151 auto result = gs_data.sort(0);
152 auto gs_vals = result.first;
153 auto gs_idx = result.second;
154
155 std::cout << " Values shape: [" << gs_vals.shape()[0] << "]" << std::endl;
156 std::cout << " Indices shape: [" << gs_idx.shape()[0] << "]" << std::endl;
157 std::cout << " Index dtype: " << lfs::core::dtype_name(gs_idx.dtype()) << std::endl;
158
159 // Compare values
160 bool vals_match = compare_float_tensors(gs_vals, torch_vals);
161 print_comparison("Sort values match", vals_match);
162 EXPECT_TRUE(vals_match);
163
164 // Compare indices (allow Int32 or Int64)
165 bool idx_match = compare_int_tensors(gs_idx, torch_idx);
166 print_comparison("Sort indices match", idx_match);
167 EXPECT_TRUE(idx_match);
168
169 } catch (const std::exception& e) {
170 std::cout << " ERROR: " << e.what() << std::endl;
171 FAIL() << "lfs::core::Tensor sort() threw exception";
172 }
173}
174
175TEST_F(TensorDebugTest, Sort_Float32_Descending) {
176 std::cout << "\n=== TEST: Sort Float32 Descending ===" << std::endl;

Callers

nothing calls this directly

Calls 15

sortFunction · 0.85
dtype_nameFunction · 0.85
print_comparisonFunction · 0.85
TensorOptionsClass · 0.85
shapeMethod · 0.80
unsqueezeMethod · 0.80
squeezeMethod · 0.80
ndimMethod · 0.80
numelMethod · 0.80
cumsumMethod · 0.80
eqMethod · 0.80
any_scalarMethod · 0.80

Tested by

no test coverage detected