AOT-biomaps 2.9.261__py3-none-any.whl → 2.9.294__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.

Potentially problematic release.


This version of AOT-biomaps might be problematic. Click here for more details.

@@ -1,9 +1,11 @@
1
1
  import os
2
+ from AOT_biomaps.AOT_Recon.AOT_SparseSMatrix import SparseSMatrix_CSR, SparseSMatrix_SELL
2
3
  import torch
3
4
  import numpy as np
5
+ import pycuda.driver as drv
4
6
  from numba import njit, prange
5
7
  from torch_sparse import coalesce
6
- import cupyx.scipy.sparse as cpsparse
8
+ from scipy.signal.windows import hann
7
9
 
8
10
  def load_recon(hdr_path):
9
11
  """
@@ -152,36 +154,72 @@ def ssim(img1, img2, win_size=7, k1=0.01, k2=0.03, L=1.0):
152
154
  def calculate_memory_requirement(SMatrix, y):
153
155
  """
154
156
  Calcule la mémoire requise (en Go) pour :
155
- - SMatrix : np.ndarray (dense) ou cpsparse.csr_matrix (sparse)
157
+ - SMatrix : Matrice (np.ndarray, CuPy CSR, SparseSMatrix_CSR ou SparseSMatrix_SELL)
156
158
  - y : vecteur (NumPy ou CuPy, float32)
157
159
 
158
160
  Args:
