Index: trunk/SophyaLib/TArray/tmatrix.cc
===================================================================
--- trunk/SophyaLib/TArray/tmatrix.cc	(revision 804)
+++ trunk/SophyaLib/TArray/tmatrix.cc	(revision 813)
@@ -1,3 +1,3 @@
-// $Id: tmatrix.cc,v 1.3 2000-04-03 17:35:58 ansari Exp $
+// $Id: tmatrix.cc,v 1.4 2000-04-05 15:44:15 ansari Exp $
 //                         C.Magneville          04/99
 #include "machdefs.h"
@@ -17,4 +17,5 @@
   : TArray<T>()
 {
+  ck_memo_vt_ = true;
 }
 
@@ -48,6 +49,12 @@
 : TArray<T>(a)
 {
-  if (a.NbDimensions() != 2) 
-    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions() != 2 ");
+  if (a.NbDimensions() > 2) 
+    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a) a.NbDimensions()>2 ");
+  if (a.NbDimensions() == 1) {
+    size_[1] = 1;
+    step_[1] = size_[0]*step_[0];
+    ndim_ = 2;
+  }
+  UpdateMemoryMapping(a, SameMemoryMapping);
 }
 
@@ -56,6 +63,11 @@
 : TArray<T>(a, share)
 {
-  if (a.NbDimensions() != 2) 
-    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions() != 2 ");
+  if (a.NbDimensions() > 2) 
+    throw SzMismatchError("TMatrix<T>::TMatrix(const TArray<T>& a, ...) a.NbDimensions()>2");
+  if (a.NbDimensions() == 1) {
+    size_[1] = 1;
+    step_[1] = size_[0]*step_[0];
+    ndim_ = 2;
+  }
   UpdateMemoryMapping(a, mm);
 }
@@ -71,7 +83,14 @@
 TArray<T>& TMatrix<T>::Set(const TArray<T>& a)
 {
-  if (a.NbDimensions() != 2) 
-    throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() != 2 ");
-  return(TArray<T>::Set(a));
+  if (a.NbDimensions() > 2) 
+    throw SzMismatchError("TMatrix<T>::Set(const TArray<T>& a) a.NbDimensions() > 2");
+  TArray<T>::Set(a);
+  if (a.NbDimensions() == 1) {
+    size_[1] = 1;
+    step_[1] = size_[0]*step_[0];
+    ndim_ = 2;
+  }
+  UpdateMemoryMapping(a, SameMemoryMapping);
+  return(*this);
 }
 
@@ -83,9 +102,15 @@
   uint_4 size[BASEARRAY_MAXNDIMS];
   for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)  size[kk] = 0;
-  size[0] = r;  size[1] = c;
   if (mm == SameMemoryMapping) mm = GetMemoryMapping();  
-  UpdateMemoryMapping(mm, size[0], size[1]);
+  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 
+    mm = GetDefaultMemoryMapping();
+  if (mm == CMemoryMapping) {
+    size[0] = c;  size[1] = r;
+  }
+  else {
+    size[0] = r;  size[1] = c;
+  }
   TArray<T>::ReSize(2, size, 1);
-  UpdateMemoryMapping(mm, size[0], size[1]);
+  UpdateMemoryMapping(mm);
 }
 
@@ -97,27 +122,29 @@
   uint_4 size[BASEARRAY_MAXNDIMS];
   for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)  size[kk] = 0;
-  UpdateMemoryMapping(mm, size[0], size[1]);
+  if (mm == SameMemoryMapping) mm = GetMemoryMapping();  
+  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 
+    mm = GetDefaultMemoryMapping();
+  if (mm == CMemoryMapping) {
+    size[0] = c;  size[1] = r;
+  }
+  else {
+    size[0] = r;  size[1] = c;
+  }
   TArray<T>::Realloc(2, size, 1, force);
-  UpdateMemoryMapping(mm, size[0], size[1]);
+  UpdateMemoryMapping(mm);
 }
 
 // $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ?
 template <class T>
-TMatrix<T> TMatrix<T>::operator () (Range rline, Range rcol) const
-{
-  uint_4 nx, ny;
-  nx = ny = 0;
-  if (GetMemoryMapping() == CMemoryMapping ) {
-    TMatrix sm(SubArray(rcol, rline, 0, 0, 0),true,CMemoryMapping);
-    sm.UpdateMemoryMapping(CMemoryMapping, nx, ny);
-    sm.SetTemp(true);
-    return(sm);
-  }
-  else {
-    TMatrix sm(SubArray(rline, rcol, 0, 0, 0),true,CMemoryMapping);
-    sm.UpdateMemoryMapping(FortranMemoryMapping, nx, ny);
-    sm.SetTemp(true);
-    return(sm);
-  }
+TMatrix<T> TMatrix<T>::SubMatrix(Range rline, Range rcol) const
+{
+  short mm = GetMemoryMapping();
+  Range rx, ry;
+  if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
+  else { ry = rcol;  rx = rline; }
+  TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true, mm);
+  sm.UpdateMemoryMapping(mm);
+  sm.SetTemp(true);
+  return(sm);
 }
 
@@ -127,7 +154,9 @@
 TMatrix<T>& TMatrix<T>::Transpose() 
 {
+  short vt = (marowi_ == veceli_) ? ColumnVector : RowVector;
   uint_4 rci = macoli_;
   macoli_ = marowi_;
   marowi_ = rci;
+  veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
   return(*this);
 }
@@ -147,8 +176,15 @@
 
 // Rearrangement memoire
+// Si identique, renvoie une matrice qui partage les donnees 
 template <class T>
 TMatrix<T> TMatrix<T>::Rearrange(short mm)
 {
-  if (mm == SameMemoryMapping) mm = GetMemoryMapping();  
+  if ( mm == SameMemoryMapping)  mm = GetMemoryMapping();
+  else if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) 
+    mm = GetDefaultMemoryMapping();
+  
+  if  (mm == GetMemoryMapping())
+    return (TMatrix<T>(*this, true));
+  
   TMatrix<T> tm(NRows(), NCols(), mm);
   for(uint_4 i=0; i<NRows(); i++)
@@ -180,9 +216,17 @@
 //**** Impression
 template <class T>
+string TMatrix<T>::InfoString() const
+{
+  string rs = "TMatrix<";
+  rs += typeid(T).name();
+  char buff[64];
+  sprintf(buff, ">(NRows=%ld, NCols=%ld)", (long)NRows(), (long)NCols());
+  rs += buff;
+  return(rs);  
+}
+
+template <class T>
 void TMatrix<T>::Print(ostream& os, int_4 maxprt, bool si) const
 {
-  os << "... TMatrix<T>(NRows=" << NRows() << " x NCols=" << NCols() 
-     << ")::Print() (MemOrg=" << GetMemoryMapping() << ")" << endl;
-  os << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA() << " VectKA=" << VectKA() << endl;
   if (maxprt < 0)  maxprt = max_nprt_;
   int_4 npr = 0;
@@ -200,5 +244,5 @@
     os << endl;
   }
-  os << "\n" << endl;
+  os << endl;
 }
 
@@ -235,5 +279,4 @@
 }
 
-
 ///////////////////////////////////////////////////////////////
 #ifdef __CXX_PRAGMA_TEMPLATES__
