mailr24242 - /branches/disp_spin_speed/lib/dispersion/matrix_exponential.py


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

Header


Content

Posted by tlinnet on June 23, 2014 - 14:09:
Author: tlinnet
Date: Mon Jun 23 14:09:26 2014
New Revision: 24242

URL: http://svn.gna.org/viewcvs/relax?rev=24242&view=rev
Log:
Fix to lib/dispersion/matrix_exponential.py, since the svn copy command was 
used on non-updated version of the file.

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

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

Modified: branches/disp_spin_speed/lib/dispersion/matrix_exponential.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/lib/dispersion/matrix_exponential.py?rev=24242&r1=24241&r2=24242&view=diff
==============================================================================
--- branches/disp_spin_speed/lib/dispersion/matrix_exponential.py       
(original)
+++ branches/disp_spin_speed/lib/dispersion/matrix_exponential.py       Mon 
Jun 23 14:09:26 2014
@@ -57,15 +57,17 @@
         return array(eA.real)
 
 
-def matrix_exponential_rankN(A):
+def matrix_exponential_rankN(A, dtype=None):
     """Calculate the exact matrix exponential using the eigenvalue 
decomposition approach, for higher dimensional data.
 
     Here X is the Row and Column length, of the outer square matrix.
 
-    @param A:   The square matrix to calculate the matrix exponential of.
-    @type A:    numpy float array of rank [NE][NS][NM][NO][ND][X][X]
-    @return:    The matrix exponential.  This will have the same 
dimensionality as the A matrix.
-    @rtype:     numpy float array of rank [NE][NS][NM][NO][ND][X][X]
+    @param A:       The square matrix to calculate the matrix exponential of.
+    @type A:        numpy float array of rank [NE][NS][NM][NO][ND][X][X]
+    @param dtype:   If provided, forces the calculation to use the data type 
specified.
+    @type type:     data-type, optional
+    @return:        The matrix exponential.  This will have the same 
dimensionality as the A matrix.
+    @rtype:         numpy float array of rank [NE][NS][NM][NO][ND][X][X]
     """
 
     # Set initial to None.
@@ -75,6 +77,15 @@
         NE, NS, NM, NO, ND, Row, Col = A.shape
     elif len(A.shape) == 6:
         NS, NM, NO, ND, Row, Col = A.shape
+
+    # Convert dtype, if specified.
+    if dtype != None:
+        dtype_mat = A.dtype
+
+        # If the dtype is different from the input.
+        if dtype_mat != dtype:
+            # This needs to be made as a copy.
+            A = A.astype(dtype)
 
     # Is the original matrix real?
     complex_flag = any(iscomplex(A))
@@ -102,7 +113,11 @@
         eye_mat = tile(eye(Row)[newaxis, newaxis, newaxis, newaxis, newaxis, 
...], (NE, NS, NM, NO, ND, 1, 1) )
 
     # Transform it to a diagonal matrix, with elements from vector down the 
diagonal.
-    W_exp_diag = multiply(W_exp, eye_mat )
+    # Use the dtype, if specified.
+    if dtype != None:
+        W_exp_diag = multiply(W_exp, eye_mat, dtype=dtype )
+    else:
+        W_exp_diag = multiply(W_exp, eye_mat)
 
     # Make dot products for higher dimension.
     # "...", the Ellipsis notation, is designed to mean to insert as many 
full slices (:)




Related Messages


Powered by MHonArc, Updated Mon Jun 23 14:20:02 2014