@@ -400,27 +400,42 @@ def _generate_grf(
400
400
msg = "all gls are empty"
401
401
raise ValueError (msg )
402
402
403
- # generates the covariance matrix for the iterative sampler
404
- cov = cls2cov (gls , n , ngrf , ncorr )
405
-
406
403
# working arrays for the iterative sampling
407
404
z = np .zeros (n * (n + 1 ) // 2 , dtype = np .complex128 )
408
405
y = np .zeros ((n * (n + 1 ) // 2 , ncorr ), dtype = np .complex128 )
409
406
407
+ blocks = []
408
+ block_ns = []
409
+ for j in range (len (gls )):
410
+ block = [gls [i ][j : j + 1 ] for i in range (j , len (gls ))]
411
+ blocks .append (block )
412
+ block_ns .append (len (gls ) - j )
413
+
410
414
# generate the conditional normal distribution for iterative sampling
411
- conditional_dist = iternorm (ncorr , cov , size = n )
415
+ conditional_dists = []
416
+ for block , block_n in zip (blocks , block_ns , strict = False ):
417
+ # generate the covariance matrix of this block for the iterative sampler
418
+ block_cov = cls2cov (block , block_n , ngrf , ncorr )
419
+ # generate the conditional normal distribution for iterative sampling
420
+ conditional_dist = iternorm (ncorr , block_cov , size = block_n )
421
+ # store for parallel processing of all blocks
422
+ conditional_dists .append (conditional_dist )
412
423
413
424
# sample the fields from the conditional distribution
414
- for j , a , s in conditional_dist :
425
+ for results in zip ( * conditional_dists , strict = False ) :
415
426
# standard normal random variates for alm
416
427
# sample real and imaginary parts, then view as complex number
417
428
rng .standard_normal (n * (n + 1 ), np .float64 , z .view (np .float64 ))
418
429
430
+ # concatenate individual updates into one update
431
+ s = np .concatenate ([block_s for _ , _ , block_s in results ])
432
+
419
433
# scale by standard deviation of the conditional distribution
420
434
# variance is distributed over real and imaginary part
421
435
alm = _multalm (z , s )
422
436
423
437
# add the mean of the conditional distribution
438
+ a = np .concatenate ([block_a for _ , block_a , _ in results ])
424
439
for i in range (ncorr ):
425
440
alm += _multalm (y [:, i ], a [:, i ])
426
441
0 commit comments