diffct 2.0.0__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/constants.py ADDED
@@ -0,0 +1,72 @@
1
+ """Global constants and configuration for diffct package.
2
+
3
+ This module defines core constants used throughout the diffct package,
4
+ including data types, CUDA thread block configurations, and numerical
5
+ precision parameters.
6
+ """
7
+
8
+ import numpy as np
9
+ from numba import cuda
10
+
11
+ # ---------------------------------------------------------------------------
12
+ # Data Types and Numerical Constants
13
+ # ---------------------------------------------------------------------------
14
+
15
+ _DTYPE = np.float32
16
+ """Default data type for numerical computations (numpy.float32)."""
17
+
18
+ _INF = _DTYPE(np.inf)
19
+ """Floating-point infinity in default data type."""
20
+
21
+ _NEG_INF = _DTYPE(-np.inf)
22
+ """Negative floating-point infinity in default data type."""
23
+
24
+ _BIG = _DTYPE(1e30)
25
+ """Finite stand-in for infinity in fastmath kernels, where LLVM may assume no inf occurs."""
26
+
27
+ _TINY = _DTYPE(1e-20)
28
+ """Smallest ray direction component that the Siddon kernels divide by; ray parameters then stay below _BIG."""
29
+
30
+ _ZERO = _DTYPE(0.0)
31
+ """Floating-point zero in default data type."""
32
+
33
+ _ONE = _DTYPE(1.0)
34
+ """Floating-point one in default data type."""
35
+
36
+ _HALF = _DTYPE(0.5)
37
+ """Floating-point one half in default data type."""
38
+
39
+ _EPSILON = _DTYPE(1e-6)
40
+ """Small epsilon value for numerical comparisons to avoid division by zero."""
41
+
42
+ # ---------------------------------------------------------------------------
43
+ # CUDA Thread Block Configurations
44
+ # ---------------------------------------------------------------------------
45
+
46
+ # CUDA thread block configurations optimized for different dimensionalities
47
+ # 2D blocks: 16x16 = 256 threads per block, optimal for 2D ray-tracing kernels
48
+ # Balances occupancy with shared memory usage for parallel/fan beam projections
49
+ _TPB_2D = (16, 16)
50
+ """CUDA threads-per-block for 2D kernels (parallel/fan beam): (16, 16) = 256 threads."""
51
+
52
+ # 3D blocks: 8x8x8 = 512 threads per block, optimal for 3D cone beam kernels
53
+ # Smaller per-dimension size accommodates higher register usage in 3D algorithms
54
+ _TPB_3D = (8, 8, 8)
55
+ """CUDA threads-per-block for 3D kernels (cone beam): (8, 8, 8) = 512 threads."""
56
+
57
+ # ---------------------------------------------------------------------------
58
+ # CUDA JIT Decorators
59
+ # ---------------------------------------------------------------------------
60
+
61
+ # CUDA fastmath optimization: enables aggressive floating-point optimizations
62
+ # Trades numerical precision for performance in ray-tracing calculations
63
+ # Safe for CT reconstruction where slight precision loss is acceptable for speed gains
64
+ _FASTMATH_DECORATOR = cuda.jit(cache=True, fastmath=True)
65
+ """Numba CUDA JIT decorator with fastmath enabled for forward kernels."""
66
+
67
+ # Analytical reconstruction kernels (FBP / FDK voxel-driven gather) run at
68
+ # the tightest available precision - the Fourier-convention constant and
69
+ # the (sid/U)^2 weight amplify rounding errors, and the kernels are only
70
+ # called once per reconstruction so the speed penalty is negligible.
71
+ _FDK_ACCURACY_DECORATOR = cuda.jit(cache=True, fastmath=False)
72
+ """Numba CUDA JIT decorator with fastmath disabled for FBP/FDK gather kernels."""
@@ -0,0 +1,74 @@
1
+ """Backward compatibility module for diffct.differentiable.
2
+
3
+ This module provides backward compatibility by re-exporting all functions
4
+ and classes from the refactored modular structure. New code should import
5
+ directly from the specific modules (projectors, geometry, etc.) or from
6
+ the top-level diffct package.
7
+
8
+ DEPRECATED: This module exists only for backward compatibility.
9
+ Prefer importing from 'diffct' directly:
10
+ from diffct import ConeProjectorFunction, circular_trajectory_3d
11
+ """
12
+
13
+ import warnings
14
+
15
+ # Show deprecation warning when this module is imported
16
+ warnings.warn(
17
+ "Importing from 'diffct.differentiable' is deprecated. "
18
+ "Please import from 'diffct' directly, e.g., 'from diffct import ConeProjectorFunction'",
19
+ DeprecationWarning,
20
+ stacklevel=2
21
+ )
22
+
23
+ # Re-export all public API from refactored modules
24
+ from .projectors import (
25
+ ParallelProjectorFunction,
26
+ ParallelBackprojectorFunction,
27
+ FanProjectorFunction,
28
+ FanBackprojectorFunction,
29
+ ConeProjectorFunction,
30
+ ConeBackprojectorFunction,
31
+ )
32
+
33
+ from .geometry import (
34
+ circular_trajectory_3d,
35
+ random_trajectory_3d,
36
+ )
37
+
38
+ # Also export utility functions that were previously accessible
39
+ from .utils import (
40
+ DeviceManager,
41
+ TorchCUDABridge,
42
+ )
43
+
44
+ from .constants import (
45
+ _DTYPE,
46
+ _TPB_2D,
47
+ _TPB_3D,
48
+ _FASTMATH_DECORATOR,
49
+ _INF,
50
+ _EPSILON,
51
+ )
52
+
53
+ __all__ = [
54
+ # Projector Functions
55
+ 'ParallelProjectorFunction',
56
+ 'ParallelBackprojectorFunction',
57
+ 'FanProjectorFunction',
58
+ 'FanBackprojectorFunction',
59
+ 'ConeProjectorFunction',
60
+ 'ConeBackprojectorFunction',
61
+ # Geometry Functions
62
+ 'circular_trajectory_3d',
63
+ 'random_trajectory_3d',
64
+ # Utility Classes
65
+ 'DeviceManager',
66
+ 'TorchCUDABridge',
67
+ # Constants (for advanced users)
68
+ '_DTYPE',
69
+ '_TPB_2D',
70
+ '_TPB_3D',
71
+ '_FASTMATH_DECORATOR',
72
+ '_INF',
73
+ '_EPSILON',
74
+ ]