Changeset 813 in Sophya for trunk/SophyaLib/TArray/tmatrix.cc


Ignore:
Timestamp:
Apr 5, 2000, 5:44:19 PM (25 years ago)
Author:
ansari
Message:

Correction bug/amelioarions TArray,TMatrix,TVector - Reza 5/4/2000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/tmatrix.cc

    r804 r813  
    1 // $Id: tmatrix.cc,v 1.3 2000-04-03 17:35:58 ansari Exp $
     1// $Id: tmatrix.cc,v 1.4 2000-04-05 15:44:15 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "machdefs.h"
     
    1717  : TArray<T>()
    1818{
     19  ck_memo_vt_ = true;
    1920}
    2021
     
    4849: TArray<T>(a)
    4950{
    50   if (a.NbDimensions() != 2)
    51     throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions() != 2 ");
     51  if (a.NbDimensions() > 2)
     52    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions()>2 ");
     53  if (a.NbDimensions() == 1) {
     54    size_[1] = 1;
     55    step_[1] = size_[0]*step_[0];
     56    ndim_ = 2;
     57  }
     58  UpdateMemoryMapping(a, SameMemoryMapping);
    5259}
    5360
     
    5663: TArray<T>(a, share)
    5764{
    58   if (a.NbDimensions() != 2)
    59     throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions() != 2 ");
     65  if (a.NbDimensions() > 2)
     66    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions()>2");
     67  if (a.NbDimensions() == 1) {
     68    size_[1] = 1;
     69    step_[1] = size_[0]*step_[0];
     70    ndim_ = 2;
     71  }
    6072  UpdateMemoryMapping(a, mm);
    6173}
     
    7183TArray<T>& TMatrix<T>::Set(const TArray<T>& a)
    7284{
    73   if (a.NbDimensions() != 2)
    74     throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() != 2 ");
    75   return(TArray<T>::Set(a));
     85  if (a.NbDimensions() > 2)
     86    throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() > 2");
     87  TArray<T>::Set(a);
     88  if (a.NbDimensions() == 1) {
     89    size_[1] = 1;
     90    step_[1] = size_[0]*step_[0];
     91    ndim_ = 2;
     92  }
     93  UpdateMemoryMapping(a, SameMemoryMapping);
     94  return(*this);
    7695}
    7796
     
    83102  uint_4 size[BASEARRAY_MAXNDIMS];
    84103  for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)  size[kk] = 0;
    85   size[0] = r;  size[1] = c;
    86104  if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 
    87   UpdateMemoryMapping(mm, size[0], size[1]);
     105  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) )
     106    mm = GetDefaultMemoryMapping();
     107  if (mm == CMemoryMapping) {
     108    size[0] = c;  size[1] = r;
     109  }
     110  else {
     111    size[0] = r;  size[1] = c;
     112  }
    88113  TArray<T>::ReSize(2, size, 1);
    89   UpdateMemoryMapping(mm, size[0], size[1]);
     114  UpdateMemoryMapping(mm);
    90115}
    91116
     
    97122  uint_4 size[BASEARRAY_MAXNDIMS];
    98123  for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)  size[kk] = 0;
    99   UpdateMemoryMapping(mm, size[0], size[1]);
     124  if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 
     125  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) )
     126    mm = GetDefaultMemoryMapping();
     127  if (mm == CMemoryMapping) {
     128    size[0] = c;  size[1] = r;
     129  }
     130  else {
     131    size[0] = r;  size[1] = c;
     132  }
    100133  TArray<T>::Realloc(2, size, 1, force);
    101   UpdateMemoryMapping(mm, size[0], size[1]);
     134  UpdateMemoryMapping(mm);
    102135}
    103136
    104137// $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ?
    105138template <class T>
    106 TMatrix<T> TMatrix<T>::operator () (Range rline, Range rcol) const
    107 {
    108   uint_4 nx, ny;
    109   nx = ny = 0;
    110   if (GetMemoryMapping() == CMemoryMapping ) {
    111     TMatrix sm(SubArray(rcol, rline, 0, 0, 0),true,CMemoryMapping);
    112     sm.UpdateMemoryMapping(CMemoryMapping, nx, ny);
    113     sm.SetTemp(true);
    114     return(sm);
    115   }
    116   else {
    117     TMatrix sm(SubArray(rline, rcol, 0, 0, 0),true,CMemoryMapping);
    118     sm.UpdateMemoryMapping(FortranMemoryMapping, nx, ny);
    119     sm.SetTemp(true);
    120     return(sm);
    121   }
     139TMatrix<T> TMatrix<T>::SubMatrix(Range rline, Range rcol) const
     140{
     141  short mm = GetMemoryMapping();
     142  Range rx, ry;
     143  if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
     144  else { ry = rcol;  rx = rline; }
     145  TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true, mm);
     146  sm.UpdateMemoryMapping(mm);
     147  sm.SetTemp(true);
     148  return(sm);
    122149}
    123150
     
    127154TMatrix<T>& TMatrix<T>::Transpose()
    128155{
     156  short vt = (marowi_ == veceli_) ? ColumnVector : RowVector;
    129157  uint_4 rci = macoli_;
    130158  macoli_ = marowi_;
    131159  marowi_ = rci;
     160  veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
    132161  return(*this);
    133162}
     
    147176
    148177// Rearrangement memoire
     178// Si identique, renvoie une matrice qui partage les donnees
    149179template <class T>
    150180TMatrix<T> TMatrix<T>::Rearrange(short mm)
    151181{
    152   if (mm == SameMemoryMapping) mm = GetMemoryMapping(); 
     182  if ( mm == SameMemoryMapping)  mm = GetMemoryMapping();
     183  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) )
     184    mm = GetDefaultMemoryMapping();
     185 
     186  if  (mm == GetMemoryMapping())
     187    return (TMatrix<T>(*this, true));
     188 
    153189  TMatrix<T> tm(NRows(), NCols(), mm);
    154190  for(uint_4 i=0; i<NRows(); i++)
     
    180216//**** Impression
    181217template <class T>
     218string TMatrix<T>::InfoString() const
     219{
     220  string rs = "TMatrix<";
     221  rs += typeid(T).name();
     222  char buff[64];
     223  sprintf(buff, ">(NRows=%ld, NCols=%ld)", (long)NRows(), (long)NCols());
     224  rs += buff;
     225  return(rs); 
     226}
     227
     228template <class T>
    182229void TMatrix<T>::Print(ostream& os, int_4 maxprt, bool si) const
    183230{
    184   os << "... TMatrix<T>(NRows=" << NRows() << " x NCols=" << NCols()
    185      << ")::Print() (MemOrg=" << GetMemoryMapping() << ")" << endl;
    186   os << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA() << " VectKA=" << VectKA() << endl;
    187231  if (maxprt < 0)  maxprt = max_nprt_;
    188232  int_4 npr = 0;
     
    200244    os << endl;
    201245  }
    202   os << "\n" << endl;
     246  os << endl;
    203247}
    204248
     
    235279}
    236280
    237 
    238281///////////////////////////////////////////////////////////////
    239282#ifdef __CXX_PRAGMA_TEMPLATES__
Note: See TracChangeset for help on using the changeset viewer.