Index: trunk/psLib/test/math/tap_psHistogram.c
===================================================================
--- trunk/psLib/test/math/tap_psHistogram.c	(revision 17566)
+++ trunk/psLib/test/math/tap_psHistogram.c	(revision 17567)
@@ -5,5 +5,5 @@
     psVectorHistogram(): uniform histograms
     psVectorHistogram(): generic histograms
- *****************************************************************************/
+*****************************************************************************/
 #include <stdio.h>
 #include <string.h>
@@ -67,5 +67,5 @@
         for (int i=0;i<numBins+1;i++) {
             myBounds->data.F32[i] = lower + ((higher - lower) / (float) numBins) *
-                                    (float) i;
+		(float) i;
         }
         psHistogram *myHist = psHistogramAllocGeneric(myBounds);
@@ -134,24 +134,24 @@
         skip_start(myHist == NULL, 1, "Skipping tests because psVectorHistogram() returned NULL");
 
-	// we need to explicitly count the number in each bin.  we can fool ourselves with rounding
-	// otherwise
-
         bool errorFlag = false;
         for (int i = 0; i < numBins; i++) {
-	  int nValues = 0;
-	  for (int j = 0; j < myData->n; j++) {
-	    // XXX EAM : need to get rules right.  which boundary is inclusive, which is exclusive?
-	    if (myData->data.F32[j] <= myHist->bounds->data.F32[i]) continue;
-	    if (myData->data.F32[j] > myHist->bounds->data.F32[i+1]) continue;
-	    nValues ++;
-	  }
-	  if (myHist->nums->data.F32[i] != nValues) {
-	    diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n",
-		 i,
-		 myHist->bounds->data.F32[i],
-		 myHist->bounds->data.F32[i+1],
-		 myHist->nums->data.F32[i], nValues);
-	    errorFlag = true;
-	  }
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
+		diag("Bin number %d bounds: (%.2f - %.2f) data (%.2f) should be (%2d)\n",
+		     i,
+		     myHist->bounds->data.F32[i],
+		     myHist->bounds->data.F32[i+1],
+		     myHist->nums->data.F32[i], nValues);
+		errorFlag = true;
+	    }
         }
         ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
@@ -189,21 +189,22 @@
         bool errorFlag = false;
         for (int i = 0;i < numBins;i++) {
-            if (i < numBins/2) {
-                if (fabs(myHist->nums->data.F32[i] - (NUM_DATA/numBins)) > ERROR_TOLERANCE) {
-                    diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
-                         myHist->bounds->data.F32[i],
-                         myHist->bounds->data.F32[i + 1],
-                         myHist->nums->data.F32[i], (float) (NUM_DATA/numBins));
-                    errorFlag = true;
-                }
-            } else {
-                if (fabs(myHist->nums->data.F32[i]) > ERROR_TOLERANCE) {
-                    diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
-                         myHist->bounds->data.F32[i],
-                         myHist->bounds->data.F32[i + 1],
-                         myHist->nums->data.F32[i], 0.0);
-                    errorFlag = true;
-                }
-            }
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myMask->data.U8[j] == 1) continue;
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
+		diag("Bin number %d bounds: (%6.3f - %6.3f) data (%f) should be (%.2f)\n", i,
+		     myHist->bounds->data.F32[i],
+		     myHist->bounds->data.F32[i + 1],
+		     myHist->nums->data.F32[i], (float) (NUM_DATA/numBins));
+		errorFlag = true;
+	    }
         }
         ok(!errorFlag, "psVectorHistogram() correctly set the histogram");
@@ -226,5 +227,5 @@
         }
         ok(false == psVectorHistogram(NULL, myData, NULL, NULL, 0),
-          "psVectorHistogram() returned FALSE with a NULL psHistogram input");
+	   "psVectorHistogram() returned FALSE with a NULL psHistogram input");
         psFree(myData);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -239,5 +240,5 @@
         psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
         ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0),
