diffct 2.5.1__py3-none-any.whl → 2.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
diffct/__init__.py CHANGED
@@ -64,7 +64,7 @@ try:
64
64
  except ImportError:
65
65
  pass
66
66
 
67
- __version__ = '2.5.1'
67
+ __version__ = '2.5.2'
68
68
 
69
69
  __all__ = [
70
70
  'Projector',
diffct/_solver_state.py CHANGED
@@ -328,10 +328,16 @@ def callbacks_enabled(operator, callback):
328
328
  world_size=getattr(operator, "world_size", 1))[0])
329
329
 
330
330
 
331
- def callback_stop(operator, callback, iteration, residual, volume):
331
+ def callback_stop(operator, callback, iteration, residual, volume, *, readonly=False,
332
+ block_elements=1048576):
332
333
  error, stop = None, False
333
334
  try:
334
- stop = callback is not None and callback(iteration, residual, volume) is False
335
+ if callback is not None:
336
+ before = (fingerprint(volume, block_elements), getattr(volume, "device", None)) if readonly else None
337
+ stop = callback(iteration, residual, volume) is False
338
+ if readonly and ((isinstance(volume, torch.Tensor) and not torch.is_floating_point(volume))
339
+ or (fingerprint(volume, block_elements), getattr(volume, "device", None)) != before):
340
+ raise ValueError("CGLS callback iterate is read-only")
335
341
  except Exception as caught:
336
342
  error = caught
337
343
  failed, stop = control_status((int(error is not None), int(stop)),
@@ -21,7 +21,9 @@ from .chunking import _memory_budget, _pixel_tiles
21
21
  from .distribution import Partition, preflight
22
22
  from .operators import _detector_spacing, _normalize_devices, _positive_int, _shape, _validate_trajectory
23
23
  from .reconstruction import _angles, _cosine, _filter, _fixed, _parker_setup
24
- from .streaming import _as_store, _validate_stores
24
+ from .streaming import (_as_store, _backing_store, _backing_tensor, _store_phase,
25
+ _store_rounds, _tensor_overlap, _validate_stores)
26
+ from .storage import NpyStore
25
27
 
26
28
 
27
29
  def _weight(value, shape, name, *, exact=False):
@@ -351,7 +353,7 @@ class AnalyticalExecution:
351
353
  return cone_weighted_backproject(data, *geometry, *shape, *self.pitch,
352
354
  self.voxel_spacing, isocenter=isocenter)
353
355
 
354
- def _tile(self, spatial):
356
+ def _tile(self, spatial, *, reduce=True):
355
357
  shape = tuple(part.stop - part.start for part in spatial)
356
358
  value = torch.zeros(shape, device=self.output_device, dtype=self.dtype)
357
359
  if self.input_dependency is not None:
@@ -361,7 +363,7 @@ class AnalyticalExecution:
361
363
  partial = (self._native_gather(filtered, geometry, spatial) if self.backend == "numba"
362
364
  else self._portable_gather(filtered, geometry, views, spatial))
363
365
  value = value + partial.to(self.output_device)
364
- return _sum(value, self.partition.view_group, self.partition.view_world_size)
366
+ return _sum(value, self.partition.view_group, self.partition.view_world_size) if reduce else value
365
367
 
366
368
  def _prepare_gradients(self):
367
369
  partition = self.partition
@@ -426,17 +428,33 @@ class AnalyticalExecution:
426
428
  error, source, sink = None, None, None
427
429
  try:
428
430
  source, sink = _validate_stores(self, self.source, output, False)
431
+ output_tensor = _backing_tensor(sink)
432
+ backing = _backing_store(sink)
433
+ if isinstance(backing, NpyStore):
434
+ output_tensor = torch.from_numpy(backing._array)
429
435
  for option in (self.projection_weights, self.angular_weights, self.filter_response):
430
436
  if isinstance(option, torch.Tensor) and option.requires_grad:
431
437
  raise ValueError("into methods are numerical; detach autograd weights")
438
+ if (isinstance(option, torch.Tensor) and isinstance(output_tensor, torch.Tensor)
439
+ and _tensor_overlap(option, output_tensor)):
440
+ raise ValueError("analytical weights and output stores overlap")
432
441
  except (ValueError, TypeError, RuntimeError, OSError) as caught:
433
442
  error = caught
434
443
  self.partition.preflight(error)
435
444
  self.source = source
436
445
  with torch.no_grad():
437
- for spatial, _ in _pixel_tiles(self.volume_shape, self.chunk_shape):
438
- sink.write(spatial, self._tile(spatial))
439
- sink.flush()
446
+ for job in _store_rounds(_pixel_tiles(self.volume_shape, self.chunk_shape), self.partition):
447
+ with _store_phase(self.partition):
448
+ if job is not None:
449
+ spatial, _ = job
450
+ value = self._tile(spatial, reduce=False)
451
+ if job is not None:
452
+ value = _sum(value, self.partition.view_group, self.partition.view_world_size)
453
+ with _store_phase(self.partition):
454
+ if job is not None:
455
+ sink.write(spatial, value)
456
+ with _store_phase(self.partition):
457
+ sink.flush()
440
458
  return original
441
459
 
442
460