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

Function compare_float_tensors

tests/test_tensor_debug.cpp:45–66  ·  view source on GitHub ↗

Helper to compare float tensors

Source from the content-addressed store, hash-verified

43
44 // Helper to compare float tensors
45 bool compare_float_tensors(const lfs::core::Tensor& gs_t, const torch::Tensor& torch_t,
46 float tol = FLOAT_TOLERANCE) {
47 if (gs_t.numel() != torch_t.numel()) {
48 std::cout << " Size mismatch: gs=" << gs_t.numel()
49 << " torch=" << torch_t.numel() << std::endl;
50 return false;
51 }
52
53 auto gs_cpu = gs_t.cpu().to_vector();
54 auto torch_cpu = torch_t.cpu();
55 auto torch_ptr = torch_cpu.data_ptr<float>();
56
57 for (size_t i = 0; i < gs_t.numel(); ++i) {
58 float diff = std::abs(gs_cpu[i] - torch_ptr[i]);
59 if (diff > tol) {
60 std::cout << " Mismatch at index " << i << ": gs=" << gs_cpu[i]
61 << " torch=" << torch_ptr[i] << " diff=" << diff << std::endl;
62 return false;
63 }
64 }
65 return true;
66 }
67
68 // Helper to compare int tensors
69 bool compare_int_tensors(const lfs::core::Tensor& gs_t, const torch::Tensor& torch_t) {

Callers 1

TEST_FFunction · 0.70

Calls 4

numelMethod · 0.80
to_vectorMethod · 0.80
absFunction · 0.50
cpuMethod · 0.45

Tested by

no test coverage detected