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