IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15768


Ignore:
Timestamp:
Dec 7, 2007, 3:48:34 PM (18 years ago)
Author:
Paul Price
Message:

Fixing psMatrixTranspose to allow transposition of non-square matrices.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMatrix.c

    r15767 r15768  
    2222 *  @author Andy Becker, University of Washington (SVD).
    2323 *
    24  *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    25  *  @date $Date: 2007-12-08 01:31:58 $
     24 *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     25 *  @date $Date: 2007-12-08 01:48:34 $
    2626 *
    2727 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4242#include <gsl/gsl_eigen.h>
    4343
     44#include "psAbort.h"
    4445#include "psMemory.h"
    4546#include "psError.h"
     
    657658}
    658659
    659 psImage* psMatrixTranspose(psImage* out,
    660                            const psImage* in)
    661 {
    662     psU32 i = 0;
    663     psU32 j = 0;
    664     psS32 numRowsIn = 0;
    665     psS32 numColsIn = 0;
    666     psS32 numRowsOut = 0;
    667     psS32 numColsOut = 0;
    668 
    669     #define TRANSPOSE_CLEANUP { psFree(out); return NULL; }
     660psImage* psMatrixTranspose(psImage* out, const psImage* in)
     661{
    670662    // Error checks
     663    #define TRANSPOSE_CLEANUP { return NULL; }
    671664    PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, TRANSPOSE_CLEANUP);
    672665    PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, TRANSPOSE_CLEANUP);
     
    674667    PS_CHECK_POINTERS(in, out, TRANSPOSE_CLEANUP);
    675668
    676     out = psImageRecycle(out, in->numCols, in->numRows, in->type.type);
    677 
    678     // Initialize data
    679     numRowsIn = in->numRows;
    680     numColsIn = in->numCols;
    681     numRowsOut = out->numRows;
    682     numColsOut = out->numCols;
    683 
    684     if(numRowsIn!=numColsOut && numRowsOut!=numColsIn) {
    685         psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Number of rows do not match number of columns."));
    686         TRANSPOSE_CLEANUP;
    687     }
    688 
    689     if(out->type.type == PS_TYPE_F32) {
    690         for(i=0; i<numRowsOut; i++) {
    691             for(j=0; j<numColsOut; j++) {
    692                 out->data.F32[i][j] = in->data.F32[j][i];
    693             }
    694         }
    695     } else {
    696         for(i=0; i<numRowsOut; i++) {
    697             for(j=0; j<numColsOut; j++) {
    698                 out->data.F64[i][j] = in->data.F64[j][i];
    699             }
    700         }
     669    int numCols = in->numRows, numRows = in->numCols; // Size of transposed image
     670    psElemType type = in->type.type;    // Data type
     671
     672    out = psImageRecycle(out, numCols, numRows, type);
     673
     674#define TRANSPOSE_CASE(TYPE) \
     675  case PS_TYPE_##TYPE: { \
     676      for (int i = 0; i < numRows; i++) { \
     677          for (int j = 0; j < numCols; j++) { \
     678              out->data.TYPE[i][j] = in->data.TYPE[j][i]; \
     679          } \
     680      } \
     681      break; \
     682  }
     683
     684    switch (type) {
     685        TRANSPOSE_CASE(F32);
     686        TRANSPOSE_CASE(F64);
     687      default:
     688        psAbort("Unsupported type: %x", type);
    701689    }
    702690
Note: See TracChangeset for help on using the changeset viewer.