/[escript]/trunk/escript/src/Data.cpp
ViewVC logotype

Diff of /trunk/escript/src/Data.cpp

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

revision 757 by woo409, Mon Jun 26 13:12:56 2006 UTC revision 775 by ksteube, Mon Jul 10 04:00:08 2006 UTC
# Line 1215  Data::trace() const Line 1215  Data::trace() const
1215  }  }
1216    
1217  Data  Data
1218  Data::transpose(int axis) const  Data::symmetric() const
1219    {
1220         #if defined DOPROF
1221            profData->unary++;
1222         #endif
1223         // check input
1224         DataArrayView::ShapeType s=getDataPointShape();
1225         if (getDataPointRank()==2) {
1226            if(s[0] != s[1])
1227               throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");
1228         }
1229         else if (getDataPointRank()==4) {
1230            if(!(s[0] == s[2] && s[1] == s[3]))
1231               throw DataException("Error - Data::symmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");
1232         }
1233         else {
1234            throw DataException("Error - Data::symmetric can only be calculated for rank 2 or 4 object.");
1235         }
1236         Data ev(0.,getDataPointShape(),getFunctionSpace());
1237         ev.typeMatchRight(*this);
1238         m_data->symmetric(ev.m_data.get());
1239         return ev;
1240    }
1241    
1242    Data
1243    Data::nonsymmetric() const
1244    {
1245         #if defined DOPROF
1246            profData->unary++;
1247         #endif
1248         // check input
1249         DataArrayView::ShapeType s=getDataPointShape();
1250         if (getDataPointRank()==2) {
1251            if(s[0] != s[1])
1252               throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");
1253            DataArrayView::ShapeType ev_shape;
1254            ev_shape.push_back(s[0]);
1255            ev_shape.push_back(s[1]);
1256            Data ev(0.,ev_shape,getFunctionSpace());
1257            ev.typeMatchRight(*this);
1258            m_data->nonsymmetric(ev.m_data.get());
1259            return ev;
1260         }
1261         else if (getDataPointRank()==4) {
1262            if(!(s[0] == s[2] && s[1] == s[3]))
1263               throw DataException("Error - Data::nonsymmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");
1264            DataArrayView::ShapeType ev_shape;
1265            ev_shape.push_back(s[0]);
1266            ev_shape.push_back(s[1]);
1267            ev_shape.push_back(s[2]);
1268            ev_shape.push_back(s[3]);
1269            Data ev(0.,ev_shape,getFunctionSpace());
1270            ev.typeMatchRight(*this);
1271            m_data->nonsymmetric(ev.m_data.get());
1272            return ev;
1273         }
1274         else {
1275            throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 or 4 object.");
1276         }
1277    }
1278    
1279    Data
1280    Data::matrixtrace(int axis_offset) const
1281    {
1282         #if defined DOPROF
1283            profData->unary++;
1284         #endif
1285         DataArrayView::ShapeType s=getDataPointShape();
1286         if (getDataPointRank()==2) {
1287            DataArrayView::ShapeType ev_shape;
1288            Data ev(0.,ev_shape,getFunctionSpace());
1289            ev.typeMatchRight(*this);
1290            m_data->matrixtrace(ev.m_data.get(), axis_offset);
1291            return ev;
1292         }
1293         if (getDataPointRank()==3) {
1294            DataArrayView::ShapeType ev_shape;
1295            if (axis_offset==0) {
1296              int s2=s[2];
1297              ev_shape.push_back(s2);
1298            }
1299            else if (axis_offset==1) {
1300              int s0=s[0];
1301              ev_shape.push_back(s0);
1302            }
1303            Data ev(0.,ev_shape,getFunctionSpace());
1304            ev.typeMatchRight(*this);
1305            m_data->matrixtrace(ev.m_data.get(), axis_offset);
1306            return ev;
1307         }
1308         if (getDataPointRank()==4) {
1309            DataArrayView::ShapeType ev_shape;
1310            if (axis_offset==0) {
1311              ev_shape.push_back(s[2]);
1312              ev_shape.push_back(s[3]);
1313            }
1314            else if (axis_offset==1) {
1315              ev_shape.push_back(s[0]);
1316              ev_shape.push_back(s[3]);
1317            }
1318        else if (axis_offset==2) {
1319          ev_shape.push_back(s[0]);
1320          ev_shape.push_back(s[1]);
1321        }
1322            Data ev(0.,ev_shape,getFunctionSpace());
1323            ev.typeMatchRight(*this);
1324        m_data->matrixtrace(ev.m_data.get(), axis_offset);
1325            return ev;
1326         }
1327         else {
1328            throw DataException("Error - Data::matrixtrace can only be calculated for rank 2, 3 or 4 object.");
1329         }
1330    }
1331    
1332    Data
1333    Data::transpose(int axis_offset) const
1334  {  {
1335  #if defined DOPROF  #if defined DOPROF
1336    profData->reduction2++;       profData->reduction2++;
1337  #endif  #endif
1338         DataArrayView::ShapeType s=getDataPointShape();
1339    // not implemented       DataArrayView::ShapeType ev_shape;
1340    throw DataException("Error - Data::transpose not implemented yet.");       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1341    return Data();       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1342         int rank=getDataPointRank();
1343         if (axis_offset<0 || axis_offset>rank) {
1344            throw DataException("Error - Data::transpose must have 0 <= axis_offset <= rank=" + rank);
1345         }
1346         for (int i=0; i<rank; i++) {
1347           int index = (axis_offset+i)%rank;
1348           ev_shape.push_back(s[index]); // Append to new shape
1349         }
1350         Data ev(0.,ev_shape,getFunctionSpace());
1351         ev.typeMatchRight(*this);
1352         m_data->transpose(ev.m_data.get(), axis_offset);
1353         return ev;
1354  }  }
1355    
1356  Data  Data

Legend:
Removed from v.757  
changed lines
  Added in v.775

  ViewVC Help
Powered by ViewVC 1.1.26