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