/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataArrayView.cpp
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/DataArrayView.cpp

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

revision 576 by gross, Fri Mar 3 08:28:42 2006 UTC revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC
# Line 1  Line 1 
 // $Id$  
1    
2  /*  /* $Id$ */
3   ******************************************************************************  
4   *                                                                            *  /*******************************************************
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *
6   *                                                                            *   *           Copyright 2003-2007 by ACceSS MNRF
7   * This software is the property of ACcESS. No part of this code              *   *       Copyright 2007 by University of Queensland
8   * may be copied in any form or by any means without the expressed written    *   *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *                http://esscc.uq.edu.au
10   * by any unauthorised person is illegal unless that person has a software    *   *        Primary Business: Queensland, Australia
11   * license agreement with ACcESS.                                             *   *  Licensed under the Open Software License version 3.0
12   *                                                                            *   *     http://www.opensource.org/licenses/osl-3.0.php
13   ******************************************************************************   *
14  */   *******************************************************/
15    
16  #include "DataArrayView.h"  #include "DataArrayView.h"
17  #include "DataException.h"  #include "DataException.h"
# Line 370  getSliceRange(const boost::python::objec Line 369  getSliceRange(const boost::python::objec
369    }    }
370    if (s0 < 0)    if (s0 < 0)
371       throw DataException("Error - slice index out of range.");       throw DataException("Error - slice index out of range.");
372    if (s0 == s1 and s1 >= shape)    if (s0 == s1 && s1 >= shape)
373       throw DataException("Error - slice index out of range.");       throw DataException("Error - slice index out of range.");
374    if (s0 != s1 and  s1>shape)    if (s0 != s1 &&  s1>shape)
375       throw DataException("Error - slice index out of range.");       throw DataException("Error - slice index out of range.");
376    if (s0 > s1)    if (s0 > s1)
377       throw DataException("Error - lower index must less or equal upper index.");       throw DataException("Error - lower index must less or equal upper index.");
# Line 663  DataArrayView::toString(const string& su Line 662  DataArrayView::toString(const string& su
662        break;        break;
663      case 1:      case 1:
664        for (int i=0;i<getShape()[0];i++) {        for (int i=0;i<getShape()[0];i++) {
665      temp << "(" << i << ") " << finalSuffix << (*this)(i);      temp << finalSuffix << "(" << i << ") " << (*this)(i);
666      if (i!=(getShape()[0]-1)) {      if (i!=(getShape()[0]-1)) {
667        temp << endl;        temp << endl;
668      }      }
# Line 672  DataArrayView::toString(const string& su Line 671  DataArrayView::toString(const string& su
671      case 2:      case 2:
672        for (int i=0;i<getShape()[0];i++) {        for (int i=0;i<getShape()[0];i++) {
673      for (int j=0;j<getShape()[1];j++) {      for (int j=0;j<getShape()[1];j++) {
674        temp << "(" << i << "," << j << ") " << finalSuffix << (*this)(i,j);        temp << finalSuffix << "(" << i << "," << j << ") " << (*this)(i,j);
675        if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1))) {        if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1))) {
676          temp << endl;          temp << endl;
677        }        }
# Line 683  DataArrayView::toString(const string& su Line 682  DataArrayView::toString(const string& su
682        for (int i=0;i<getShape()[0];i++) {        for (int i=0;i<getShape()[0];i++) {
683      for (int j=0;j<getShape()[1];j++) {      for (int j=0;j<getShape()[1];j++) {
684        for (int k=0;k<getShape()[2];k++) {        for (int k=0;k<getShape()[2];k++) {
685          temp << "(" << i << "," << j << "," << k << ") " << finalSuffix << (*this)(i,j,k);          temp << finalSuffix << "(" << i << "," << j << "," << k << ") " << (*this)(i,j,k);
686          if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1) && k==(getShape()[2]-1))) {          if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1) && k==(getShape()[2]-1))) {
687            temp << endl;            temp << endl;
688          }          }
# Line 696  DataArrayView::toString(const string& su Line 695  DataArrayView::toString(const string& su
695      for (int j=0;j<getShape()[1];j++) {      for (int j=0;j<getShape()[1];j++) {
696        for (int k=0;k<getShape()[2];k++) {        for (int k=0;k<getShape()[2];k++) {
697          for (int l=0;l<getShape()[3];l++) {          for (int l=0;l<getShape()[3];l++) {
698            temp << "(" << i << "," << j << "," << k << "," << l << ") " << finalSuffix << (*this)(i,j,k,l);            temp << finalSuffix << "(" << i << "," << j << "," << k << "," << l << ") " << (*this)(i,j,k,l);
699            if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1) && k==(getShape()[2]-1) && l==(getShape()[3]-1))) {            if (!(i==(getShape()[0]-1) && j==(getShape()[1]-1) && k==(getShape()[2]-1) && l==(getShape()[3]-1))) {
700              temp << endl;              temp << endl;
701            }            }
# Line 728  DataArrayView::shapeToString(const DataA Line 727  DataArrayView::shapeToString(const DataA
727      return temp.str();      return temp.str();
728  }  }
729    
 void  
 DataArrayView::eigenvalues(const DataArrayView& in,  
                            DataArrayView& ev)  
 {  
    EsysAssert(!in.isEmpty(),  
                "Error - in view is empty.");  
    EsysAssert(!ev.isEmpty(),  
                "Error - ev view is empty.");  
    EsysAssert(in.getRank()==2,  
                "Error - in has not rank 2.");  
    EsysAssert(in.getShape()[0]==in.getShape()[1],  
                "Error - in is not square");  
    EsysAssert(ev.getRank()==1,  
                "Error - ev has not rank 1.");  
    EsysAssert(ev.getShape()[0]==in.getShape()[0],  
                "Error - ev is too short");  
    EsysAssert(0<ev.getShape()[0] && ev.getShape()[0]<4,  
                "Error - dimension is restricted to 3.");  
    double ev0,ev1,ev2;  
    int s=in.getShape()[0];  
    if (s==1) {  
       eigenvalues1(in(0,0),&ev0);  
       ev(0)=ev0;  
   
    } else  if (s==2) {  
       eigenvalues2(in(0,0),(in(0,1)+in(1,0))/2.,in(1,1),  
                    &ev0,&ev1);  
       ev(0)=ev0;  
       ev(1)=ev1;  
   
    } else  if (s==3) {  
       eigenvalues3(in(0,0),(in(0,1)+in(1,0))/2.,(in(0,2)+in(2,0))/2.,in(1,1),(in(2,1)+in(1,2))/2.,in(2,2),  
                  &ev0,&ev1,&ev2);  
       ev(0)=ev0;  
       ev(1)=ev1;  
       ev(2)=ev2;  
   
    }  
 }  
   
730  void  void
731  DataArrayView::matMult(const DataArrayView& left,  DataArrayView::matMult(const DataArrayView& left,
732                         const DataArrayView& right,                         const DataArrayView& right,

Legend:
Removed from v.576  
changed lines
  Added in v.1388

  ViewVC Help
Powered by ViewVC 1.1.26