HeterogeneousCollection.hxx
1 // Copyright (C) 2001-2009 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_HETEROGENEOUSCOLLECTION_HXX
22 
23 
24 #include "../share/Common.hxx"
25 #include "../share/Properties.hxx"
26 #include "../share/Storage.hxx"
27 #include "../share/Errors.hxx"
28 #include "../share/Allocator.hxx"
29 
30 
31 #ifndef SELDON_DEFAULT_COLLECTION_ALLOCATOR
32 #define SELDON_DEFAULT_COLLECTION_ALLOCATOR NewAlloc
33 #endif
34 
35 namespace Seldon
36 {
37 
39  template <class T, template <class U> class Allocator >
40  class Vector<FloatDouble, DenseSparseCollection, Allocator<T> >
41  : public Vector_Base<T, Allocator<T> >
42  {
43  // typedef declarations.
44  public:
49 
51  SELDON_DEFAULT_COLLECTION_ALLOCATOR<float_dense_v> >
54  SELDON_DEFAULT_COLLECTION_ALLOCATOR<float_sparse_v> >
57  SELDON_DEFAULT_COLLECTION_ALLOCATOR<double_dense_v> >
60  SELDON_DEFAULT_COLLECTION_ALLOCATOR<double_sparse_v> >
62 
64 
65  // Attributes.
66  protected:
68  int Nvector_;
77 
86 
88  map<string, int> label_map_;
90  vector<string> label_vector_;
91 
92  // Methods.
93  public:
94  // Constructor.
95  explicit Vector();
96  Vector(const Vector<FloatDouble, DenseSparseCollection, Allocator<T> >&);
97 
98  // Destructor.
99  ~Vector();
100  void Clear();
101  void Deallocate();
102 
103  // Management of the vectors.
104  void AddVector(const Vector<float, VectFull, Allocator<float> >&);
105  void AddVector(const Vector<float, VectSparse, Allocator<float> >&);
106  void AddVector(const Vector<double, VectFull, Allocator<double> >&);
107  void AddVector(const Vector<double, VectSparse, Allocator<double> >&);
108 
109  template <class T0, class Storage0, class Allocator0>
110  void AddVector(const Vector<T0, Storage0, Allocator0>&, string name);
111 
112  void SetVector(int i,
113  const Vector<float, VectFull, Allocator<float> >&);
114  void SetVector(int i,
115  const Vector<float, VectSparse, Allocator<float> >&);
116  void SetVector(int i,
117  const Vector<double, VectFull, Allocator<double> >&);
118  void SetVector(int i,
119  const Vector<double, VectSparse, Allocator<double> >&);
120 
121  template <class T0, class Storage0, class Allocator0>
122  void SetVector(int i, const Vector<T0, Storage0, Allocator0>&,
123  string name);
124  template <class T0, class Storage0, class Allocator0>
125  void SetVector(string name, const Vector<T0, Storage0, Allocator0>&);
126  void SetName(int i, string name);
127 
128  void Nullify();
129 
130  // Basic methods.
131  int GetM() const;
132  int GetLength() const;
133  int GetNvector() const;
134 
135  const Vector<int, VectFull, MallocAlloc<int> >& GetVectorLength() const;
136  const Vector<int, VectFull, MallocAlloc<int> >& GetLengthSum() const;
137  const Vector<int, VectFull, MallocAlloc<int> >& GetCollectionIndex()
138  const;
139  const Vector<int, VectFull, MallocAlloc<int> >& GetSubvectorIndex() const;
140 
141  float_dense_c& GetFloatDense();
142  const float_dense_c& GetFloatDense() const;
143  float_sparse_c& GetFloatSparse();
144  const float_sparse_c& GetFloatSparse() const;
145  double_dense_c& GetDoubleDense();
146  const double_dense_c& GetDoubleDense() const;
147  double_sparse_c& GetDoubleSparse();
148  const double_sparse_c& GetDoubleSparse() const;
149 
150 
151  void GetVector(int i, float_dense_v& vector) const;
152  void GetVector(int i, float_sparse_v& vector) const;
153  void GetVector(int i, double_dense_v& vector) const;
154  void GetVector(int i, double_sparse_v& vector) const;
155  template <class T0, class Storage0, class Allocator0>
156  void GetVector(string name, Vector<T0, Storage0, Allocator0>& vector)
157  const;
158 
159  // Element access and assignment.
160  double operator() (int i) const;
161 
164 
165  void
166  Copy(const Vector<FloatDouble, DenseSparseCollection, Allocator<T> >& X);
167 
168  template <class T0>
170  operator*= (const T0& X);
171 
172  // Convenient method.
173  void Print() const;
174 
175  // Input/output functions.
176  void Write(string FileName, bool with_size) const;
177  void Write(ostream& FileStream, bool with_size) const;
178  void WriteText(string FileName) const;
179  void WriteText(ostream& FileStream) const;
180 
181  void Read(string FileName);
182  void Read(istream& FileStream);
183 
184  protected:
185  string GetType(int i) const;
186  };
187 
188  template <class T, template <class U> class Allocator >
189  ostream& operator << (ostream& out,
191  Allocator<T> >& V);
192 
193 } // namespace Seldon.
194 
195 
196 #define SELDON_FILE_VECTOR_HETEROGENEOUSCOLLECTION_HXX
197 #endif
Seldon::FloatDouble
Definition: Storage.hxx:365
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::float_sparse_c_
float_sparse_c float_sparse_c_
Pointers of the underlying float sparse vectors.
Definition: HeterogeneousCollection.hxx:81
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::float_dense_c_
float_dense_c float_dense_c_
Pointers of the underlying float dense vectors.
Definition: HeterogeneousCollection.hxx:79
Seldon::DenseSparseCollection
Definition: StorageInline.cxx:89
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::double_dense_c_
double_dense_c double_dense_c_
Pointers of the underlying double dense vectors.
Definition: HeterogeneousCollection.hxx:83
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::length_
Vector< int, VectFull, MallocAlloc< int > > length_
Lengths of the underlying vectors.
Definition: HeterogeneousCollection.hxx:74
Seldon::Collection
Definition: StorageInline.cxx:84
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::label_map_
map< string, int > label_map_
Indexes of the inner vectors that have a name.
Definition: HeterogeneousCollection.hxx:88
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::subvector_
Vector< int, VectFull, MallocAlloc< int > > subvector_
Index of the underlying vectors in the inner collection.
Definition: HeterogeneousCollection.hxx:72
Seldon::Vector_Base
Base structure for all vectors.
Definition: SeldonHeader.hxx:201
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::collection_
Vector< int, VectFull, MallocAlloc< int > > collection_
For each underlying vectors, index of the corresponding collection.
Definition: HeterogeneousCollection.hxx:70
Seldon::VectSparse
Definition: StorageInline.cxx:79
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::Nvector_
int Nvector_
Total number of vectors.
Definition: HeterogeneousCollection.hxx:68
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::double_sparse_c_
double_sparse_c double_sparse_c_
Pointers of the underlying float sparse vectors.
Definition: HeterogeneousCollection.hxx:85
Seldon::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::length_sum_
Vector< int, VectFull, MallocAlloc< int > > length_sum_
Cumulative sum of the lengths of the underlying vectors.
Definition: HeterogeneousCollection.hxx:76
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::Vector< FloatDouble, DenseSparseCollection, Allocator< T > >::label_vector_
vector< string > label_vector_
Names associated with the inner vectors.
Definition: HeterogeneousCollection.hxx:90
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