mailr24160 - /branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by tlinnet on June 19, 2014 - 17:42:
Author: tlinnet
Date: Thu Jun 19 17:42:16 2014
New Revision: 24160

URL: http://svn.gna.org/viewcvs/relax?rev=24160&view=rev
Log:
Moved the calculation the evolution matrix out of for loops.

The trick is that numpy.einsum allows for dot product of higher dimension:

- The the essential evolution matrix.
- This is a dot product of the outer [7][7] matrix of the Rexpo_mat and 
r180x_mat matrixes, which
- have the shape [NE][NS][NM][NO][ND][7][7].
- This can be achieved by using numpy einsum, and where ellipsis notation 
will use the last axis.
evolution_matrix_mat = einsum('...ij,...jk', Rexpo_mat, r180x_mat)
evolution_matrix_mat = einsum('...ij,...jk', evolution_matrix_mat, Rexpo_mat)
evolution_matrix_mat = einsum('...ij,...jk', evolution_matrix_mat, 
evolution_matrix_mat)

Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion 
models for Clustered analysis.

Modified:
    branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py

Modified: branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py?rev=24160&r1=24159&r2=24160&view=diff
==============================================================================
--- branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py (original)
+++ branches/disp_spin_speed/lib/dispersion/ns_cpmg_2site_3d.py Thu Jun 19 
17:42:16 2014
@@ -55,7 +55,7 @@
 """
 
 # Python module imports.
-from numpy import asarray, dot, fabs, isfinite, log, min, newaxis, sum, tile
+from numpy import asarray, dot, fabs, einsum, isfinite, log, min, newaxis, 
sum, tile
 from numpy.ma import fix_invalid, masked_where
 
 
@@ -139,6 +139,14 @@
     Mint_mat =  tile(M0[newaxis, newaxis, newaxis, newaxis, newaxis, :, 
newaxis], (NE, NS, NM, NO, ND, 1, 1) )
     r180x_mat = tile(r180x[newaxis, newaxis, newaxis, newaxis, newaxis, 
...], (NE, NS, NM, NO, ND, 1, 1) )
 
+    # The the essential evolution matrix.
+    # This is a dot product of the outer [7][7] matrix of the Rexpo_mat and 
r180x_mat matrixes, which
+    # have the shape [NE][NS][NM][NO][ND][7][7].
+    # This can be achieved by using numpy einsum, and where ellipsis 
notation will use the last axis.
+    evolution_matrix_mat = einsum('...ij,...jk', Rexpo_mat, r180x_mat)
+    evolution_matrix_mat = einsum('...ij,...jk', evolution_matrix_mat, 
Rexpo_mat)
+    evolution_matrix_mat = einsum('...ij,...jk', evolution_matrix_mat, 
evolution_matrix_mat)
+
     # Loop over the spins
     for si in range(NS):
         # Loop over the spectrometer frequencies.
@@ -160,13 +168,7 @@
                 # This matrix is a propagator that will evolve the 
magnetization with the matrix R for a delay tcp.
                 Rexpo_i = Rexpo_mat[0, si, mi, 0, di]
                 r180x_i = r180x_mat[0, si, mi, 0, di]
-
-                # The essential evolution matrix.
-                # This is the first round.
-                evolution_matrix_i = dot(Rexpo_i, r180x_i)
-                evolution_matrix_i = dot(evolution_matrix_i, Rexpo_i)
-                # The second round.
-                evolution_matrix_i = dot(evolution_matrix_i, 
evolution_matrix_i )
+                evolution_matrix_i = evolution_matrix_mat[0, si, mi, 0, di]
 
                 # Loop over the CPMG elements, propagating the magnetisation.
                 for j in range(power_si_mi_di):




Related Messages


Powered by MHonArc, Updated Thu Jun 19 18:00:03 2014