-          "psVectorHistogram() returns TRUE with a NULL input array");
+	   "psVectorHistogram() returns TRUE with a NULL input array");
         psFree(myHist);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -253,5 +254,5 @@
         psHistogram *myHist = psHistogramAlloc(lower, higher, numBins);
         ok(true == psVectorHistogram(myHist, NULL, NULL, NULL, 0),
-          "psVectorHistogram() returns TRUE with an empty input array");
+	   "psVectorHistogram() returns TRUE with an empty input array");
         psFree(myHist);
         psFree(myData);
@@ -301,14 +302,23 @@
         skip_start(rc == false, 1, "Skipping tests because psVectorHistogram() returned FALSE");
         for (int i=0;i<numBins;i++) {
-            psF32 expected = ((float) NUM_DATA) / ((float) numBins);
-            if (fabs(myHist->nums->data.F32[i] - expected) > ERROR_TOLERANCE) {
+
+	    // we need to explicitly count the number in each bin.  we can fool ourselves with
+	    // rounding otherwise
+	    int nValues = 0;
+	    for (int j = 0; j < myData->n; j++) {
+		// valid bin: bound[bin] <= value < bound[bin+1]
+		if (myData->data.F32[j] < myHist->bounds->data.F32[i]) continue;
+		if (myData->data.F32[j] >= myHist->bounds->data.F32[i+1]) continue;
+		nValues ++;
+	    }
+	    if (myHist->nums->data.F32[i] != nValues) {
                 diag("Bin number %d bounds: (%.2f - %.2f): data: (%.2f) should be (%.2f)\n", i,
                      myHist->bounds->data.F32[i],
                      myHist->bounds->data.F32[i+1],
-                     myHist->nums->data.F32[i], expected);
+                     myHist->nums->data.F32[i], nValues);
                 errorFlag = true;
             }
         }
-        ok(!errorFlag, "psVectorHistogram() correctly initialized the bins");
+        ok(!errorFlag, "psVectorHistogram() correctly set the bins");
         skip_end();
         psFree(myData);
