From cc8d4d36183f7bbf012eaa5920a1bb1358304490 Mon Sep 17 00:00:00 2001 From: Carlo Date: Mon, 15 Jun 2026 22:29:36 +0200 Subject: [PATCH] Revert "u" This reverts commit 4f3bf3ff02d572e84a120ab476ef312a3edd37a3. --- deeptrack/optical/optics.py | 13 +++---------- deeptrack/optical/scatterers.py | 9 --------- tests/test_scatterers.py | 9 +++++++++ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/deeptrack/optical/optics.py b/deeptrack/optical/optics.py index 2b906755..148f8622 100644 --- a/deeptrack/optical/optics.py +++ b/deeptrack/optical/optics.py @@ -677,17 +677,10 @@ def get_voxel_size( props = self._normalize( resolution=resolution, magnification=magnification ) - res = props["resolution"] - mag = props["magnification"] - if TORCH_AVAILABLE and ( - torch.is_tensor(res) or torch.is_tensor(mag) - ): - res = res if torch.is_tensor(res) else torch.tensor(res, dtype=torch.float64) - mag = mag if torch.is_tensor(mag) else torch.tensor(mag, dtype=torch.float64) - v = res / mag - return torch.stack([v, v, v]) return ( - xp.ones((3,), dtype=xp.float64) * res / mag + xp.ones((3,), dtype=xp.float64) + * props["resolution"] + / props["magnification"] ) def get_pixel_size( diff --git a/deeptrack/optical/scatterers.py b/deeptrack/optical/scatterers.py index 13e7dc93..94e15042 100644 --- a/deeptrack/optical/scatterers.py +++ b/deeptrack/optical/scatterers.py @@ -225,15 +225,6 @@ def _asarray_vector(value, dtype=None): if isinstance(value, (list, tuple)) and any( apc.is_array_api_obj(element) for element in value ): - if TORCH_AVAILABLE and any(torch.is_tensor(e) for e in value): - elements = [] - for e in value: - if not torch.is_tensor(e): - e = torch.tensor(e, dtype=dtype) - elif dtype is not None: - e = e.to(dtype=dtype) - elements.append(e.reshape(())) - return torch.stack(elements) return xp.stack( [xp.reshape(_asarray(element, dtype), ()) for element in value] ) diff --git a/tests/test_scatterers.py b/tests/test_scatterers.py index adcbfd16..f6b89b02 100644 --- a/tests/test_scatterers.py +++ b/tests/test_scatterers.py @@ -699,7 +699,12 @@ def test_mie_sphere_brightfield_sums_multiple_torch_fields(self): return_field=True, ) + # image = microscope(sample).resolve() image = microscope(sample).resolve() + print(radius_1.requires_grad) # True — set by us + print(image.requires_grad) # Is the graph connected? + loss = torch.abs(image).sum() + loss.backward() self.assertIsInstance(image, torch.Tensor) self.assertEqual(image.shape, (32, 32, 1)) @@ -774,7 +779,11 @@ def test_mie_sphere_brightfield_autodiff_learnable_parameters(self): with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") + print(parameter.requires_grad) # True here image = microscope(sample).resolve() + print(parameter.requires_grad) # Still True, but now detached from computation graph + + # image = microscope(sample).resolve() tensor_warning = ( "Converting a tensor with requires_grad=True to a scalar"