mailr9069 - /1.3/maths_fns/kronecker_product.py


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

Header


Content

Posted by edward on June 08, 2009 - 17:13:
Author: bugman
Date: Mon Jun  8 17:13:54 2009
New Revision: 9069

URL: http://svn.gna.org/viewcvs/relax?rev=9069&view=rev
Log:
Added a copyright notice and spun out the T14 transpose into its own function.


Modified:
    1.3/maths_fns/kronecker_product.py

Modified: 1.3/maths_fns/kronecker_product.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/maths_fns/kronecker_product.py?rev=9069&r1=9068&r2=9069&view=diff
==============================================================================
--- 1.3/maths_fns/kronecker_product.py (original)
+++ 1.3/maths_fns/kronecker_product.py Mon Jun  8 17:13:54 2009
@@ -1,4 +1,31 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2009 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax.                                    
 #
+#                                                                            
 #
+# relax is free software; you can redistribute it and/or modify              
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation; either version 2 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# relax is distributed in the hope that it will be useful,                   
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with relax; if not, write to the Free Software                       
 #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""Module for the calculation of the Kronecker product."""
+
+# Python imports.
 from numpy import concatenate, outer
+
 
 
 def kron_prod(A, B):
@@ -19,4 +46,29 @@
     C.shape = A.shape + B.shape
 
     # Generate and return the Kronecker product matrix.
-    return concatenate(concatenate(C, axis=1), axis=1)
+    return transpose_14(C, A.shape + B.shape)
+
+
+def transpose_14(C, shape=(3,3,3,3)):
+    """Perform the transpose of axes 1 and 4.
+
+    @param A:       ixj matrix.
+    @type A:        rank-2 numpy array
+    @keyword shape: The rank-4 shape of the matrix A.
+    @type shape:    tuple of 4 int
+    @return:        A with axes 1 and 4 transposed.
+    @rtype:         rank-2 numpy array
+    """
+
+    # Redefine the shape.
+    orig_shape = C.shape
+    C.shape = shape
+
+    # Generate the transposed matrix.
+    C_T14 = concatenate(concatenate(C, axis=1), axis=1)
+
+    # Restore the shape of C.
+    C.shape = orig_shape
+
+    # Return the transposed matrix.
+    return C_T14




Related Messages


Powered by MHonArc, Updated Wed Jun 17 19:40:02 2009