Index: trunk/psLib/test/math/tap_psMatrix02.c
===================================================================
--- trunk/psLib/test/math/tap_psMatrix02.c	(revision 17566)
+++ trunk/psLib/test/math/tap_psMatrix02.c	(revision 17567)
@@ -12,6 +12,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2007-05-02 04:20:06 $
+ *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2008-05-07 23:12:13 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,5 @@
 {
     psLogSetFormat("HLNM");
-    plan_tests(11);
+    plan_tests(23);
 
     // Input pointer same as output pointer
@@ -34,9 +34,8 @@
     // a requirement.  However, we should probably fix the case where the input
     // image equals the output image.
-    if (0) {
+     {
         psMemId id = psMemGetId();
         psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
-        ok(psMatrixTranspose(inImage, inImage) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL");
-        ok(psMemGetRefCounter(inImage) == 1, "psMatrixTranspose(): the output image was freed on an error.");
+        ok(psMatrixTranspose(inImage, inImage) == NULL, "psMatrixTranspose(): inImage == outImage results in NULL");
         psFree(inImage);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
@@ -50,26 +49,30 @@
         psImage *nullImage = NULL;
         psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
-        psMemIncrRefCounter(outImage);
         ok(psMatrixTranspose(outImage, nullImage) == NULL, "psMatrixTranspose(): inImage = NULL results in NULL return");
-        ok(psMemGetRefCounter(outImage) == 1, "psMatrixTranspose(): the output image was freed on an error.");
         psFree(outImage);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
 
-
     // Incorrect type for input pointer
-    // Merge with tap_psMatrix01.c, get rid of this test (redundant)
     {
         psMemId id = psMemGetId();
+        psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8);
         psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
-        psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8);
-        psMemIncrRefCounter(outImage);
-        ok(psMatrixTranspose(outImage, badImage1) == NULL, "psMatrixTranspose(): inImage = outImage results in NULL return");
-        ok(psMemGetRefCounter(outImage) == 1, "the output image was freed on the error.");
+        ok(psMatrixTranspose(outImage, inImage) == NULL, "psMatrixTranspose(): inImage wrong type (U8) results in NULL return");
         psFree(outImage);
-        psFree(badImage1);
+        psFree(inImage);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
 
+    // Incorrect type for input pointer
+    {
+        psMemId id = psMemGetId();
+        psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_S32);
+        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
+        ok(psMatrixTranspose(outImage, inImage) == NULL, "psMatrixTranspose(): inImage wrong type (S32) results in NULL return");
+        psFree(outImage);
+        psFree(inImage);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
 
     // Incorrect type for output pointer
@@ -77,24 +80,51 @@
         psMemId id = psMemGetId();
         psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
-        psImage *badImage1 = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8);
-        badImage1 = psMatrixTranspose(badImage1, inImage);
-        ok(badImage1 != NULL, "psMatrixTranspose() results in non-NULL return");
+        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_U8);
+        outImage = psMatrixTranspose(outImage, inImage);
+        ok(outImage != NULL, "psMatrixTranspose() results in non-NULL return");
+
         // check that the type was changed.
-        ok(badImage1->type.type == PS_TYPE_F64, "the output type was changed to F64");
+        ok(outImage->type.type == PS_TYPE_F64, "the output type was changed to F64");
         psFree(inImage);
-        psFree(badImage1);
+        psFree(outImage);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
 
-
-    // Matrix not square for output pointer
-    // XXX: We should probably do more here.
+    // output target matrix not square (Nx > Ny) for output pointer
     {
         psMemId id = psMemGetId();
         psImage *inImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
-        psImage *badImage2 = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64);
-        ok(psMatrixTranspose(badImage2, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL");
+        psImage *outImage = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64);
+        ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL");
+        ok(outImage->numCols == 3, "psMatrixTranspose(): output matrix dimensions match input");
+        ok(outImage->numRows == 3, "psMatrixTranspose(): output matrix dimensions match input");
         psFree(inImage);
-        psFree(badImage2);
+        psFree(outImage);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    // input matrix not square (Nx < Ny) 
+    {
+        psMemId id = psMemGetId();
+        psImage *inImage = (psImage*)psImageAlloc(2, 3, PS_TYPE_F64);
+        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
+        ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL");
+        ok(outImage->numCols == 3, "psMatrixTranspose(): output matrix dimensions match input");
+        ok(outImage->numRows == 2, "psMatrixTranspose(): output matrix dimensions match input");
+        psFree(inImage);
+        psFree(outImage);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    // input matrix not square (Nx > Ny) 
+    {
+        psMemId id = psMemGetId();
+        psImage *inImage = (psImage*)psImageAlloc(3, 2, PS_TYPE_F64);
+        psImage *outImage = (psImage*)psImageAlloc(3, 3, PS_TYPE_F64);
+        ok(psMatrixTranspose(outImage, inImage) != NULL, "psMatrixTranspose(): non-square matrix results in non-NULL");
+        ok(outImage->numCols == 2, "psMatrixTranspose(): output matrix dimensions match input");
+        ok(outImage->numRows == 3, "psMatrixTranspose(): output matrix dimensions match input");
+        psFree(inImage);
+        psFree(outImage);
         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     }
Index: trunk/psLib/test/math/tap_psPolyFit2D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 17566)
+++ trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 17567)
@@ -424,5 +424,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y);
-            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set x vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial2D() returned TRUE: x vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -433,5 +433,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32);
-            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set y vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial2D() returned TRUE: y vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
Index: trunk/psLib/test/math/tap_psPolyFit3D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit3D.c	(revision 17566)
+++ trunk/psLib/test/math/tap_psPolyFit3D.c	(revision 17567)
@@ -476,5 +476,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z);
-            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set x vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: x vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -485,5 +485,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z);
-            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set y vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: y vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -494,5 +494,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32);
-            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set z vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial3D() returned TRUE: z vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
Index: trunk/psLib/test/math/tap_psPolyFit4D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 17566)
+++ trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 17567)
@@ -536,5 +536,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z, t);
-            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set x vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: x vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -545,5 +545,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z, t);
-            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set y vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: y vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -554,5 +554,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32, t);
-            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set z vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: z vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
@@ -563,5 +563,5 @@
             psMemId id = psMemGetId();
             bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, tS32);
-            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set t vector to incorrect type");
+            ok(rc == true, "psVectorFitPolynomial4D() returned TRUE: t vector may be S32");
             ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
         }
