/[escript]/branches/schroedinger/escript/src/Data.cpp
ViewVC logotype

Diff of /branches/schroedinger/escript/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 800 by gross, Tue Aug 8 11:23:18 2006 UTC revision 804 by gross, Thu Aug 10 01:12:16 2006 UTC
# Line 1316  Data::minval() const Line 1316  Data::minval() const
1316  }  }
1317    
1318  Data  Data
1319  Data::swap(int axis_offset) const  Data::swapaxes(const int axis0, const int axis1) const
1320  {  {
1321         int axis0_tmp,axis1_tmp;
1322       #if defined DOPROF       #if defined DOPROF
1323       profData->unary++;       profData->unary++;
1324       #endif       #endif
# Line 1326  Data::swap(int axis_offset) const Line 1327  Data::swap(int axis_offset) const
1327       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1328       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1329       int rank=getDataPointRank();       int rank=getDataPointRank();
1330       if (axis_offset<0 || axis_offset+1>rank) {       if (rank<2) {
1331          throw DataException("Error - Data::transpose must have 0 <= axis_offset <= rank-1=" + rank-1);          throw DataException("Error - Data::swapaxes argument must have at least rank 2.");
1332         }
1333         if (axis0<0 || axis0>rank-1) {
1334            throw DataException("Error - Data::swapaxes: axis0 must be between 0 and rank-1=" + rank-1);
1335         }
1336         if (axis1<0 || axis1>rank-1) {
1337             throw DataException("Error - Data::swapaxes: axis1 must be between 0 and rank-1=" + rank-1);
1338         }
1339         if (axis0 == axis1) {
1340             throw DataException("Error - Data::swapaxes: axis indices must be different.");
1341         }
1342         if (axis0 > axis1) {
1343             axis0_tmp=axis1;
1344             axis1_tmp=axis0;
1345         } else {
1346             axis0_tmp=axis0;
1347             axis1_tmp=axis1;
1348       }       }
1349       for (int i=0; i<rank; i++) {       for (int i=0; i<rank; i++) {
1350         if (i == axis_offset) {         if (i == axis0_tmp) {
1351            ev_shape.push_back(s[axis_offset+1]);            ev_shape.push_back(s[axis1_tmp]);
1352         } else if (i == axis_offset+1) {         } else if (i == axis1_tmp) {
1353            ev_shape.push_back(s[axis_offset]);            ev_shape.push_back(s[axis0_tmp]);
1354         } else {         } else {
1355            ev_shape.push_back(s[i]);            ev_shape.push_back(s[i]);
1356         }         }
1357       }       }
1358       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1359       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1360       m_data->swap(ev.m_data.get(), axis_offset);       m_data->swapaxes(ev.m_data.get(), axis0_tmp, axis1_tmp);
1361       return ev;       return ev;
1362    
1363  }  }

Legend:
Removed from v.800  
changed lines
  Added in v.804

  ViewVC Help
Powered by ViewVC 1.1.26