Vector2.hxx
1 // Copyright (C) 2010, INRIA
2 // Author(s): Marc Fragu, Vivien Mallet
3 // Copyright (C) 2011, Vivien Mallet
4 //
5 // This file is part of the linear-algebra library Seldon,
6 // http://seldon.sourceforge.net/.
7 //
8 // Seldon is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License as published by the Free
10 // Software Foundation; either version 2.1 of the License, or (at your option)
11 // any later version.
12 //
13 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
14 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with Seldon. If not, see http://www.gnu.org/licenses/.
20 
21 
22 #ifndef SELDON_FILE_VECTOR_VECTOR2_HXX
23 
24 
25 #ifndef SELDON_VECTOR2_DEFAULT_ALLOCATOR_1
26 
29 #define SELDON_VECTOR2_DEFAULT_ALLOCATOR_1 MallocObject
30 #endif
31 
32 
33 namespace Seldon
34 {
35 
36 
38 
49  template <class T, class Allocator0 =
50  typename SeldonDefaultAllocator<VectFull, T>::allocator,
51  class Allocator1 = SELDON_VECTOR2_DEFAULT_ALLOCATOR_1<
52  Vector<T, VectFull, Allocator0> > >
53  class Vector2
54  {
55  public:
56  typedef T value_type;
57  typedef T* pointer;
58  typedef const T* const_pointer;
59  typedef T& reference;
60  typedef const T& const_reference;
61 
62  protected:
64 
65  public:
66 
67  /*** Constructors and destructor ***/
68 
69  Vector2();
70  Vector2(long length);
71  Vector2(const Vector<long>& length);
72  ~Vector2();
73 
74  /*** Management of the vectors ***/
75 
76  bool IsEmpty() const;
77  long GetLength() const;
78  long GetSize() const;
79  long GetLength(long i) const;
80  long GetSize(long i) const;
81  size_t GetMemorySize() const;
82  long GetNelement() const;
83  long GetNelement(long beg, long end) const;
84  Vector<long> GetShape() const;
85  void GetShape(Vector<long>& shape) const;
86  void Reallocate(long M);
87  void Reallocate(long i, long N);
88  void Reallocate(const Vector<long>& length);
89  void Select(long beg, long end);
91  template <class Td, class Allocatord>
92  void Flatten(Vector<Td, VectFull, Allocatord>& data) const;
93  template <class Td, class Allocatord>
94  void Flatten(long beg, long end, Vector<Td, VectFull, Allocatord>& data)
95  const;
96 
97  void PushBack(long i, const T& x);
99 #ifndef SWIG
101  VectFull, Allocator1>& V);
102 #endif
104 
105  void Clear();
106  void Clear(long i);
107 
108  void Fill(const T& x);
109 
111  GetVector();
112 #ifndef SWIG
114  Allocator1> GetVector() const;
115 #endif
116 
118 #ifndef SWIG
119  const Vector<T, VectFull, Allocator0>& GetVector(long i) const;
120 #endif
121 
124 
125  /*** Element access and assignment ***/
126 
127 #ifndef SWIG
128  const Vector<T, VectFull, Allocator0>& operator() (long i) const;
129 #endif
131 #ifndef SWIG
132  const_reference operator() (long i, long j) const;
133 #endif
134  reference operator() (long i, long j);
135 
136  /*** Convenient methods ***/
137 
138  template <class V2>
139  bool HasSameShape(const V2& V) const;
140  void Print() const;
141 
142  /*** Input/output functions ***/
143 
144  void Write(string file_name, bool with_size = true) const;
145  void Write(ostream& file_stream, bool with_size = true) const;
146  void Read(string file_name, bool with_size = true);
147  void Read(istream& file_stream, bool with_size = true);
148  };
149 
150 
151 }
152 
153 
154 #define SELDON_FILE_VECTOR_VECTOR2_HXX
155 #endif
Seldon::Vector2::HasSameShape
bool HasSameShape(const V2 &V) const
Checks whether another Vector2 instance has the same shape.
Definition: Vector2.cxx:618
Seldon::Vector2::GetLength
long GetLength() const
Returns the size along dimension 1.
Definition: Vector2.cxx:126
Seldon::Vector2::GetSize
long GetSize() const
Returns the size along dimension 1.
Definition: Vector2.cxx:115
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Vector2
Vector of vectors.
Definition: Vector2.hxx:53
Seldon::Vector2::GetMemorySize
size_t GetMemorySize() const
Returns the memory used by the object in bytes.
Definition: Vector2.cxx:150
Seldon::Vector2::GetVector
Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > & GetVector()
Returns the vector of vectors.
Definition: Vector2.cxx:467
Seldon::Vector2::GetNelement
long GetNelement() const
Returns the total number of elements in the inner vectors.
Definition: Vector2.cxx:177
Seldon::Vector2::Print
void Print() const
Displays the vector.
Definition: Vector2.cxx:631
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::Vector2::IsEmpty
bool IsEmpty() const
Checks whether no elements are contained in the inner vectors.
Definition: Vector2.cxx:101
Seldon::Vector2::PushBack
void PushBack(long i, const T &x)
Appends an element at the end of the inner vector #i.
Definition: Vector2.cxx:384
Seldon::Vector2::Write
void Write(string file_name, bool with_size=true) const
Writes the instance in a binary file.
Definition: Vector2.cxx:657
Seldon::Vector2::~Vector2
~Vector2()
Destructor. The vector of vectors and the inner vectors are deallocated.
Definition: Vector2.cxx:86
Seldon::Vector2::Fill
void Fill(const T &x)
Fills the vector with a given value.
Definition: Vector2.cxx:454
Seldon::Vector2::Read
void Read(string file_name, bool with_size=true)
Reads the Vector2 from a file.
Definition: Vector2.cxx:729
Seldon::Vector2::GetShape
Vector< long > GetShape() const
Returns the shape.
Definition: Vector2.cxx:220
Seldon::Vector2::Select
void Select(long beg, long end)
Selects a range of inner vectors.
Definition: Vector2.cxx:288
Seldon::Vector2::Reallocate
void Reallocate(long M)
Reallocates the vector of vector.
Definition: Vector2.cxx:247
Seldon::Vector2::Clear
void Clear()
Clears the vector.
Definition: Vector2.cxx:432
Seldon::Vector2::Vector2
Vector2()
Default constructor.
Definition: Vector2.cxx:47
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Vector2::Flatten
Vector< T, VectFull, Allocator0 > Flatten() const
Returns all values in a vector.
Definition: Vector2.cxx:316
Seldon::Vector2::operator()
const Vector< T, VectFull, Allocator0 > & operator()(long i) const
Returns a given inner vector.
Definition: Vector2.cxx:555
Seldon::Vector2::Copy
Vector2< T, Allocator0, Allocator1 > Copy() const
Copies a Vector2 instance.
Definition: Vector2.cxx:535