Index: /trunk/psLib/src/math/psMatrix.c
===================================================================
--- /trunk/psLib/src/math/psMatrix.c	(revision 15767)
+++ /trunk/psLib/src/math/psMatrix.c	(revision 15768)
@@ -22,6 +22,6 @@
  *  @author Andy Becker, University of Washington (SVD).
  *
- *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-12-08 01:31:58 $
+ *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-12-08 01:48:34 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -42,4 +42,5 @@
 #include <gsl/gsl_eigen.h>
 
+#include "psAbort.h"
 #include "psMemory.h"
 #include "psError.h"
@@ -657,16 +658,8 @@
 }
 
-psImage* psMatrixTranspose(psImage* out,
-                           const psImage* in)
-{
-    psU32 i = 0;
-    psU32 j = 0;
-    psS32 numRowsIn = 0;
-    psS32 numColsIn = 0;
-    psS32 numRowsOut = 0;
-    psS32 numColsOut = 0;
-
-    #define TRANSPOSE_CLEANUP { psFree(out); return NULL; }
+psImage* psMatrixTranspose(psImage* out, const psImage* in)
+{
     // Error checks
+    #define TRANSPOSE_CLEANUP { return NULL; }
     PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, TRANSPOSE_CLEANUP);
     PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, TRANSPOSE_CLEANUP);
@@ -674,29 +667,24 @@
     PS_CHECK_POINTERS(in, out, TRANSPOSE_CLEANUP);
 
-    out = psImageRecycle(out, in->numCols, in->numRows, in->type.type);
-
-    // Initialize data
-    numRowsIn = in->numRows;
-    numColsIn = in->numCols;
-    numRowsOut = out->numRows;
-    numColsOut = out->numCols;
-
-    if(numRowsIn!=numColsOut && numRowsOut!=numColsIn) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Number of rows do not match number of columns."));
-        TRANSPOSE_CLEANUP;
-    }
-
-    if(out->type.type == PS_TYPE_F32) {
-        for(i=0; i<numRowsOut; i++) {
-            for(j=0; j<numColsOut; j++) {
-                out->data.F32[i][j] = in->data.F32[j][i];
-            }
-        }
-    } else {
-        for(i=0; i<numRowsOut; i++) {
-            for(j=0; j<numColsOut; j++) {
-                out->data.F64[i][j] = in->data.F64[j][i];
-            }
-        }
+    int numCols = in->numRows, numRows = in->numCols; // Size of transposed image
+    psElemType type = in->type.type;    // Data type
+
+    out = psImageRecycle(out, numCols, numRows, type);
+
+#define TRANSPOSE_CASE(TYPE) \
+  case PS_TYPE_##TYPE: { \
+      for (int i = 0; i < numRows; i++) { \
+          for (int j = 0; j < numCols; j++) { \
+              out->data.TYPE[i][j] = in->data.TYPE[j][i]; \
+          } \
+      } \
+      break; \
+  }
+
+    switch (type) {
+        TRANSPOSE_CASE(F32);
+        TRANSPOSE_CASE(F64);
+      default:
+        psAbort("Unsupported type: %x", type);
     }
 
