Index: branches/pap/psLib/src/math/psMatrix.c
===================================================================
--- branches/pap/psLib/src/math/psMatrix.c	(revision 25862)
+++ branches/pap/psLib/src/math/psMatrix.c	(revision 25864)
@@ -103,4 +103,6 @@
 static void vectorPStoGSL(gsl_vector *out, const psVector *in)
 {
+    psAssert(out->size == in->n, "Sizes don't match!");
+
     long n = in->n;                     // Size of input
     switch (in->type.type) {
@@ -122,4 +124,6 @@
 static void vectorGSLtoPS(psVector *out, const gsl_vector *in)
 {
+    psAssert(in->size == out->n, "Sizes don't match!");
+
     long n = out->n;                    // Size of output
     switch (out->type.type) {
@@ -142,4 +146,6 @@
 static void matrixPStoGSL(gsl_matrix *out, const psImage *in)
 {
+    psAssert(out->size1 == in->numRows && out->size2 == in->numCols, "Sizes don't match!");
+
     int numCols = in->numCols, numRows = in->numRows; // Size of matrix
     switch (in->type.type) {
@@ -152,10 +158,10 @@
         break;
       case PS_TYPE_F64:
-        if (in->parent) {
+        if (in->parent|| out->tda != out->size1) {
             for (int y = 0, i = 0; y < numRows; y++, i += numCols) {
                 memcpy(&out->data[i], in->data.F64[y], numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
             }
         } else {
-            memcpy(out->data, in->data.F64, numCols * numRows * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
+            memcpy(out->data, in->p_rawDataBuffer, numCols * numRows * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
         }
         break;
@@ -167,6 +173,8 @@
 
 /** Static function to copy GSL matrix data to a psF32 or psF64 image */
-static void matrixGSLtoPS(psImage *out, gsl_matrix *in)
-{
+static void matrixGSLtoPS(psImage *out, const gsl_matrix *in)
+{
+    psAssert(in->size1 == out->numRows && in->size2 == out->numCols, "Sizes don't match!");
+
     int numCols = out->numCols, numRows = out->numRows; // Size of matrix
     switch (out->type.type) {
@@ -179,10 +187,10 @@
         break;
       case PS_TYPE_F64:
-        if (out->parent) {
+        if (out->parent || in->tda != in->size1) {
             for (int y = 0, i = 0; y < numRows; y++, i += numCols) {
                 memcpy(out->data.F64[y], &in->data[i], numCols * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
             }
         } else {
-            memcpy(out->data.F64, in->data, numCols * numRows * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
+            memcpy(out->p_rawDataBuffer, in->data, numCols * numRows * PSELEMTYPE_SIZEOF(PS_TYPE_F64));
         }
         break;
