max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 // Copyright (C) 2009-2010 Ian Cullinan
|
max@0
|
4 //
|
max@0
|
5 // This file is part of the Armadillo C++ library.
|
max@0
|
6 // It is provided without any warranty of fitness
|
max@0
|
7 // for any purpose. You can redistribute this file
|
max@0
|
8 // and/or modify it under the terms of the GNU
|
max@0
|
9 // Lesser General Public License (LGPL) as published
|
max@0
|
10 // by the Free Software Foundation, either version 3
|
max@0
|
11 // of the License or (at your option) any later version.
|
max@0
|
12 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
13
|
max@0
|
14
|
max@0
|
15 //! \addtogroup field
|
max@0
|
16 //! @{
|
max@0
|
17
|
max@0
|
18
|
max@0
|
19
|
max@0
|
20 struct field_prealloc_n_elem
|
max@0
|
21 {
|
max@0
|
22 static const uword val = 16;
|
max@0
|
23 };
|
max@0
|
24
|
max@0
|
25
|
max@0
|
26
|
max@0
|
27 //! A lightweight 2D container for abitrary objects
|
max@0
|
28 //! (the objects must have a copy constructor)
|
max@0
|
29
|
max@0
|
30 template<typename oT>
|
max@0
|
31 class field
|
max@0
|
32 {
|
max@0
|
33 public:
|
max@0
|
34
|
max@0
|
35 typedef oT object_type;
|
max@0
|
36
|
max@0
|
37 const uword n_rows; //!< number of rows in the field (read-only)
|
max@0
|
38 const uword n_cols; //!< number of columns in the field (read-only)
|
max@0
|
39 const uword n_elem; //!< number of elements in the field (read-only)
|
max@0
|
40
|
max@0
|
41
|
max@0
|
42 private:
|
max@0
|
43
|
max@0
|
44 arma_aligned oT** mem; //!< pointer to memory used by the object
|
max@0
|
45 arma_aligned oT* mem_local[ field_prealloc_n_elem::val ];
|
max@0
|
46 //!< Internal memory, to avoid calling the 'new' operator for small amounts of memory
|
max@0
|
47
|
max@0
|
48
|
max@0
|
49 public:
|
max@0
|
50
|
max@0
|
51 inline ~field();
|
max@0
|
52 inline field();
|
max@0
|
53
|
max@0
|
54 inline field(const field& x);
|
max@0
|
55 inline const field& operator=(const field& x);
|
max@0
|
56
|
max@0
|
57 inline field(const subview_field<oT>& x);
|
max@0
|
58 inline const field& operator=(const subview_field<oT>& x);
|
max@0
|
59
|
max@0
|
60 inline explicit field(const uword n_elem_in);
|
max@0
|
61 inline field(const uword n_rows_in, const uword n_cols_in);
|
max@0
|
62
|
max@0
|
63 inline void set_size(const uword n_obj_in);
|
max@0
|
64 inline void set_size(const uword n_rows_in, const uword n_cols_in);
|
max@0
|
65
|
max@0
|
66 template<typename oT2>
|
max@0
|
67 inline void copy_size(const field<oT2>& x);
|
max@0
|
68
|
max@0
|
69 arma_inline oT& operator[](const uword i);
|
max@0
|
70 arma_inline const oT& operator[](const uword i) const;
|
max@0
|
71
|
max@0
|
72 arma_inline oT& at(const uword i);
|
max@0
|
73 arma_inline const oT& at(const uword i) const;
|
max@0
|
74
|
max@0
|
75 arma_inline oT& operator()(const uword i);
|
max@0
|
76 arma_inline const oT& operator()(const uword i) const;
|
max@0
|
77
|
max@0
|
78 arma_inline oT& at(const uword row, const uword col);
|
max@0
|
79 arma_inline const oT& at(const uword row, const uword col) const;
|
max@0
|
80
|
max@0
|
81 arma_inline oT& operator()(const uword row, const uword col);
|
max@0
|
82 arma_inline const oT& operator()(const uword row, const uword col) const;
|
max@0
|
83
|
max@0
|
84 inline field_injector<field> operator<<(const oT& val);
|
max@0
|
85 inline field_injector<field> operator<<(const injector_end_of_row& x);
|
max@0
|
86
|
max@0
|
87
|
max@0
|
88 inline subview_field<oT> row(const uword row_num);
|
max@0
|
89 inline const subview_field<oT> row(const uword row_num) const;
|
max@0
|
90
|
max@0
|
91 inline subview_field<oT> col(const uword col_num);
|
max@0
|
92 inline const subview_field<oT> col(const uword col_num) const;
|
max@0
|
93
|
max@0
|
94 inline subview_field<oT> rows(const uword in_row1, const uword in_row2);
|
max@0
|
95 inline const subview_field<oT> rows(const uword in_row1, const uword in_row2) const;
|
max@0
|
96
|
max@0
|
97 inline subview_field<oT> cols(const uword in_col1, const uword in_col2);
|
max@0
|
98 inline const subview_field<oT> cols(const uword in_col1, const uword in_col2) const;
|
max@0
|
99
|
max@0
|
100 inline subview_field<oT> subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2);
|
max@0
|
101 inline const subview_field<oT> subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const;
|
max@0
|
102
|
max@0
|
103 inline subview_field<oT> subfield (const span& row_span, const span& col_span);
|
max@0
|
104 inline const subview_field<oT> subfield (const span& row_span, const span& col_span) const;
|
max@0
|
105
|
max@0
|
106 inline subview_field<oT> operator()(const span& row_span, const span& col_span);
|
max@0
|
107 inline const subview_field<oT> operator()(const span& row_span, const span& col_span) const;
|
max@0
|
108
|
max@0
|
109
|
max@0
|
110 inline void print(const std::string extra_text = "") const;
|
max@0
|
111 inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
|
max@0
|
112
|
max@0
|
113 inline void fill(const oT& x);
|
max@0
|
114
|
max@0
|
115 inline void reset();
|
max@0
|
116 inline void reset_objects();
|
max@0
|
117
|
max@0
|
118 arma_inline bool is_empty() const;
|
max@0
|
119
|
max@0
|
120 arma_inline arma_warn_unused bool in_range(const uword i) const;
|
max@0
|
121 arma_inline arma_warn_unused bool in_range(const span& x) const;
|
max@0
|
122
|
max@0
|
123 arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col ) const;
|
max@0
|
124 arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col ) const;
|
max@0
|
125 arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const;
|
max@0
|
126 arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const;
|
max@0
|
127
|
max@0
|
128 inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const;
|
max@0
|
129 inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const;
|
max@0
|
130
|
max@0
|
131 inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true);
|
max@0
|
132 inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true);
|
max@0
|
133
|
max@0
|
134
|
max@0
|
135 inline bool quiet_save(const std::string name, const file_type type = arma_binary) const;
|
max@0
|
136 inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const;
|
max@0
|
137
|
max@0
|
138 inline bool quiet_load(const std::string name, const file_type type = auto_detect);
|
max@0
|
139 inline bool quiet_load( std::istream& is, const file_type type = auto_detect);
|
max@0
|
140
|
max@0
|
141
|
max@0
|
142 // iterators
|
max@0
|
143
|
max@0
|
144 class iterator
|
max@0
|
145 {
|
max@0
|
146 public:
|
max@0
|
147
|
max@0
|
148 inline iterator(field<oT>& in_M, const bool at_end = false);
|
max@0
|
149
|
max@0
|
150 inline oT& operator* ();
|
max@0
|
151
|
max@0
|
152 inline iterator& operator++();
|
max@0
|
153 inline void operator++(int);
|
max@0
|
154
|
max@0
|
155 inline iterator& operator--();
|
max@0
|
156 inline void operator--(int);
|
max@0
|
157
|
max@0
|
158 inline bool operator!=(const iterator& X) const;
|
max@0
|
159 inline bool operator==(const iterator& X) const;
|
max@0
|
160
|
max@0
|
161 arma_aligned field<oT>& M;
|
max@0
|
162 arma_aligned uword i;
|
max@0
|
163 };
|
max@0
|
164
|
max@0
|
165
|
max@0
|
166 class const_iterator
|
max@0
|
167 {
|
max@0
|
168 public:
|
max@0
|
169
|
max@0
|
170 const_iterator(const field<oT>& in_M, const bool at_end = false);
|
max@0
|
171 const_iterator(const iterator& X);
|
max@0
|
172
|
max@0
|
173 inline const oT& operator*() const;
|
max@0
|
174
|
max@0
|
175 inline const_iterator& operator++();
|
max@0
|
176 inline void operator++(int);
|
max@0
|
177
|
max@0
|
178 inline const_iterator& operator--();
|
max@0
|
179 inline void operator--(int);
|
max@0
|
180
|
max@0
|
181 inline bool operator!=(const const_iterator& X) const;
|
max@0
|
182 inline bool operator==(const const_iterator& X) const;
|
max@0
|
183
|
max@0
|
184 arma_aligned const field<oT>& M;
|
max@0
|
185 arma_aligned uword i;
|
max@0
|
186 };
|
max@0
|
187
|
max@0
|
188 inline iterator begin();
|
max@0
|
189 inline const_iterator begin() const;
|
max@0
|
190
|
max@0
|
191 inline iterator end();
|
max@0
|
192 inline const_iterator end() const;
|
max@0
|
193
|
max@0
|
194
|
max@0
|
195 private:
|
max@0
|
196
|
max@0
|
197 inline void init(const field<oT>& x);
|
max@0
|
198 inline void init(const uword n_rows_in, const uword n_cols_in);
|
max@0
|
199
|
max@0
|
200 inline void delete_objects();
|
max@0
|
201 inline void create_objects();
|
max@0
|
202
|
max@0
|
203 friend class field_aux;
|
max@0
|
204 friend class subview_field<oT>;
|
max@0
|
205
|
max@0
|
206
|
max@0
|
207 public:
|
max@0
|
208
|
max@0
|
209 #ifdef ARMA_EXTRA_FIELD_PROTO
|
max@0
|
210 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_PROTO)
|
max@0
|
211 #endif
|
max@0
|
212 };
|
max@0
|
213
|
max@0
|
214
|
max@0
|
215
|
max@0
|
216 class field_aux
|
max@0
|
217 {
|
max@0
|
218 public:
|
max@0
|
219
|
max@0
|
220 template<typename oT> inline static void reset_objects(field< oT >& x);
|
max@0
|
221 template<typename eT> inline static void reset_objects(field< Mat<eT> >& x);
|
max@0
|
222 template<typename eT> inline static void reset_objects(field< Col<eT> >& x);
|
max@0
|
223 template<typename eT> inline static void reset_objects(field< Row<eT> >& x);
|
max@0
|
224 template<typename eT> inline static void reset_objects(field< Cube<eT> >& x);
|
max@0
|
225 inline static void reset_objects(field< std::string >& x);
|
max@0
|
226
|
max@0
|
227
|
max@0
|
228 template<typename oT> inline static bool save(const field< oT >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
229 template<typename oT> inline static bool save(const field< oT >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
230 template<typename oT> inline static bool load( field< oT >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
231 template<typename oT> inline static bool load( field< oT >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
232
|
max@0
|
233 template<typename eT> inline static bool save(const field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
234 template<typename eT> inline static bool save(const field< Mat<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
235 template<typename eT> inline static bool load( field< Mat<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
236 template<typename eT> inline static bool load( field< Mat<eT> >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
237
|
max@0
|
238 template<typename eT> inline static bool save(const field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
239 template<typename eT> inline static bool save(const field< Col<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
240 template<typename eT> inline static bool load( field< Col<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
241 template<typename eT> inline static bool load( field< Col<eT> >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
242
|
max@0
|
243 template<typename eT> inline static bool save(const field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
244 template<typename eT> inline static bool save(const field< Row<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
245 template<typename eT> inline static bool load( field< Row<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
246 template<typename eT> inline static bool load( field< Row<eT> >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
247
|
max@0
|
248 template<typename eT> inline static bool save(const field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
249 template<typename eT> inline static bool save(const field< Cube<eT> >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
250 template<typename eT> inline static bool load( field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
251 template<typename eT> inline static bool load( field< Cube<eT> >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
252
|
max@0
|
253 inline static bool save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
254 inline static bool save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg);
|
max@0
|
255 inline static bool load( field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg);
|
max@0
|
256 inline static bool load( field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg);
|
max@0
|
257
|
max@0
|
258 };
|
max@0
|
259
|
max@0
|
260
|
max@0
|
261 //! @}
|