vecbse.cpp

Go to the documentation of this file.
00001 #include "arraybse.h"
00002 #include "vecbse.h"
00003 #include "matbse.h" 
00004 #include "matbse.h"
00005 #include "bnengine.h"
00006 #include "matbse.h" 
00007 #include "blas.h"
00008 //
00009 //***************************************************************
00010 //                    VECBSE.CPP
00011 //***************************************************************
00012 //
00013 //
00014 //*****************************************************************
00015 //
00016 //            Chris Anderson
00017 //
00018 //            Mon Sep 11 12:49:20 1995
00019 //
00020 //*****************************************************************
00021 //
00022 //
00023 //*****************************************************************
00024 //                    CONSTRUCTORS
00025 //*****************************************************************
00026 //
00027 //
00028 //*****************************************************************
00029 //               
00030 //*****************************************************************
00031 //
00032 CAMvectorBase::CAMvectorBase()
00033 : Structure()
00034 {
00035     DataP                   = 0;
00036     typeValue               = 0;
00037     referenceFlag           = 0;
00038     vectorBaseReferenceCount = 0;
00039 }
00040 
00041 CAMvectorBase::CAMvectorBase(int d_type)
00042 : Structure()
00043 {
00044     DataP                   = 0;
00045     typeValue               = d_type;
00046     referenceFlag           = 0;
00047     vectorBaseReferenceCount = 0;
00048 }
00049 
00050 CAMvectorBase::CAMvectorBase(const CAMvectorBase& A)
00051 :Structure(A.Structure)
00052 {
00053     if(A.DataP == 0)
00054     {DataP = 0;}
00055     else
00056     {
00057      if(A.referenceFlag == 1)
00058      {DataP = A.DataP; }
00059      else if(A.DataP->getTemporaryFlag() == 1)
00060      {
00061       DataP = new CAMdataHandler(*(A.DataP));
00062       DataP ->setReferenceCount(1);
00063      }
00064      else
00065      {
00066       A.Structure.initializeMinStructure(Structure);
00067       DataP = new CAMdataHandler(Structure.getFullDataCount(),A.DataP->getDataType());
00068       DataP->setReferenceCount(1);
00069       //
00070       //  copy based on type
00071       //
00072       CAMbinaryEngine::doubleAequalToB(Structure, *DataP, A.Structure, *A.DataP);
00073       //
00074       //
00075       //
00076      }
00077     }
00078     typeValue               = A.typeValue;
00079     referenceFlag           = 0;
00080     vectorBaseReferenceCount = 0;
00081 }
00082 
00083 CAMvectorBase::CAMvectorBase(int d_type, const CAMrange& R1)
00084 :Structure()
00085 {
00086      Structure.initialize(R1,_(R1.getBase(),R1.getBase()));
00087      DataP = new CAMdataHandler(Structure.getFullDataCount(),d_type);
00088      DataP->setReferenceCount(1);
00089      referenceFlag           = 0;
00090      vectorBaseReferenceCount = 0;
00091 }
00092 
00093 //
00094 //*****************************************************************
00095 //                    DESTRUCTOR
00096 //*****************************************************************
00097 //
00098 CAMvectorBase::~CAMvectorBase()
00099 {
00100     if(DataP != 0)
00101      {
00102      DataP->decrementReferenceCount();
00103     if(DataP->getReferenceCount() < 0)
00104     {
00105     cerr << " Error : Reference Count < 0" << endl;
00106      }
00107      if(DataP->getReferenceCount() == 0) delete DataP;
00108     }
00109 }
00110 void CAMvectorBase::operator =(double value)
00111 {
00112 //
00113 //  NEED CONVERSION CHECK
00114 //
00115     if(DataP == 0)
00116     {
00117     Structure.initialize(_(1,1),_(1,1));
00118     DataP = new CAMdataHandler(1,CAMType::typeDouble);
00119     DataP->setReferenceCount(1);
00120     referenceFlag  = 0;
00121     vectorBaseReferenceCount = 0;
00122     }
00123     else
00124     {
00125     CAMstructureBase AStructure(_(1,1),_(1,1));
00126     if(Structure.isStrictConformingTo(AStructure) != 1)
00127     {CAMvectorBase::nonConformingMessage(Structure,AStructure);}
00128     }
00129 
00130     CAMbinaryEngine::doubleAequalToAlpha(Structure, *DataP, value);
00131 }
00132 void  CAMvectorBase::operator =( const CAMvectorBase& A)
00133 {
00134 //
00135 //  NEED CONVERSION CHECK
00136 //
00137     if(DataP == 0)
00138     {
00139     A.Structure.initializeMinStructure(Structure);
00140     DataP = new CAMdataHandler(Structure.getFullDataCount(),typeValue);
00141     DataP->setReferenceCount(1);
00142     typeValue               = CAMType::typeDouble;
00143     referenceFlag           = 0;
00144     vectorBaseReferenceCount = 0;
00145     }
00146     else
00147     {
00148     if(Structure.isStrictConformingTo(A.Structure) != 1)
00149     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00150     }
00151 
00152     CAMbinaryEngine::doubleAequalToB(Structure, *DataP, A.Structure, *A.DataP);
00153 }
00154 void  CAMvectorBase::operator =( const CAMmatrixBase& A)
00155 {
00156 //
00157 //  NEED CONVERSION CHECK
00158 //
00159     if(DataP == 0)
00160     {
00161     A.Structure.initializeMinStructure(Structure);
00162     DataP = new CAMdataHandler(Structure.getFullDataCount(),typeValue);
00163     DataP->setReferenceCount(1);
00164     typeValue               = CAMType::typeDouble;
00165     referenceFlag           = 0;
00166     vectorBaseReferenceCount = 0;
00167     }
00168     else
00169     {
00170     if(Structure.isStrictConformingTo(A.Structure) != 1)
00171     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00172     }
00173 
00174     CAMbinaryEngine::doubleAequalToB(Structure, *DataP, A.Structure, *A.DataP);
00175 }
00176 
00177 //
00178 //********************************************************************************
00179 //                    OUTPUT
00180 //********************************************************************************
00181 //
00182 ostream& operator <<(ostream& out_stream, const CAMvectorBase& A)
00183 {
00184     const long* beginPtr  = A.Structure.indexBegin.getDataPointer();
00185     const long* endPtr    = A.Structure.indexEnd.getDataPointer();
00186     const long* stridePtr = A.Structure.indexStride.getDataPointer();
00187 
00188     int  saveWidth=out_stream.width();
00189     double OutValue;
00190 
00191     long i1, i2;
00192 
00193     for(i1 = *beginPtr; i1 <= *endPtr; i1 += *stridePtr)
00194     {
00195     for(i2 = *(beginPtr+1); i2 <= *(endPtr +1); i2 += *(stridePtr+1))
00196     {
00197 
00198      out_stream.width(saveWidth);
00199      OutValue =*((double*)A.getDataPointer(i1,i2));
00200      if(OutValue < 0 )
00201      out_stream << OutValue <<" ";
00202      else
00203      out_stream << " " << OutValue <<" ";
00204     }
00205     out_stream << endl;
00206     }
00207     return(out_stream);
00208 }
00209 
00210 istream& operator >>(istream& in_stream, CAMvectorBase& A)
00211 {
00212     const long* beginPtr  = A.Structure.indexBegin.getDataPointer();
00213     const long* endPtr    = A.Structure.indexEnd.getDataPointer();
00214     const long* stridePtr = A.Structure.indexStride.getDataPointer();
00215 
00216     long i1, i2;
00217 
00218     for(i1 = *beginPtr; i1 <= *endPtr; i1 += *stridePtr)
00219     {
00220     for(i2 = *(beginPtr+1); i2 <= *(endPtr +1); i2 += *(stridePtr+1))
00221     {
00222      if( !( in_stream >> *((double*)A.getDataPointer(i1,i2))))
00223      CAMarrayBase::inputSizeError();
00224     }}
00225     return(in_stream);
00226 }
00227 
00228 //
00229 //*****************************************************************
00230 //             INITIALIZATION MEMBER_FUNCTIONS
00231 //*****************************************************************
00232 //
00233 
00234 void  CAMvectorBase::initialize()
00235 {
00236     Structure.initialize();
00237     if(DataP != 0)
00238      {
00239       DataP->decrementReferenceCount();
00240       if(DataP->getReferenceCount() == 0) delete DataP;
00241      }
00242     DataP = 0;
00243     typeValue      = 0;
00244     referenceFlag  = 0;
00245     vectorBaseReferenceCount = 0;
00246 }
00247 
00248 void  CAMvectorBase::initialize(int d_type)
00249 {
00250     Structure.initialize();
00251     if(DataP != 0)
00252      {
00253       DataP->decrementReferenceCount();
00254       if(DataP->getReferenceCount() == 0) delete DataP;
00255      }
00256     DataP = 0;
00257     typeValue      = d_type;
00258     referenceFlag  = 0;
00259     vectorBaseReferenceCount = 0;
00260 }
00261 
00262 void  CAMvectorBase::initialize(const CAMvectorBase& A)
00263 {
00264 //
00265 //  NEED CONVERSION CHECK
00266 //
00267     if(DataP != 0)
00268     {
00269     DataP->decrementReferenceCount();
00270     if(DataP->getReferenceCount() == 0) delete DataP;
00271     }
00272 
00273     if(A.DataP != 0)
00274     {
00275     A.Structure.initializeMinStructure(Structure);
00276 
00277     DataP = new CAMdataHandler(Structure.getFullDataCount(),A.DataP->getDataType());
00278     DataP->setReferenceCount(1);
00279     CAMbinaryEngine::doubleAequalToB(Structure, *DataP, A.Structure, *A.DataP);
00280     }
00281     else
00282     {
00283     DataP = 0;
00284     Structure.initialize();
00285     }
00286 
00287     typeValue      = A.typeValue;
00288     referenceFlag  = 0;
00289     vectorBaseReferenceCount = 0;
00290 }
00291 
00292 void  CAMvectorBase::initialize(int d_type, const CAMrange& R1)
00293 {
00294      Structure.initialize(R1,_(R1.getBase(),R1.getBase()));
00295 
00296      if(DataP != 0)
00297      {
00298      DataP->decrementReferenceCount();
00299      if(DataP->getReferenceCount() == 0) delete DataP;
00300      }
00301 
00302      DataP = new CAMdataHandler(Structure.getFullDataCount(),d_type);
00303      DataP->setReferenceCount(1);
00304      referenceFlag  = 0;
00305      vectorBaseReferenceCount = 0;
00306 }
00307 
00308 //
00309 //***************************************************************
00310 //                    ARRAYOPS.CPP
00311 //***************************************************************
00312 //
00313 //
00314 //*****************************************************************
00315 //
00316 void  CAMvectorBase::initializeReturnArgument(const CAMvectorBase& A)
00317 {
00318     A.Structure.initializeMinStructure(Structure);
00319     DataP = new CAMdataHandler(Structure.getFullDataCount(),A.DataP->getDataType());
00320     DataP->setReferenceCount(1);
00321 }
00322 void  CAMvectorBase::initializeReturnArgument(const CAMstructureBase& S, int dataT)
00323 {
00324     S.initializeMinStructure(Structure);
00325     DataP = new CAMdataHandler(Structure.getFullDataCount(), dataT);
00326     DataP->setReferenceCount(1);
00327 }
00328 void  CAMvectorBase::initializeMinDuplicate(const CAMvectorBase& A)
00329 {
00330 
00331     if(A.DataP == 0) return;
00332 
00333     long i;
00334     long icount    = 0;
00335     long dimension = 0;
00336 
00337     for(i = 1; i <= A.Structure.getDimension(); i++)
00338     if(A.Structure[i].getIndexCount() != 1) dimension++;
00339 
00340 
00341     if(dimension == 0) dimension = 1;
00342     Structure.initialize(dimension);
00343 
00344 
00345     for(i = 1; i <= A.Structure.getDimension(); i++)
00346     {
00347       if(A.Structure[i].getIndexCount() != 1)
00348       {
00349       Structure.indexBegin[icount]     = 1;
00350       Structure.indexBeginBase[icount] = 1;
00351       Structure.indexEndBase[icount]   = A.Structure[i].getIndexCount();
00352       Structure.indexEnd[icount]       = A.Structure[i].getIndexCount();
00353       Structure.indexStride[icount]    = 1;
00354       icount++;
00355       }
00356     }
00357 
00358     if(icount == 0)
00359     {
00360     Structure.indexBegin[icount]     = 1;
00361     Structure.indexBeginBase[icount] = 1;
00362     Structure.indexEndBase[icount]   = 1;
00363     Structure.indexEnd[icount]       = 1;
00364     Structure.indexStride[icount]    = 1;
00365     }
00366     DataP = new CAMdataHandler(Structure.getFullDataCount(), A.typeValue);
00367     DataP->setReferenceCount(1);
00368 //
00369 //  copy over data
00370 //
00371     *this = A;
00372 }
00373 //
00374 //*****************************************************************
00375 //                    Operators
00376 //*****************************************************************
00377 //
00378 CAMvectorBase CAMvectorBase::operator-() const
00379 {
00380 //
00381 //  NEED CONVERSION CHECK
00382 //
00383     CAMvectorBase S;
00384     S.initializeReturnArgument(*this);
00385 
00386     CAMbinaryEngine::doubleAequalToMinusB(S.Structure, *S.DataP, Structure, *DataP);
00387     S.setTemporaryFlag();
00388     return S;
00389 }
00390 
00391 CAMvectorBase CAMvectorBase::operator+(const CAMvectorBase& A) const
00392 {
00393     if(Structure.isStrictConformingTo(A.Structure) != 1)
00394     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00395 //
00396 //  NEED CONVERSION CHECK
00397 //
00398     CAMvectorBase S;
00399     S.initializeReturnArgument(A.Structure,A.DataP->getDataType());
00400 
00401     CAMbinaryEngine::doubleCequalAplusB(Structure, *DataP, A.Structure, *A.DataP,
00402     S.Structure, *S.DataP);
00403 
00404     S.setTemporaryFlag();
00405     return S;
00406 }
00407 
00408 CAMmatrixBase CAMvectorBase::operator+(const CAMmatrixBase& A) const
00409 {
00410     if(Structure.isStrictConformingTo(A.Structure) != 1)
00411     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00412 //
00413 //  NEED CONVERSION CHECK
00414 //
00415     CAMmatrixBase S;
00416     S.initializeReturnArgument(A.Structure,A.DataP->getDataType());
00417 
00418     CAMbinaryEngine::doubleCequalAplusB(Structure, *DataP, A.Structure, *A.DataP,
00419     S.Structure, *S.DataP);
00420 
00421     S.setTemporaryFlag();
00422     return S;
00423 }
00424 CAMvectorBase CAMvectorBase::operator-(const CAMvectorBase& A) const
00425 {
00426     if(Structure.isStrictConformingTo(A.Structure) != 1)
00427     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00428 //
00429 //  NEED CONVERSION CHECK
00430 //
00431     CAMvectorBase S;
00432     S.initializeReturnArgument(A.Structure,A.DataP->getDataType());
00433 
00434     CAMbinaryEngine::doubleCequalAminusB(Structure, *DataP, A.Structure, *A.DataP,
00435     S.Structure, *S.DataP);
00436 
00437     S.setTemporaryFlag();
00438     return S;
00439 }
00440 CAMmatrixBase CAMvectorBase::operator-(const CAMmatrixBase& A) const
00441 {
00442     if(Structure.isStrictConformingTo(A.Structure) != 1)
00443     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00444 //
00445 //  NEED CONVERSION CHECK
00446 //
00447     CAMmatrixBase S;
00448     S.initializeReturnArgument(A.Structure,A.DataP->getDataType());
00449 
00450     CAMbinaryEngine::doubleCequalAminusB(Structure, *DataP, A.Structure, *A.DataP,
00451     S.Structure, *S.DataP);
00452 
00453     S.setTemporaryFlag();
00454     return S;
00455 }
00456 
00457 CAMmatrixBase CAMvectorBase::operator*(const CAMvectorBase& A) const
00458 {
00459     if(Structure.isMatrixOpConformingTo(A.Structure) != 1)
00460     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00461 //
00462 //  NEED CONVERSION CHECK
00463 //
00464 //
00465 //  Prepare Operands
00466 //
00467     int STempFlag = 0;
00468     int TTempFlag = 0;
00469 
00470     CAMvectorBase* S;
00471     CAMvectorBase* T;
00472 
00473     if(Structure.isSubset()  == 0)
00474     { S = (CAMvectorBase*)this;}
00475     else
00476     {
00477      STempFlag = 1;
00478      S = new CAMvectorBase();
00479      S->initializeReturnArgument(*this);
00480      *S = *this;
00481     }
00482 
00483     if(A.Structure.isSubset()  == 0)
00484     { T = (CAMvectorBase*)&A;}
00485     else
00486     {
00487      TTempFlag = 1;
00488      T = new CAMvectorBase();
00489      T->initializeReturnArgument(A);
00490      *T = A;
00491     }
00492 //
00493 //  return argument
00494 //
00495     long  Rows = (*S).Structure[1].getIndexCount();
00496     long  Cols = A.Structure[2].getIndexCount();
00497 
00498     CAMrange R1((*S).Structure[1].getIndexBase(),
00499     (*S).Structure[1].getIndexBase() +  Rows  - 1);
00500 
00501     CAMrange R2(A.Structure[2].getIndexBase(),
00502     A.Structure[2].getIndexBase() +  Cols  - 1);
00503 
00504     CAMmatrixBase R(CAMType::typeDouble,R1, R2);
00505 //
00506 //  dgemm performs the operation R := alpha*op(S)*op(T) + beta*R;
00507 //  op(matrix) is either the matrix or its transpose.
00508 //  the characters transX below specify that S and T are 'n'ot
00509 //  to be transposed.
00510 //
00511 //  R = m by n
00512 //  S = m by k
00513 //  T = k by n
00514 //
00515     char transa = 'n';
00516     char transb = 'n';
00517 
00518     long m = R[1].getIndexCount();
00519     long n = R[2].getIndexCount();
00520     long k = (*S).Structure[2].getIndexCount();
00521 
00522     double* s = (double*)((*S).getDataPointer());
00523     double* t = (double*)((*T).getDataPointer());
00524     double* r = (double*)(   R.getDataPointer());
00525 
00526     long lds =  (*S).Structure[1].getIndexCount();
00527     long ldt =  (*T).Structure[1].getIndexCount();
00528     long ldr =  R[1].getIndexCount();
00529 
00530     double alpha = 1.0;
00531     double beta  = 0.0;
00532 
00533     short f1 = 1;
00534     short f2 = 1;
00535 
00536     dgemm_(&transa, &transb, &m, &n, &k, &alpha, s, &lds, t, &ldt,
00537     &beta, r, &ldr,f1,f2);
00538 //
00539 //  clean up
00540 //
00541     if(STempFlag == 1) delete S;
00542     if(TTempFlag == 1) delete T;
00543 
00544     R.setTemporaryFlag();
00545     return R;
00546 }
00547 
00548 
00549 
00550 CAMvectorBase CAMvectorBase::operator*(const CAMmatrixBase& A) const
00551 {
00552     if(Structure.isMatrixOpConformingTo(A.Structure) != 1)
00553     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00554 //
00555 //  NEED CONVERSION CHECK
00556 //
00557 //
00558 //  Prepare Operands
00559 //
00560     int STempFlag = 0;
00561     int TTempFlag = 0;
00562 
00563     CAMvectorBase* S;
00564     CAMmatrixBase* T;
00565 
00566     if(Structure.isSubset()  == 0)
00567     { S = (CAMvectorBase*)this;}
00568     else
00569     {
00570      STempFlag = 1;
00571      S = new CAMvectorBase();
00572      S->initializeReturnArgument(*this);
00573      *S = *this;
00574     }
00575 
00576     if(A.Structure.isSubset()  == 0)
00577     { T = (CAMmatrixBase*)&A;}
00578     else
00579     {
00580      TTempFlag = 1;
00581      T = new CAMmatrixBase();
00582      T->initializeReturnArgument(A);
00583      *T = A;
00584     }
00585 //
00586 //  return argument
00587 //
00588     long  Rows = (*S).Structure[1].getIndexCount();
00589     long  Cols = A.Structure[2].getIndexCount();
00590 
00591     CAMrange R1((*S).Structure[1].getIndexBase(),
00592     (*S).Structure[1].getIndexBase() +  Rows  - 1);
00593 
00594     CAMrange R2(A.Structure[2].getIndexBase(),
00595     A.Structure[2].getIndexBase() +  Cols  - 1);
00596 
00597     CAMvectorBase R;
00598     if(R1.length() == 1)
00599     {R.initialize(CAMType::typeDouble,R2);}
00600     else    
00601     {R.initialize(CAMType::typeDouble,R1);}
00602 //
00603 //  dgemm performs the operation R := alpha*op(S)*op(T) + beta*R;
00604 //  op(matrix) is either the matrix or its transpose.
00605 //  the characters transX below specify that S and T are 'n'ot
00606 //  to be transposed.
00607 //
00608 //  R = m by n
00609 //  S = m by k
00610 //  T = k by n
00611 //
00612     char transa = 'n';
00613     char transb = 'n';
00614 
00615     long m = R.Structure[1].getIndexCount();
00616     long n = R.Structure[2].getIndexCount();
00617     long k = (*S).Structure[2].getIndexCount();
00618 
00619     double* s = (double*)((*S).getDataPointer());
00620     double* t = (double*)((*T).getDataPointer());
00621     double* r = (double*)(   R.getDataPointer());
00622 
00623     long lds =  (*S).Structure[1].getIndexCount();
00624     long ldt =  (*T).Structure[1].getIndexCount();
00625     long ldr =  R.Structure[1].getIndexCount();
00626 
00627     double alpha = 1.0;
00628     double beta  = 0.0;
00629 
00630     short f1 = 1;
00631     short f2 = 1;
00632 
00633     dgemm_(&transa, &transb, &m, &n, &k, &alpha, s, &lds, t, &ldt,
00634     &beta, r, &ldr,f1,f2);
00635 //
00636 //  clean up
00637 //
00638     if(STempFlag == 1) delete S;
00639     if(TTempFlag == 1) delete T;
00640 
00641     R.setTemporaryFlag();
00642     return R;
00643 }
00644 //
00645 //*****************************************************************
00646 //                    op = Operators
00647 //*****************************************************************
00648 //
00649 
00650 void CAMvectorBase::operator+=(const CAMvectorBase& A)
00651 {
00652     if(Structure.isStrictConformingTo(A.Structure) != 1)
00653     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00654 //
00655 //  NEED CONVERSION CHECK
00656 //
00657 
00658     CAMbinaryEngine::doubleAplusEqualB(Structure, *DataP, A.Structure, *A.DataP);
00659 }
00660 //
00661 //*****************************************************************
00662 //                    op = Operators
00663 //*****************************************************************
00664 //
00665 
00666 void CAMvectorBase::operator+=(const CAMmatrixBase& A)
00667 {
00668     if(Structure.isStrictConformingTo(A.Structure) != 1)
00669     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00670 //
00671 //  NEED CONVERSION CHECK
00672 //
00673 
00674     CAMbinaryEngine::doubleAplusEqualB(Structure, *DataP, A.Structure, *A.DataP);
00675 }
00676 void CAMvectorBase::operator-=(const CAMvectorBase& A)
00677 {
00678     if(Structure.isStrictConformingTo(A.Structure) != 1)
00679     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00680 //
00681 //  NEED CONVERSION CHECK
00682 //
00683 
00684     CAMbinaryEngine::doubleAminusEqualB(Structure, *DataP, A.Structure, *A.DataP);
00685 }
00686 void CAMvectorBase::operator-=(const CAMmatrixBase& A)
00687 {
00688     if(Structure.isStrictConformingTo(A.Structure) != 1)
00689     {CAMvectorBase::nonConformingMessage(Structure,A.Structure);}
00690 //
00691 //  NEED CONVERSION CHECK
00692 //
00693 
00694     CAMbinaryEngine::doubleAminusEqualB(Structure, *DataP, A.Structure, *A.DataP);
00695 }
00696 
00697 CAMvectorBase CAMvectorBase::transpose() const
00698 {
00699 //
00700 //  NEED CONVERSION CHECK
00701 //
00702     CAMvectorBase S(*this);
00703 //
00704 //  Only need to change indices, since the copy constructor
00705 //  moves the data.
00706 //
00707     S.Structure.indexBegin[0] = Structure.indexBegin[1];
00708     S.Structure.indexBegin[1] = Structure.indexBegin[0];
00709     S.Structure.indexBeginBase[0] = Structure.indexBeginBase[1];
00710     S.Structure.indexBeginBase[1] = Structure.indexBeginBase[0];
00711     S.Structure.indexEnd[0] = Structure.indexEnd[1];
00712     S.Structure.indexEnd[1] = Structure.indexEnd[0];
00713     S.Structure.indexEndBase[0] = Structure.indexEndBase[1];
00714     S.Structure.indexEndBase[1] = Structure.indexEndBase[0];
00715     S.Structure.indexStride[0] = Structure.indexStride[1];
00716     S.Structure.indexStride[1] = Structure.indexStride[0];
00717 
00718     S.setTemporaryFlag();
00719     return S;
00720 }
00721 
00722 
00723 
00724 long  CAMvectorBase::getIndexBase() const
00725 {
00726     long dimensionReference = 1;
00727 
00728     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00729     dimensionReference = 2;
00730 
00731     return   Structure.indexBegin[dimensionReference-1];
00732 }
00733 
00734 long CAMvectorBase::getIndexBound() const
00735 {
00736     long dimensionReference = 1;
00737 
00738     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00739     dimensionReference = 2;
00740 
00741     return   Structure.indexEnd[dimensionReference-1];
00742 }
00743 
00744 
00745 long  CAMvectorBase::getIndexStride() const
00746 {
00747     long dimensionReference = 1;
00748 
00749     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00750     dimensionReference = 2;
00751 
00752     return    Structure.indexStride[dimensionReference-1];
00753 }
00754 
00755 long  CAMvectorBase::getIndexCount() const
00756 {
00757     long dimensionReference = 1;
00758 
00759     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00760     dimensionReference =2;
00761 
00762     return  ((Structure.indexEnd[dimensionReference - 1]
00763            - Structure.indexBegin[dimensionReference - 1]) + 1);
00764 }
00765 
00766 void  CAMvectorBase::setIndexStride(long i)
00767 {
00768     long dimensionReferenceA = 1;
00769     long dimensionReferenceB = 2;
00770 
00771     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00772     {dimensionReferenceA = 2; dimensionReferenceB = 1;}
00773 
00774 
00775     Structure.indexStride[dimensionReferenceA - 1] = i;
00776     Structure.indexStride[dimensionReferenceB - 1] = 1;
00777 
00778 
00779 }
00780 
00781 void  CAMvectorBase::setIndexBase(long i)
00782 {
00783 
00784     long dimensionReferenceA = 1;
00785     long dimensionReferenceB = 2;
00786 
00787     if((Structure.indexEndBase[0] - Structure.indexBeginBase[0]) == 0)
00788     {dimensionReferenceA = 2; dimensionReferenceB = 1;}
00789 
00790 
00791     long k      = dimensionReferenceA - 1;
00792 
00793     long offset = i - Structure.indexBegin[k];
00794     Structure.indexBegin[k]     = Structure.indexBegin[k]     + offset;
00795     Structure.indexEnd[k]       = Structure.indexEnd[k]       + offset;
00796     Structure.indexBeginBase[k] = Structure.indexBeginBase[k] + offset;
00797     Structure.indexEndBase[k]   = Structure.indexEndBase[k]   + offset;
00798 
00799     Structure.indexBegin[dimensionReferenceB - 1]     = Structure.indexBegin[k];
00800     Structure.indexEnd[dimensionReferenceB - 1]       = Structure.indexBegin[k];
00801     Structure.indexBeginBase[dimensionReferenceB - 1] = Structure.indexBegin[k];
00802     Structure.indexEndBase[dimensionReferenceB - 1]   = Structure.indexBegin[k] ;
00803 
00804 
00805 }
00806 
00807 CAMvectorBase CAMvectorBase::operator~() const
00808 {
00809 //
00810 //  NEED CONVERSION CHECK
00811 //
00812     CAMvectorBase S(*this);
00813 //
00814 //  Only need to change indices, since the copy constructor
00815 //  moves the data.
00816 //
00817     S.Structure.indexBegin[0] = Structure.indexBegin[1];
00818     S.Structure.indexBegin[1] = Structure.indexBegin[0];
00819     S.Structure.indexBeginBase[0] = Structure.indexBeginBase[1];
00820     S.Structure.indexBeginBase[1] = Structure.indexBeginBase[0];
00821     S.Structure.indexEnd[0] = Structure.indexEnd[1];
00822     S.Structure.indexEnd[1] = Structure.indexEnd[0];
00823     S.Structure.indexEndBase[0] = Structure.indexEndBase[1];
00824     S.Structure.indexEndBase[1] = Structure.indexEndBase[0];
00825     S.Structure.indexStride[0] = Structure.indexStride[1];
00826     S.Structure.indexStride[1] = Structure.indexStride[0];
00827 
00828     S.setTemporaryFlag();
00829     return S;
00830 }
00831 //
00832 //*****************************************************************
00833 //                    Operations with Scalers
00834 //*****************************************************************
00835 //
00836 CAMvectorBase  CAMvectorBase::operator +(const double value) const
00837 {
00838 //
00839 //  NEED CONVERSION CHECK
00840 //
00841     CAMstructureBase AStructure(_(1,1));
00842     if(Structure.isStrictConformingTo(AStructure) != 1)
00843     {CAMvectorBase::nonConformingMessage(Structure,AStructure);}
00844 
00845     CAMvectorBase S(*this);
00846     CAMbinaryEngine::doubleAplusEqualAlpha(S.Structure, *(S.DataP), value);
00847 
00848     S.setTemporaryFlag();
00849     return S;
00850 }
00851 CAMvectorBase  operator +(const double value, const CAMvectorBase& A)
00852 {
00853 //
00854 //  NEED CONVERSION CHECK
00855 //
00856     CAMstructureBase  BStructure(_(1,1));
00857     if(A.Structure.isStrictConformingTo(BStructure) != 1)
00858     {CAMvectorBase::nonConformingMessage(A.Structure,BStructure);}
00859 
00860     CAMvectorBase S(A);
00861     CAMbinaryEngine::doubleAplusEqualAlpha(S.Structure, *(S.DataP), value);
00862 
00863     S.setTemporaryFlag();
00864     return S;
00865 }
00866 
00867 CAMvectorBase  CAMvectorBase::operator -(const double value) const
00868 {
00869 //
00870 //  NEED CONVERSION CHECK
00871 //
00872     CAMstructureBase AStructure(_(1,1));
00873     if(Structure.isStrictConformingTo(AStructure) != 1)
00874     {CAMvectorBase::nonConformingMessage(Structure,AStructure);}
00875 
00876     CAMvectorBase S(*this);
00877     CAMbinaryEngine::doubleAminusEqualAlpha(S.Structure, *(S.DataP), value);
00878 
00879     S.setTemporaryFlag();
00880     return S;
00881 }
00882 
00883 CAMvectorBase  operator -(const double value, const CAMvectorBase& A)
00884 {
00885 //
00886 //  NEED CONVERSION CHECK
00887 //
00888     CAMstructureBase  BStructure(_(1,1));
00889     if(A.Structure.isStrictConformingTo(BStructure) != 1)
00890     {CAMvectorBase::nonConformingMessage(A.Structure,BStructure);}
00891 
00892     CAMvectorBase S(A);
00893     CAMbinaryEngine::doubleAminusEqualAlpha(S.Structure, *(S.DataP), value);
00894 
00895     S.setTemporaryFlag();
00896     return S;
00897 }
00898 
00899 void  CAMvectorBase::operator +=(const double value)
00900 {
00901 //
00902 //  NEED CONVERSION CHECK
00903 //
00904     CAMstructureBase AStructure(_(1,1));
00905     if(Structure.isStrictConformingTo(AStructure) != 1)
00906     {CAMvectorBase::nonConformingMessage(Structure,AStructure);}
00907 
00908     CAMbinaryEngine::doubleAplusEqualAlpha(Structure, *(DataP), value);
00909 }
00910 
00911 void  CAMvectorBase::operator -=(const double value)
00912 {
00913 //
00914 //  NEED CONVERSION CHECK
00915 //
00916     CAMstructureBase AStructure(_(1,1));
00917     if(Structure.isStrictConformingTo(AStructure) != 1)
00918     {CAMvectorBase::nonConformingMessage(Structure,AStructure);}
00919 
00920     CAMbinaryEngine::doubleAminusEqualAlpha(Structure, *(DataP), value);
00921 }
00922 
00923 CAMvectorBase  CAMvectorBase::operator*(double value) const
00924 {
00925 //
00926 //  NEED CONVERSION CHECK
00927 //
00928     CAMvectorBase S(*this);
00929     CAMbinaryEngine::doubleAtimesEqualAlpha(S.Structure, *S.DataP, value);
00930     S.setTemporaryFlag();
00931     return S;
00932 }
00933 
00934 CAMvectorBase  operator *(double value, const CAMvectorBase& A)
00935 {
00936 //
00937 //  NEED CONVERSION CHECK
00938 //
00939     CAMvectorBase S(A);
00940     CAMbinaryEngine::doubleAtimesEqualAlpha(S.Structure, *S.DataP, value);
00941     S.setTemporaryFlag();
00942     return S;
00943 }
00944 
00945 CAMvectorBase  CAMvectorBase::operator /(double value) const
00946 {
00947 //
00948 //  NEED CONVERSION CHECK
00949 //
00950     CAMvectorBase S(*this);
00951     CAMbinaryEngine::doubleAdivideEqualAlpha(S.Structure, *S.DataP, value);
00952     S.setTemporaryFlag();
00953     return S;
00954 }
00955 
00956 CAMvectorBase  operator /(double value, const CAMvectorBase& A)
00957 {
00958 //
00959 //  NEED CONVERSION CHECK
00960 //
00961     CAMvectorBase S(A);
00962     CAMbinaryEngine::doubleAdivideEqualAlpha(S.Structure, *S.DataP, value);
00963     S.setTemporaryFlag();
00964     return S;
00965 }
00966 
00967 void  CAMvectorBase::operator *=(double value)
00968 {
00969 //
00970 //  NEED CONVERSION CHECK
00971 //
00972     CAMbinaryEngine::doubleAtimesEqualAlpha(Structure, *DataP, value);
00973 }
00974 
00975 void  CAMvectorBase::operator /=(double value)
00976 {
00977     CAMbinaryEngine::doubleAdivideEqualAlpha(Structure, *DataP, value);
00978 }
00979 
00980 
00981 
00982 void  CAMvectorBase::setToValue(double value)
00983 {
00984 //
00985 //  NEED CONVERSION CHECK
00986 //
00987     CAMbinaryEngine::doubleAequalToAlpha(Structure, *DataP, value);
00988 }
00989 
00990 CAMvectorBase  CAMvectorBase::plusValue(double value)
00991 {
00992 //
00993 //  NEED CONVERSION CHECK
00994 //
00995     CAMvectorBase S(*this);
00996     CAMbinaryEngine::doubleAplusEqualAlpha(S.Structure, *S.DataP, value);
00997     S.setTemporaryFlag();
00998     return S;
00999 }
01000 
01001 CAMvectorBase  CAMvectorBase::minusValue(double value)
01002 {
01003 //
01004 //  NEED CONVERSION CHECK
01005 //
01006     CAMvectorBase S(*this);
01007     CAMbinaryEngine::doubleAminusEqualAlpha(S.Structure, *S.DataP, value);
01008     S.setTemporaryFlag();
01009     return S;
01010 }
01011 
01012 //
01013 //*****************************************************************
01014 //            Temporary and Reference Utilities
01015 //*****************************************************************
01016 //
01017 void  CAMvectorBase::exchangeContentsWith(CAMvectorBase& B)
01018 {
01019 //
01020 //  This routine exchanges the contents of *this with B.
01021 //  The routine is typically used with *this input as
01022 //  a null object and B a temporary object (i.e. the result
01023 //  of an operator or function which returns B with the
01024 //  temporary flag set). In such a case, the contents of
01025 //  B are captured by *this --- resulting in a transfer of the
01026 //  results without invoking a data copy.
01027 //
01028 //
01029     CAMstructureBase S_temp(Structure);
01030     CAMdataHandler*  DataP_temp        = DataP;
01031     int  typeValue_temp                = typeValue;
01032     int  referenceFlag_temp            = referenceFlag;
01033     long  vectorBaseReferenceCount_temp = vectorBaseReferenceCount;
01034 
01035     Structure.initialize(B.Structure);
01036     DataP                   = B.DataP;
01037     typeValue               = B.typeValue;
01038     referenceFlag           = B.referenceFlag;
01039     vectorBaseReferenceCount = B.vectorBaseReferenceCount;
01040 //
01041     B.Structure.initialize(S_temp);
01042     B.DataP                   = DataP_temp;
01043     B.typeValue               = typeValue_temp;
01044     B.referenceFlag           = referenceFlag_temp;
01045     B.vectorBaseReferenceCount = vectorBaseReferenceCount_temp;
01046 }
01047 
01048 void  CAMvectorBase::initializeReferenceDuplicate(const CAMvectorBase& B)
01049 {
01050 //
01051 //  This routine initializes *this with the contents of B and
01052 //  and sets the *this reference flag.  This results in a
01053 //  class instance whose data is that associated with B.
01054 //
01055 //  Typically this routine is used in a container class which
01056 //  contains arrays --- and one wants to have sub-array access
01057 //  for the contained class which is based upon the sub-array
01058 //  access of the array class. 
01059 //
01060     if(DataP != 0)
01061     {
01062     DataP->decrementReferenceCount();
01063      if(DataP->getReferenceCount() == 0) delete DataP;
01064     }
01065 
01066     Structure.initialize(B.Structure);
01067     DataP                   = B.DataP;
01068     DataP->incrementReferenceCount();  //One Reference for local copy
01069     DataP->incrementReferenceCount();  //One Reference for compiler copy
01070     typeValue               = B.typeValue;
01071     referenceFlag           = 1;
01072     vectorBaseReferenceCount = 0;
01073 }
01074 
01075 //
01076 //*****************************************************************
01077 //                    CONVERSIONS
01078 //*****************************************************************
01079 //
01080 CAMmatrixBase  CAMvectorBase::asMatrix() const
01081 {
01082     CAMmatrixBase S;
01083     if(DataP == 0) return S;
01084 
01085     CAMrange R1; CAMrange R2;
01086 
01087     if(Structure[1].getIndexCount() != 1)
01088     {
01089     R1.initialize(Structure[1].getIndexBase(), Structure[1].getIndexBound());
01090     R2.initialize(Structure[2].getIndexBase(), Structure[2].getIndexBound());
01091     }
01092     else
01093     {
01094     R1.initialize(Structure[2].getIndexBase(), Structure[2].getIndexBound());
01095     R2.initialize(Structure[1].getIndexBase(), Structure[1].getIndexBound());
01096     }
01097 //
01098 //
01099     S.initialize(CAMType::typeDouble, R1,R2);
01100     CAMbinaryEngine::doubleAequalToB(S.Structure, *(S.DataP), Structure, *DataP);
01101 //
01102 //
01103     S.setTemporaryFlag();
01104     return S;
01105 }
01106 CAMarrayBase  CAMvectorBase::asArray() const
01107 {
01108     CAMarrayBase S;
01109     if(DataP == 0) return S;
01110 
01111     CAMrange R1;
01112 
01113     if(Structure[1].getIndexCount() != 1)
01114     {
01115     R1.initialize(Structure[1].getIndexBase(), Structure[1].getIndexBound());
01116     }
01117     else
01118     {
01119     R1.initialize(Structure[2].getIndexBase(), Structure[2].getIndexBound());
01120     }
01121 //
01122     S.initialize(CAMType::typeDouble, R1);
01123     CAMbinaryEngine::doubleAequalToB(S.Structure, *(S.DataP), Structure, *DataP);
01124 //
01125 //
01126     S.setTemporaryFlag();
01127     return S;
01128 }
01129 
01130 
01131 
01132 void*  CAMvectorBase::getDataPointer(long i1, long i2) const
01133 {
01134     const long* beginPtr  = Structure.indexBeginBase.getDataPointer();
01135     const long* endPtr    = Structure.indexEndBase.getDataPointer();
01136 //
01137 //  NEED CONVERSION CHECK
01138 //
01139     double* dataPtr =  (double*)(DataP->dataPointer);
01140 
01141     long offset;
01142     offset  = (i1 - *(beginPtr))
01143     + ((*(endPtr) - *(beginPtr)) + 1)*(i2 - *(beginPtr + 1));
01144 
01145 
01146     return (void*)(dataPtr + offset);
01147 }
01148 //
01149 //********************************************************************************
01150 //                    Reference Counting Functions
01151 //********************************************************************************
01152 //
01153 
01154 void  CAMvectorBase::incrementReferenceCount()
01155 {
01156     if(vectorBaseReferenceCount == 0) CAMvectorBase::referenceCountError();
01157     vectorBaseReferenceCount++;
01158 }
01159 
01160 void  CAMvectorBase::referenceCountError()
01161 {
01162 cerr << " Cannot Use Reference Counting on Objects New\'d by the Compiler " << endl;
01163 CAMmvaExit();
01164 }
01165 //
01166 //*****************************************************************
01167 //                    MEMBER_FUNCTIONS
01168 //*****************************************************************
01169 //
01170 
01171 
01172 void  CAMvectorBase::indexCheck(const CAMstructureBase &S, long i1, long i2)
01173 {
01174     if(S.dataDimension != 2)
01175     {
01176      cerr << " Error : Incorrect Vector Array Index Dimension " << endl;
01177      cerr << " Object Dimension = " << S.dataDimension
01178           << "--- Dimension Used = "<< 2 << endl;
01179      CAMmvaExit();
01180      }
01181      const long* indexBeginP = S.indexBegin.getDataPointer();
01182      const long* indexEndP = S.indexEnd.getDataPointer();
01183      if((i1 < *indexBeginP)||(i1 > *indexEndP))
01184      {
01185      CAMvectorBase::indexErrorMessage(1, *(indexBeginP), *(indexEndP), i1);
01186      }
01187      if((i2 < *(indexBeginP +1))||(i2 > *(indexEndP+1)))
01188      {
01189      CAMvectorBase::indexErrorMessage(2, *(indexBeginP+1), *(indexEndP+1), i2);
01190      }
01191 }
01192 
01193 
01194 
01195 
01196 
01197 void  CAMvectorBase::indexErrorMessage(long indexDimension, long base, long bound, long index)
01198 {
01199      cerr << " Error :  Index " << indexDimension << " Out of Range " << endl;
01200 
01201      cerr << " Current Index Range  :(" << base << ", " << bound << ")"  << endl;
01202      cerr << " Index Used          : " << index << endl;
01203      CAMmvaExit();
01204 }
01205 void CAMvectorBase::nonConformingMessage(const CAMstructureBase& A,  const CAMstructureBase& B)
01206 {
01207     long i;
01208     cerr << endl;
01209     cerr << "Error :  Object Dimensions not Compatable with Operation " << endl << endl;
01210     cerr << "Left  Operand Dimensions :   ";
01211     cerr << A[1].getIndexCount();
01212     for(i = 2; i <= A.dataDimension; i++)
01213     cerr <<  " x " << A[i].getIndexCount() ;
01214     cerr << endl << endl;
01215     cerr << "Right Operand Dimensions :   ";
01216     cerr << B[1].getIndexCount();
01217     for(i = 2; i <= B.dataDimension; i++)
01218     cerr <<  " x " << B[i].getIndexCount();
01219     cerr << endl << endl;
01220     CAMmvaExit();
01221 }
01222 void CAMvectorBase::doubleConversionError(const CAMstructureBase& A)
01223 {
01224     long i;
01225     cerr << endl;
01226     cerr << "Dimensions not Compatable with Conversion to Double " << endl << endl;
01227     cerr << "Operand Dimensions :   ";
01228     cerr << A[1].getIndexCount();
01229     for(i = 2; i <= A.dataDimension; i++)
01230     cerr <<  " x " << A[i].getIndexCount() ;
01231     cerr << endl << endl;
01232     CAMmvaExit();
01233 }
01234 
01235 void CAMvectorBase::objectConversionError(const CAMstructureBase& A)
01236 {
01237     long i;
01238     cerr << endl;
01239     cerr << " Dimensions not Compatable with Conversion Operator " << endl << endl;
01240     cerr << "Operand Dimensions :   ";
01241     cerr << A[1].getIndexCount();
01242     for(i = 2; i <= A.dataDimension; i++)
01243     cerr <<  " x " << A[i].getIndexCount() ;
01244     cerr << endl << endl;
01245     CAMmvaExit();
01246 }
01247 void CAMvectorBase::nullOperandError()
01248 {
01249     cerr << endl;
01250     cerr << " Error : Null Object Used As Operand  " << endl;
01251     CAMmvaExit();
01252 }
01253 void CAMvectorBase::nullOperandError(char* Operation)
01254 {
01255     cerr << endl;
01256     cerr << " Error : Null Object Used As Operand With "<< Operation << endl;
01257     CAMmvaExit();
01258 }
01259 void CAMvectorBase::inputSizeError()
01260 {
01261     cerr << endl;
01262     cerr << " Input error : Insufficient # of data elements in input stream " << endl;
01263     CAMmvaExit();
01264 }
01265 //
01266 //*****************************************************************
01267 //                     CPP File End
01268 //*****************************************************************
01269 //
01270 
01271 
01272 
01273 
01274 
01275 
01276 
01277 
01278 
01279 
01280   

Generated on Wed Aug 6 12:58:54 2003 for Open-Sessame Framework by doxygen1.3