Index: trunk/psLib/src/math/psMatrix.c
===================================================================
--- trunk/psLib/src/math/psMatrix.c	(revision 878)
+++ trunk/psLib/src/math/psMatrix.c	(revision 908)
@@ -20,6 +20,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-04 23:49:59 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-08 01:57:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,4 +35,5 @@
 #include <gsl/gsl_eigen.h>
 
+#include "psMemory.h"
 #include "psError.h"
 #include "psImage.h"
@@ -253,4 +254,8 @@
 
     // Error checks
+    if(det == NULL) {
+        psError(__func__, "Invalid operation: determinant argument is NULL.");
+        return outImage;
+    }
     PS_CHECK_POINTERS(inImage, outImage, outImage);
     PS_CHECK_NULL_IMAGE(inImage, outImage);
@@ -292,5 +297,5 @@
 }
 
-float psMatrixDeterminant(const psImage *restrict inImage)
+float* psMatrixDeterminant(const psImage *restrict inImage)
 {
     int signum = 0;
@@ -298,12 +303,12 @@
     int numRows = 0;
     int numCols = 0;
-    float det = 0.0f;
+    float *det = NULL;
     gsl_matrix *lu = NULL;
     gsl_permutation *perm = NULL;
 
     // Error checks
-    PS_CHECK_NULL_IMAGE(inImage, 0);
-    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, 0);
-    PS_CHECK_SIZE_IMAGE(inImage, 0);
+    PS_CHECK_NULL_IMAGE(inImage, NULL);
+    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL);
+    PS_CHECK_SIZE_IMAGE(inImage, NULL);
 
     // Initialize data
@@ -323,6 +328,7 @@
 
     // Calculate determinant
+    det = (float*)psAlloc(sizeof(float));
     gsl_linalg_LU_decomp(lu, perm, &signum);
-    det = (float)gsl_linalg_LU_det(lu, signum);
+    *det = (float)gsl_linalg_LU_det(lu, signum);
 
     // Free GSL structs
@@ -458,5 +464,5 @@
 psVector *psMatrixToVector(psVector *outVector, psImage *inImage)
 {
-    int colSize = 0;
+    int size = 0;
 
     // Error checks
@@ -464,24 +470,52 @@
     PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
     PS_CHECK_SIZE_IMAGE(inImage, outVector);
-    PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
-    PS_CHECK_NULL_VECTOR(outVector, outVector);
-    PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
-
-    // Set n if allocated, but empty
-    if(outVector->n == 0) {
-        outVector->n = inImage->numRows;
-    }
-
-    // More checks
-    if(inImage->numCols > 1) {
-        psError(__func__, "Image has more than 1 column: numCols = %d.", inImage->numCols);
-        return outVector;
-    } else if(outVector->n != inImage->numRows) {
-        psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
+
+    if(inImage->numRows == 1) {
+        // Create transposed row vector
+        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);
+        outVector->type.dimen = PS_DIMEN_TRANSV;
+    } else if(inImage->numCols == 1) {
+        // Create non-transposed column vector
+        PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
+    } else {
+        psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows,
+                inImage->numCols);
         return outVector;
     }
 
-    colSize = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
-    memcpy(outVector->data.V, inImage->data.V[0], colSize);
+    PS_CHECK_NULL_VECTOR(outVector, outVector);
+
+
+    // More checks
+    if(outVector->type.dimen == PS_DIMEN_VECTOR) {
+        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
+
+        if(outVector->n == 0) {
+            outVector->n = inImage->numRows;
+        }
+
+        if(outVector->n != inImage->numRows) {
+            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
+            return outVector;
+        }
+
+        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numRows;
+
+    } else if(outVector->type.dimen == PS_DIMEN_TRANSV) {
+        PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_TRANSV, outVector);
+
+        if(outVector->n == 0) {
+            outVector->n = inImage->numCols;
+        }
+
+        if(outVector->n != inImage->numCols) {
+            psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n);
+            return outVector;
+        }
+
+        size = PSELEMTYPE_SIZEOF(inImage->type.type)*inImage->numCols;
+    }
+
+    memcpy(outVector->data.V, inImage->data.V[0], size);
 
     return outVector;
@@ -490,25 +524,46 @@
 psImage *psVectorToMatrix(psImage *outImage, psVector *inVector)
 {
-    int colSize = 0;
+    int size = 0;
 
     // Error checks
     PS_CHECK_NULL_VECTOR(inVector, outImage);
-    PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
-    PS_CHECK_SIZE_VECTOR(inVector, outImage);
-    PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F32)
+
+    if(inVector->type.dimen == PS_DIMEN_VECTOR) {
+        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
+        PS_CHECK_SIZE_VECTOR(inVector, outImage);
+        PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)
+
+        // More checks for PS_DIMEN_VECTOR
+        if(outImage->numCols > 1) {
+            psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
+            return outImage;
+        } else if(outImage->numRows != inVector->n) {
+            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
+            return outImage;
+        }
+
+        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
+
+    } else if(inVector->type.dimen == PS_DIMEN_TRANSV) {
+        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage);
+        PS_CHECK_SIZE_VECTOR(inVector, outImage);
+        PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)
+
+        // More checks for PS_DIMEN_TRANSV
+        if(outImage->numRows > 1) {
+            psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows);
+            return outImage;
+        } else if(outImage->numCols != inVector->n) {
+            psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n);
+            return outImage;
+        }
+
+        size = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numCols;
+    }
+
     PS_CHECK_NULL_IMAGE(outImage, outImage);
     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
 
-    // More checks
-    if(outImage->numCols > 1) {
-        psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
-        return outImage;
-    } else if(outImage->numRows != inVector->n) {
-        psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
-        return outImage;
-    }
-
-    colSize = PSELEMTYPE_SIZEOF(outImage->type.type)*outImage->numRows;
-    memcpy(outImage->data.V[0], inVector->data.V, colSize);
+    memcpy(outImage->data.V[0], inVector->data.V, size);
 
     return outImage;
