Vector3.hxx
1 // Copyright (C) 2010-2012, 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_VECTOR_3_HXX
22 
23 
24 #ifndef SELDON_VECTOR3_DEFAULT_ALLOCATOR_1
25 
28 #define SELDON_VECTOR3_DEFAULT_ALLOCATOR_1 MallocObject
29 #endif
30 
31 #ifndef SELDON_VECTOR3_DEFAULT_ALLOCATOR_2
32 #define SELDON_VECTOR3_DEFAULT_ALLOCATOR_2 MallocObject
33 
36 #endif
37 
38 
39 namespace Seldon
40 {
41 
43 
57  template <class T, class Allocator0 =
58  typename SeldonDefaultAllocator<VectFull, T>::allocator,
59  class Allocator1 = SELDON_VECTOR3_DEFAULT_ALLOCATOR_1<
60  Vector<T, Vect_Full, Allocator0> >,
61  class Allocator2 =
62  SELDON_VECTOR3_DEFAULT_ALLOCATOR_2<
63  Vector<Vector<T, Vect_Full, Allocator0>,
64  Vect_Full, Allocator1> > >
65  class Vector3
66  {
67  public:
68  typedef T value_type;
69  typedef T* pointer;
70  typedef const T* const_pointer;
71  typedef T& reference;
72  typedef const T& const_reference;
73 
74  protected:
75  Vector<Vector<Vector<T, Vect_Full, Allocator0>, Vect_Full, Allocator1>,
76  Vect_Full, Allocator2> data_;
77 
78  public:
79 
80  /*** Constructors and destructor ***/
81 
82  Vector3();
83  Vector3(int);
84  Vector3(Vector<int>& length);
85  template <class Allocator>
86  Vector3(Vector<Vector<int>, Vect_Full, Allocator>& length);
87  ~Vector3();
88 
89  /*** Management of the vectors ***/
90 
91  int GetLength() const;
92  int GetSize() const;
93  int GetLength(int i) const;
94  int GetSize(int i) const;
95  int GetLength(int i, int j) const;
96  int GetSize(int i, int j) const;
97  size_t GetMemorySize() const;
98  int GetNelement() const;
99  int GetNelement(int beg, int end) const;
100  int GetNelement(int beg0, int end0, int beg1, int end1) const;
101  Vector<int> GetShape(int i) const;
102  void GetShape(int i, Vector<int>& shape) const;
103  void Reallocate(int N);
104  void Reallocate(int i, int N);
105  void Reallocate(int i, int j, int N);
106 
107  template <class Td, class Allocatord>
108  void Flatten(Vector<Td, VectFull, Allocatord>& data) const;
109  template <class Td, class Allocatord>
110  void Flatten(int beg, int end, Vector<Td, VectFull, Allocatord>& data)
111  const;
112  template <class Td, class Allocatord>
113  void Flatten(int beg0, int end0, int beg1, int end1,
115 
116  void PushBack(int i, int j, const T& x);
117  void PushBack(int i, const Vector<T, Vect_Full, Allocator0>& X);
119  Vect_Full, Allocator1>& X);
121  Vect_Full, Allocator1>, Vect_Full, Allocator2>& X);
123 
124 
125  void Clear();
126  void Clear(int i);
127  void Clear(int i, int j);
128 
129  void Fill(const T& x);
130 
131  Vector<Vector<Vector<T, Vect_Full, Allocator0>, Vect_Full, Allocator1>,
132  Vect_Full, Allocator2>&
133  GetVector();
135  Vect_Full, Allocator1>, Vect_Full, Allocator2>&
136  GetVector() const;
137 
139  GetVector(int i);
141  GetVector(int i) const;
142 
144  const Vector<T, Vect_Full, Allocator0>& GetVector(int i, int j) const;
145 
146  /*** Element access and assignment ***/
147  const
149  operator() (int i) const;
151  operator() (int i);
152 
153  const Vector<T, Vect_Full, Allocator0>& operator() (int i, int j)
154  const;
156 
157  const_reference operator() (int i, int j, int k) const;
158  reference operator() (int i, int j, int k);
159 
160  /*** Convenient method ***/
161 
162  void Print() const;
163 
164  /*** Input/output functions ***/
165 
166  void Write(string file_name, bool with_size = true) const;
167  void Write(ostream& file_stream, bool with_size = true) const;
168  void Read(string file_name, bool with_size = true);
169  void Read(istream& file_stream, bool with_size = true);
170  };
171 
172 }
173 
174 
175 #define SELDON_FILE_VECTOR_VECTOR_3_HXX
176 #endif
Seldon::Vector3::Reallocate
void Reallocate(int N)
Reallocates the vector of vectors of vectors.
Definition: Vector3.cxx:366
Seldon::Vector3::Vector3
Vector3()
Default constructor.
Definition: Vector3.cxx:46
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Vector3::Read
void Read(string file_name, bool with_size=true)
Reads the Vector3 from a file.
Definition: Vector3.cxx:909
Seldon::Vector3::Clear
void Clear()
Clears the vector.
Definition: Vector3.cxx:586
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::Vector3::GetShape
Vector< int > GetShape(int i) const
Returns the shape of a vector of vectors.
Definition: Vector3.cxx:336
Seldon::Vector3
Vector of vectors of vectors.
Definition: Vector3.hxx:65
Seldon::Vector3::GetSize
int GetSize() const
Returns size along dimension 1.
Definition: Vector3.cxx:146
Seldon::Vector3::Fill
void Fill(const T &x)
Fills the vector with a given value.
Definition: Vector3.cxx:621
Seldon::Vector3::GetMemorySize
size_t GetMemorySize() const
Returns the memory used by the object in bytes.
Definition: Vector3.cxx:210
Seldon::Vector3::Flatten
void Flatten(Vector< Td, VectFull, Allocatord > &data) const
Returns all values in a vector.
Definition: Vector3.cxx:407
Seldon::Vector3::~Vector3
~Vector3()
Destructor.
Definition: Vector3.cxx:120
Seldon::Vector3::PushBack
void PushBack(int i, int j, const T &x)
Appends an element at the end of the inner vector #i #j.
Definition: Vector3.cxx:523
Seldon::Vector3::GetVector
Vector< Vector< Vector< T, Vect_Full, Allocator0 >, Vect_Full, Allocator1 >, Vect_Full, Allocator2 > & GetVector()
Returns the vector of vectors of vectors.
Definition: Vector3.cxx:636
Seldon::Vector3::Print
void Print() const
Displays the vector.
Definition: Vector3.cxx:810
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Vector3::operator()
const Vector< Vector< T, Vect_Full, Allocator0 >, VectFull, Allocator1 > & operator()(int i) const
Returns a given inner vector of vectors.
Definition: Vector3.cxx:723
Seldon::Vector3::GetLength
int GetLength() const
Returns size along dimension 1.
Definition: Vector3.cxx:135
Seldon::Vector3::GetNelement
int GetNelement() const
Returns the total number of elements in the inner vectors.
Definition: Vector3.cxx:229
Seldon::Vector3::Write
void Write(string file_name, bool with_size=true) const
Writes the instance in a binary file.
Definition: Vector3.cxx:834