VectorCollection.hxx
1 // Copyright (C) 2010, INRIA
2 // Author(s): Marc Fragu, Vivien Mallet
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_VECTOR_VECTORCOLLECTION_HXX
22 
23 
24 #include <map>
25 #include "../share/Common.hxx"
26 #include "../share/Properties.hxx"
27 #include "../share/Storage.hxx"
28 #include "../share/Errors.hxx"
29 #include "../share/Allocator.hxx"
30 
31 
32 namespace Seldon
33 {
34 
35 
37  template <class T, class Allocator >
38  class Vector<T, Collection, Allocator>: public Vector_Base<T, Allocator>
39  {
40  // typedef declarations.
41  public:
42  typedef typename T::value_type value_type;
43  typedef typename T::pointer pointer;
44  typedef typename T::const_pointer const_pointer;
45  typedef typename T::reference reference;
46  typedef typename T::const_reference const_reference;
47 
48  typedef T vector_type;
49  typedef vector_type* vector_pointer;
50  typedef const vector_type* const_vector_pointer;
51  typedef vector_type& vector_reference;
52  typedef const vector_type& const_vector_reference;
53 
56  typedef const collection_type const_collection_type;
58  typedef const collection_type& const_collection_reference;
59 
60  typedef Collection storage;
61 
62  // Attributes.
63  protected:
64  // Number of vectors.
65  int Nvector_;
66  // Lengths of the underlying vectors.
68  // Cumulative sum of the lengths of the underlying vectors.
70  // Pointers of the underlying vectors.
71  collection_type vector_;
72 
74  map<string, int> label_map_;
76  vector<string> label_vector_;
77 
79  public:
80  // Constructor.
81  explicit Vector();
82  explicit Vector(int i);
84 
85  // Destructor.
86  ~Vector();
87  void Clear();
88  void Reallocate(int i);
89  void Deallocate();
90 
91  // Management of the vectors.
92  template <class T0, class Storage0, class Allocator0>
93  void AddVector(const Vector<T0,
94  Storage0, Allocator0>& vector);
95  template <class T0, class Storage0, class Allocator0>
96  void AddVector(const Vector<T0,
97  Storage0, Allocator0>& vector, string name);
98  template <class T0, class Storage0, class Allocator0>
99  void SetVector(int i, const Vector<T0,
100  Storage0, Allocator0>& vector);
101  template <class T0, class Storage0, class Allocator0>
102  void SetVector(int i, const Vector<T0,
103  Storage0, Allocator0>& vector, string name);
104  template <class T0, class Storage0, class Allocator0>
105  void SetVector(string name, const Vector<T0,
106  Storage0, Allocator0>& vector);
107  void SetName(int i, string name);
108 
109  void SetData(const Vector<T, Collection, Allocator>& X);
110  void Nullify();
111 
112  // Basic methods.
113  int GetM() const;
114  int GetLength() const;
115  int GetNvector() const;
116 
117  const Vector<int, VectFull, MallocAlloc<int> >& GetVectorLength() const;
118  const Vector<int, VectFull, MallocAlloc<int> >& GetLengthSum() const;
119 
120  int GetVectorIndex(string name) const;
121  int GetIndex(string name) const;
122 
123  collection_reference GetVector();
124  const_collection_reference GetVector() const;
125  vector_reference GetVector(int i);
126  const_vector_reference GetVector(int i) const;
127  vector_reference GetVector(string name);
128  const_vector_reference GetVector(string name) const;
129 
130  // Element access and assignment.
131  const_reference operator() (int i) const;
132  reference operator() (int i);
135 
136  void Copy(const Vector<T, Collection, Allocator>& X);
137  template <class T0, class Allocator0>
138  void Copy(const Vector<T0, VectFull, Allocator0>& X);
139 
140  template <class T0>
141  Vector<T, Collection, Allocator>& operator*= (const T0& X);
142 
143  // Convenient method.
144  template <class T0>
145  void Fill(const T0& x);
146  void Print() const;
147 
148  // Input/output functions.
149  void Write(string FileName, bool with_size = true) const;
150  void Write(ostream& FileStream, bool with_size = true) const;
151  void WriteText(string FileName) const;
152  void WriteText(ostream& FileStream) const;
153 
154  void Read(string FileName);
155  void Read(string FileName, Vector<int, VectFull, MallocAlloc<int> >& length_);
156  void Read(istream& FileStream, Vector<int, VectFull, MallocAlloc<int> >& length_);
157 
158 
159  };
160 
161 
162  template <class T, class Allocator>
163  ostream& operator << (ostream& out,
165 
166 
167 } // namespace Seldon.
168 
169 
170 #define SELDON_FILE_VECTOR_VECTORCOLLECTION_HXX
171 #endif
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Vector< T, Collection, Allocator >::label_vector_
vector< string > label_vector_
Names associated with the inner vectors.
Definition: VectorCollection.hxx:76
Seldon::MallocAlloc
Definition: Allocator.hxx:32
Seldon::Collection
Definition: StorageInline.cxx:84
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::Vector_Base
Base structure for all vectors.
Definition: SeldonHeader.hxx:201
Seldon::Vector< T, Collection, Allocator >
Structure for distributed vectors.
Definition: VectorCollection.hxx:38
Seldon::Vector< T, Collection, Allocator >::label_map_
map< string, int > label_map_
Indexes of the inner vectors that have a name.
Definition: VectorCollection.hxx:74
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::operator<<
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
Definition: Array.cxx:1617
Seldon::AddVector
void AddVector(const T0 &alpha, const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Adds two vectors Y = Y + alpha X.
Definition: Functions_Vector.cxx:94