159
- SMatrix: np.ndarray ou cpsparse.csr_matrix
160
- y: vecteur (float32)
161
+ SMatrix: Matrix object (np.ndarray, cpsparse.csr_matrix, SparseSMatrix_CSR, or SparseSMatrix_SELL)
162
+ y: Vector (float32)
161
163
  """
162
- # 1. Mémoire pour SMatrix
163
- if isinstance(SMatrix, cpsparse.csr_matrix):
164
- # Matrice CSR CuPy
165
- nnz = SMatrix.nnz
166
- num_cols = SMatrix.shape[1]
167
- size_SMatrix = nnz * (4 + 4) + (num_cols + 1) * 4 # data (float32) + indices (int32) + indptr (int32)
164
+ total_bytes = 0
165
+
166
+ # --- 1. Memory for SMatrix ---
167
+
168
+ # 1.1. Custom Sparse Matrix (SELL/CSR)
169
+ if isinstance(SMatrix, (SparseSMatrix_SELL, SparseSMatrix_CSR)):
170
+ # We rely on the getMatrixSize method, which we fixed to track all host/GPU bytes.
171
+ # This is the most reliable way to estimate memory for custom GPU-backed structures.
172
+ try:
173
+ matrix_size_gb = SMatrix.getMatrixSize()
174
+ if isinstance(matrix_size_gb, dict) and 'error' in matrix_size_gb:
175
+ raise ValueError(f"SMatrix allocation error: {matrix_size_gb['error']}")
176
+
177
+ # Convert GB back to bytes (1 GB = 1024^3 bytes)
178
+ size_SMatrix = matrix_size_gb * (1024 ** 3)
179
+ total_bytes += size_SMatrix
180
+ print(f"SMatrix (Custom Sparse) size: {matrix_size_gb:.3f} GB")
181
+
182
+ except AttributeError:
183
+ raise AttributeError("Custom Sparse Matrix must implement the getMatrixSize() method.")
184
+
185
+ # 1.2. NumPy Dense Array (Standard)
168
186
  elif isinstance(SMatrix, np.ndarray):
169
- # Tableau NumPy dense (float32)
187
+ # Dense NumPy array (float32)
170
188
  size_SMatrix = SMatrix.nbytes
189
+ total_bytes += size_SMatrix
190
+ print(f"SMatrix (NumPy Dense) size: {size_SMatrix / (1024 ** 3):.3f} GB")
191
+
192
+ # 1.3. CuPy CSR Matrix (Standard Sparse CuPy)
193
+ # Note: Requires CuPy to be imported, which is usually done outside this function.
194
+ # Assuming 'cpsparse.csr_matrix' is available in the environment if this path is taken.
195
+ elif 'cupy.sparse' in str(type(SMatrix)): # Using string check for type safety outside CuPy context
196
+ # CuPy CSR matrix structure: data (float32), indices (int32), indptr (int32)
197
+ nnz = SMatrix.nnz
198
+ num_rows = SMatrix.shape[0]
199
+ size_data = nnz * 4 # float32 = 4 bytes
200
+ size_indices = nnz * 4 # int32 = 4 bytes
201
+ size_indptr = (num_rows + 1) * 4 # int32 = 4 bytes
202
+ size_SMatrix = size_data + size_indices + size_indptr
203
+ total_bytes += size_SMatrix
204
+ print(f"SMatrix (CuPy CSR) size: {size_SMatrix / (1024 ** 3):.3f} GB")
205
+
171
206
  else:
172
- raise ValueError("SMatrix doit être un np.ndarray ou une matrice CSR CuPy.")
207
+ raise ValueError("SMatrix must be a np.ndarray, cpsparse.csr_matrix, or a custom SparseSMatrix object (CSR/SELL).")
173
208
 
174
- # 2. Mémoire pour y (float32)
209
+ # --- 2. Memory for Vector y ---
210
+
211
+ # Check if y is a CuPy array or NumPy array (assuming float32 based on docstring)
175
212
  if hasattr(y, 'nbytes'):
176
213
  size_y = y.nbytes
214
+ total_bytes += size_y
215
+ print(f"Vector y size: {size_y / (1024 ** 3):.3f} GB")
177
216
  else:
178
- size_y = np.prod(y.shape) * 4 # float32
217
+ # Fallback if object doesn't expose nbytes (e.g., custom buffer), but usually array objects do.
218
+ raise ValueError("Vector y must be an array type exposing the .nbytes attribute.")
179
219
 
180
- # Total en Go
181
- total_bytes = size_SMatrix + size_y
182
- total_GB = total_bytes / 1024**3
183
220
 
184
- return total_GB
221
+ # --- 3. Final Result ---
222
+ return total_bytes / (1024 ** 3)
185
223
 
186
224
 
187
225
  def check_gpu_memory(device_index, required_memory, show_logs=True):
@@ -341,3 +379,111 @@ def filter_radon(f, N, filter_type, Fc):
341
379
  FILTER = FILTER * np.exp(-2 * (np.abs(f) / Fc)**10)
342
380
 
343
381
  return FILTER
382
+
383
+ def compute_TV_cpu(x, Z, X, isotropic=False):
384
+ """
385
+ Compute total variation of x (1D flattened of shape Z*X).
386
+ isotropic=False -> anisotropic (sum |dx| + |dy|)
387
+ isotropic=True -> isotropic sqrt(dx^2 + dy^2)
388
+ """
389
+ x2d = x.reshape(Z, X)
390
+ dx = np.diff(x2d, axis=1)
391
+ dy = np.diff(x2d, axis=0)
392
+ if isotropic:
393
+ # pad to original size for consistent measure (we only need sum of norms)
394
+ mags = np.sqrt(dx**2 + dy**2)
395
+ return float(np.sum(mags))
396
+ else:
397
+ return float(np.sum(np.abs(dx)) + np.sum(np.abs(dy)))
398
+
399
+ def get_apodization_vector_gpu(matrix_sparse_obj):
400
+ """
401
+ Génère un vecteur de fenêtrage 2D (Hanning) pour l'apodisation
402
+ de la matrice système A et le transfère sur le GPU.
403
+ Ce vecteur doit être multiplié par les colonnes de A (pixels Z*X).
404
+ """
405
+ Z = matrix_sparse_obj.Z
406
+ X = matrix_sparse_obj.X
407
+
408
+ # 1. Génération des fenêtres 1D sur l'axe X et Z
409
+ # Forte apodisation latérale (X) pour cibler l'artefact de bordure.
410
+ fenetre_x = hann(X).astype(np.float32)
411
+
412
+ # Fenêtre uniforme en profondeur (Z), car l'artefact est surtout latéral.
413
+ fenetre_z = np.ones(Z, dtype=np.float32)
414
+
415
+ # 2. Création de la matrice de fenêtre 2D (Z, X)
416
+ fenetre_2d = np.outer(fenetre_z, fenetre_x)
417
+
418
+ # 3. Vectorisation (Z*X)
419
+ fenetre_vectorisee = fenetre_2d.flatten()
420
+
421
+ # 4. Transfert sur GPU (mémoire contiguë)
422
+ fenetre_gpu = drv.mem_alloc(fenetre_vectorisee.nbytes)
423
+ drv.memcpy_htod(fenetre_gpu, fenetre_vectorisee)
424
+
425
+ print(f"✅ Vecteur de fenêtrage (Z*X={Z*X}) généré et transféré sur GPU.")
426
+
427
+ return fenetre_gpu
428
+
429
+ def _call_axpby(axpby_kernel, out_ptr, x_ptr, y_ptr, a, b, N, stream, block):
430
+ grid = ((int(N) + block - 1) // block, 1, 1)
431
+ axpby_kernel(out_ptr, x_ptr, y_ptr,
432
+ np.float32(a), np.float32(b),
433
+ np.int32(N),
434
+ block=(block, 1, 1), grid=grid, stream=stream)
435
+
436
+ def _call_minus_axpy(minus_kernel, out_ptr, z_ptr, a, N, stream, block):
437
+ grid = ((int(N) + block - 1) // block, 1, 1)
438
+ minus_kernel(out_ptr, z_ptr, np.float32(a), np.int32(N),
439
+ block=(block, 1, 1), grid=grid, stream=stream)
440
+
441
+ def power_method_estimate_L__SELL(SMatrix, stream, n_it=20, block_size=256):
442
+ """Estimate ||A||^2 using power method (uses your projection/backprojection kernels)."""
443
+ TN = int(SMatrix.N * SMatrix.T)
444
+ ZX = int(SMatrix.Z * SMatrix.X)
445
+ proj = SMatrix.sparse_mod.get_function("projection_kernel__SELL")
446
+ back = SMatrix.sparse_mod.get_function("backprojection_kernel__SELL")
447
+ TN_i = np.int32(TN)
448
+ ZX_i = np.int32(ZX)
449
+ slice_h = np.int32(SMatrix.slice_height)
450
+ grid_rows = ((TN + block_size - 1) // block_size, 1, 1)
451
+ block_1D = (block_size, 1, 1)
452
+
453
+ dtype = np.float32
454
+ x_host = np.random.randn(ZX).astype(dtype)
455
+ x_host /= np.linalg.norm(x_host) + 1e-12
456
+ x_gpu = drv.mem_alloc(x_host.nbytes)
457
+ drv.memcpy_htod_async(x_gpu, x_host, stream)
458
+ q_gpu = drv.mem_alloc(TN * np.dtype(dtype).itemsize)
459
+ ATq_gpu = drv.mem_alloc(ZX * np.dtype(dtype).itemsize)
460
+ ATq_host = np.empty(ZX, dtype=dtype)
461
+
462
+ for _ in range(n_it):
463
+ proj(q_gpu, SMatrix.sell_values_gpu, SMatrix.sell_colinds_gpu, SMatrix.slice_ptr_gpu, SMatrix.slice_len_gpu,
464
+ x_gpu, TN_i, slice_h, block=block_1D, grid=grid_rows, stream=stream)
465
+ drv.memset_d32_async(ATq_gpu, 0, ZX, stream)
466
+ back(SMatrix.sell_values_gpu, SMatrix.sell_colinds_gpu, SMatrix.slice_ptr_gpu, SMatrix.slice_len_gpu,
467
+ q_gpu, ATq_gpu, TN_i, slice_h, block=block_1D, grid=grid_rows, stream=stream)
468
+ stream.synchronize()
469
+ drv.memcpy_dtoh(ATq_host, ATq_gpu)
470
+ norm = np.linalg.norm(ATq_host)
471
+ if norm < 1e-12:
472
+ break
473
+ x_host = ATq_host / norm
474
+ drv.memcpy_htod_async(x_gpu, x_host, stream)
475
+ # final Rayleigh quotient
476
+ proj(q_gpu, SMatrix.sell_values_gpu, SMatrix.sell_colinds_gpu, SMatrix.slice_ptr_gpu, SMatrix.slice_len_gpu,
477
+ x_gpu, TN_i, slice_h, block=block_1D, grid=grid_rows, stream=stream)
478
+ drv.memset_d32_async(ATq_gpu, 0, ZX, stream)
479
+ back(SMatrix.sell_values_gpu, SMatrix.sell_colinds_gpu, SMatrix.slice_ptr_gpu, SMatrix.slice_len_gpu,
480
+ q_gpu, ATq_gpu, TN_i, slice_h, block=block_1D, grid=grid_rows, stream=stream)
481
+ stream.synchronize()
482
+ drv.memcpy_dtoh(ATq_host, ATq_gpu)
483
+ L_sq = float(np.dot(x_host, ATq_host))
484
+ for g in (x_gpu, q_gpu, ATq_gpu):
485
+ try:
486
+ g.free()
487
+ except:
488
+ pass
489
+ return max(L_sq, 1e-6)
AOT_biomaps/__init__.py CHANGED
@@ -85,7 +85,7 @@ from .AOT_Recon.AOT_PotentialFunctions.RelativeDifferences import *
85
85
  from .Config import config
86
86
  from .Settings import *
87
87
 
88
- __version__ = '2.9.261'
88
+ __version__ = '2.9.294'
89
89
  __process__ = config.get_process()
90
90
 
91
91
  def initialize(process=None):
@@ -125,3 +125,36 @@ def initialize(process=None):
125
125
 
126
126
 
127
127
 
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AOT_biomaps
3
- Version: 2.9.261
3
+ Version: 2.9.294
4
4
  Summary: Acousto-Optic Tomography
5
5
  Home-page: https://github.com/LucasDuclos/AcoustoOpticTomography
6
6
  Author: Lucas Duclos
@@ -1,6 +1,6 @@
1
1
  AOT_biomaps/Config.py,sha256=ghEOP1n8aO1pR-su13wMeAZAxZRfry5hH67NbtZ8SqI,3614
2
2
  AOT_biomaps/Settings.py,sha256=v8fPhnvvcfBJP29m1RLOTEr3jndGLGwbUiORXmsj2Bo,2853
3
- AOT_biomaps/__init__.py,sha256=EAyX3lRoiynQtskCWC5xS9exXzUs8hl6NuOWBYnaHfQ,4184
3
+ AOT_biomaps/__init__.py,sha256=86X2xRJNI72niePVEmyZMqO0Y4vQeag7ZSHPM3kc4Pk,4250
4
4
  AOT_biomaps/AOT_Acoustic/AcousticEnums.py,sha256=s5kXa6jKzbS4btwbubrVcynLOr0yg5tth5vL_FGfbMk,1802
5
5
  AOT_biomaps/AOT_Acoustic/AcousticTools.py,sha256=al7xXKMY5e-qQQ7nrQVPVAmqYiB320OluNlY6ti8iKc,7539
6
6
  AOT_biomaps/AOT_Acoustic/FocusedWave.py,sha256=3kGKKDx_3Msy5COYqIwzROPORGWvNjw8UsDanBfkMXE,11037
@@ -18,29 +18,30 @@ AOT_biomaps/AOT_Optic/Laser.py,sha256=uzQwxswjU0kZWix3CmZLoWmhsBa3VhN27STprNv-xB
18
18
  AOT_biomaps/AOT_Optic/OpticEnums.py,sha256=b349_JyjHqQohmjK4Wke-A_HLGaqb3_BKbyUqFC4jxY,499
19
19
  AOT_biomaps/AOT_Optic/__init__.py,sha256=HSUVhfz0NzwHHZZ9KP9Xyfu33IgP_rYJX86J-gEROlo,321
20
20
  AOT_biomaps/AOT_Optic/_mainOptic.py,sha256=Wk63CcgWbU-ygMfjNK80islaUbGGJpTXgZY3_C2KQNY,8179
21
- AOT_biomaps/AOT_Recon/AlgebraicRecon.py,sha256=DG9mLMYXRX6cMYjbRRoXAAuGxQQIQKq3lat6rYn5XWM,46099
21
+ AOT_biomaps/AOT_Recon/AOT_biomaps_kernels.cubin,sha256=Li4HdWpr65ONf82FqFAjZ8w3ob9UuJucDWGAAvBF77Q,83680
22
+ AOT_biomaps/AOT_Recon/AlgebraicRecon.py,sha256=CGBXZyYEZ3TOTFOKSt-h7NGuFbuI9PNr3YTWTbSLxDo,46832
22
23
  AOT_biomaps/AOT_Recon/AnalyticRecon.py,sha256=RaQ5AJ1HUmSct0BgjZ0GWSJg7SALCn3Q0laqj1yyhAE,7123
23
24
  AOT_biomaps/AOT_Recon/BayesianRecon.py,sha256=RnnPa-tTcvirwiNPnCRZnSM4NWeEEltYET-piBbp34g,12671
24
25
  AOT_biomaps/AOT_Recon/DeepLearningRecon.py,sha256=RfVcEsi4GeGqJn0_SPxwQPQx6IQjin79WKh2UarMRLI,1383
25
- AOT_biomaps/AOT_Recon/PrimalDualRecon.py,sha256=-7dqUxKXbHt7yR1I1kGcu1TOXn05ik6QoDDsuM0QvNU,10310
26
+ AOT_biomaps/AOT_Recon/PrimalDualRecon.py,sha256=JbFhxiyUoSTnlJgHbOWIfUUwhwfZoi39RJMnfkagegY,16504
26
27
  AOT_biomaps/AOT_Recon/ReconEnums.py,sha256=KAf55RqHAr2ilt6pxFrUBGQOn-7HA8NP6TyL-1FNiXo,19714
27
- AOT_biomaps/AOT_Recon/ReconTools.py,sha256=NRTr13hEohXIyAw6p56CEsVFR4O0bDM-ijcPOs-cpxw,12936
28
+ AOT_biomaps/AOT_Recon/ReconTools.py,sha256=A4IQV7IETu9MgYr7hjLNPTImzjf8CEU4cZ2e0EgJNWA,19878
28
29
  AOT_biomaps/AOT_Recon/__init__.py,sha256=xs_argJqXKFl76xP7-jiUc1ynOEEtY7XZ0gDxD5uVZc,246
29
30
  AOT_biomaps/AOT_Recon/_mainRecon.py,sha256=exoa2UBMfMHjemxAU9dW0mhEfsP6Oe1qjSfrTrgbIcY,13125
30
31
  AOT_biomaps/AOT_Recon/AOT_Optimizers/DEPIERRO.py,sha256=qA1n722GLQJH3V8HcLr5q_GxEwBS_NRlIT3E6JZk-Ag,9479
31
- AOT_biomaps/AOT_Recon/AOT_Optimizers/LS.py,sha256=N7v1xN9I-adIe3c20LN9Drc4-fBSLc9SEmJS8B3Zmag,4343
32
+ AOT_biomaps/AOT_Recon/AOT_Optimizers/LS.py,sha256=bCu1rKzFXPbYQ7jV3L3E_jVQpb6LIEC5MIlN1-mCNdY,22814
32
33
  AOT_biomaps/AOT_Recon/AOT_Optimizers/MAPEM.py,sha256=vQLCB0L4FSXJKn2_6kdIdWrI6WZ82KuqUh7CSqBGVuo,25766
33
- AOT_biomaps/AOT_Recon/AOT_Optimizers/MLEM.py,sha256=PoizVH4ifMyfJ7QSLsHP1gwKuUh9LLGPs_OaaZavpiM,19597
34
- AOT_biomaps/AOT_Recon/AOT_Optimizers/PDHG.py,sha256=5w4klYKAct9_gnlyocIiJfDrQUdz_VhXQVSpfjrjvNU,7927
34
+ AOT_biomaps/AOT_Recon/AOT_Optimizers/MLEM.py,sha256=v5wITKacemu_hY391-cZDSpw4R95XqyLGivQWa-gOOc,21254
35
+ AOT_biomaps/AOT_Recon/AOT_Optimizers/PDHG.py,sha256=oSojwug5mcZedKOWAV7YPMlCp0Qy_Aed0fjHRuyZWpo,28622
35
36
  AOT_biomaps/AOT_Recon/AOT_Optimizers/__init__.py,sha256=tNGVulINaqQZzcs5cvCMAT5ypGdoFWRnxtl9y7ePECk,106
36
37
  AOT_biomaps/AOT_Recon/AOT_PotentialFunctions/Huber.py,sha256=dRd1t5OBag_gVmfji3L0QrA1GJ_702LcCkLH32Bot0M,3285
37
38
  AOT_biomaps/AOT_Recon/AOT_PotentialFunctions/Quadratic.py,sha256=wTbzcXxMdEl9ReEXrL43DOJQecokBwJYU_s2kQUASZY,2545
38
39
  AOT_biomaps/AOT_Recon/AOT_PotentialFunctions/RelativeDifferences.py,sha256=ZlWaKsNPCMfy4fWxYFT2pSoKMbysQkJH4N1WbbWncq4,2493
39
40
  AOT_biomaps/AOT_Recon/AOT_PotentialFunctions/__init__.py,sha256=RwrJdLOFbAFBFnRxo5xdlOyeZgtQRDaRWDN9-uCGUiY,84
40
- AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_CSR.py,sha256=tk8eZHyTpey4TNDmoFL9w88LjerviQmI5YeV8M2Iuq4,10689
41
- AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_SELL.py,sha256=nH9gBea7p_V5LaewFAG-Bkfp_YepMTExoaQcbRf4_Mk,14426
41
+ AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_CSR.py,sha256=RACc2P5oxmp0uPLAGnNj9mEtAxa_OlepNgCawKij3jI,12062
42
+ AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_SELL.py,sha256=WTqHBeglUxRx-jy6CcoETgqYSSHYTwi2zR5NrJcPXGU,14449
42
43
  AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/__init__.py,sha256=8nou-hqjQjuCTLhoL5qv4EM_lMPFviAZAZKSPhi84jE,67
43
- aot_biomaps-2.9.261.dist-info/METADATA,sha256=7mJL-l-m4N7m-ScwYoV1Hey0n6dO6hHESAjzGHXgqm8,700
44
- aot_biomaps-2.9.261.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
- aot_biomaps-2.9.261.dist-info/top_level.txt,sha256=6STF-lT4kaAnBHJYCripmN5mZABoHjMuY689JdiDphk,12
46
- aot_biomaps-2.9.261.dist-info/RECORD,,
44
+ aot_biomaps-2.9.294.dist-info/METADATA,sha256=8c8tnkhnARdI6acSPSrB1FQloxgjuoNHKslkkgIq7xM,700
45
+ aot_biomaps-2.9.294.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
+ aot_biomaps-2.9.294.dist-info/top_level.txt,sha256=6STF-lT4kaAnBHJYCripmN5mZABoHjMuY689JdiDphk,12
47
+ aot_biomaps-2.9.294.dist-info/RECORD,,