1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup fn_size
20 //! @{
21 
22 
23 
24 arma_warn_unused
25 inline
26 const SizeMat
size(const uword n_rows,const uword n_cols)27 size(const uword n_rows, const uword n_cols)
28   {
29   arma_extra_debug_sigprint();
30 
31   return SizeMat(n_rows, n_cols);
32   }
33 
34 
35 
36 template<typename T1>
37 arma_warn_unused
38 inline
39 const SizeMat
size(const Base<typename T1::elem_type,T1> & X)40 size(const Base<typename T1::elem_type,T1>& X)
41   {
42   arma_extra_debug_sigprint();
43 
44   const Proxy<T1> P(X.get_ref());
45 
46   return SizeMat( P.get_n_rows(), P.get_n_cols() );
47   }
48 
49 
50 
51 // explicit overload to workround ADL issues with C++17 std::size()
52 template<typename eT>
53 arma_warn_unused
54 inline
55 const SizeMat
size(const Mat<eT> & X)56 size(const Mat<eT>& X)
57   {
58   arma_extra_debug_sigprint();
59 
60   return SizeMat( X.n_rows, X.n_cols );
61   }
62 
63 
64 
65 // explicit overload to workround ADL issues with C++17 std::size()
66 template<typename eT>
67 arma_warn_unused
68 inline
69 const SizeMat
size(const Row<eT> & X)70 size(const Row<eT>& X)
71   {
72   arma_extra_debug_sigprint();
73 
74   return SizeMat( X.n_rows, X.n_cols );
75   }
76 
77 
78 
79 // explicit overload to workround ADL issues with C++17 std::size()
80 template<typename eT>
81 arma_warn_unused
82 inline
83 const SizeMat
size(const Col<eT> & X)84 size(const Col<eT>& X)
85   {
86   arma_extra_debug_sigprint();
87 
88   return SizeMat( X.n_rows, X.n_cols );
89   }
90 
91 
92 
93 arma_warn_unused
94 inline
95 const SizeMat
size(const arma::span & row_span,const arma::span & col_span)96 size(const arma::span& row_span, const arma::span& col_span)
97   {
98   arma_extra_debug_sigprint();
99 
100   uword n_rows = 0;
101   uword n_cols = 0;
102 
103   if(row_span.whole || col_span.whole)
104     {
105     arma_debug_check(true, "size(): span::all not supported");
106     }
107   else
108     {
109     if((row_span.a > row_span.b) || (col_span.a > col_span.b))
110       {
111       arma_debug_check_bounds(true, "size(): span indices incorrectly used");
112       }
113     else
114       {
115       n_rows = row_span.b - row_span.a + 1;
116       n_cols = col_span.b - col_span.a + 1;
117       }
118     }
119 
120   return SizeMat(n_rows, n_cols);
121   }
122 
123 
124 
125 template<typename T1>
126 arma_warn_unused
127 inline
128 uword
size(const Base<typename T1::elem_type,T1> & X,const uword dim)129 size(const Base<typename T1::elem_type,T1>& X, const uword dim)
130   {
131   arma_extra_debug_sigprint();
132 
133   const Proxy<T1> P(X.get_ref());
134 
135   return SizeMat( P.get_n_rows(), P.get_n_cols() )( dim );
136   }
137 
138 
139 
140 arma_warn_unused
141 inline
142 const SizeCube
size(const uword n_rows,const uword n_cols,const uword n_slices)143 size(const uword n_rows, const uword n_cols, const uword n_slices)
144   {
145   arma_extra_debug_sigprint();
146 
147   return SizeCube(n_rows, n_cols, n_slices);
148   }
149 
150 
151 
152 template<typename T1>
153 arma_warn_unused
154 inline
155 const SizeCube
size(const BaseCube<typename T1::elem_type,T1> & X)156 size(const BaseCube<typename T1::elem_type, T1>& X)
157   {
158   arma_extra_debug_sigprint();
159 
160   const ProxyCube<T1> P(X.get_ref());
161 
162   return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() );
163   }
164 
165 
166 
167 // explicit overload to workround ADL issues with C++17 std::size()
168 template<typename eT>
169 arma_warn_unused
170 inline
171 const SizeCube
size(const Cube<eT> & X)172 size(const Cube<eT>& X)
173   {
174   arma_extra_debug_sigprint();
175 
176   return SizeCube( X.n_rows, X.n_cols, X.n_slices );
177   }
178 
179 
180 
181 template<typename T1>
182 arma_warn_unused
183 inline
184 uword
size(const BaseCube<typename T1::elem_type,T1> & X,const uword dim)185 size(const BaseCube<typename T1::elem_type, T1>& X, const uword dim)
186   {
187   arma_extra_debug_sigprint();
188 
189   const ProxyCube<T1> P(X.get_ref());
190 
191   return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() )( dim );
192   }
193 
194 
195 
196 arma_warn_unused
197 inline
198 const SizeCube
size(const arma::span & row_span,const arma::span & col_span,const arma::span & slice_span)199 size(const arma::span& row_span, const arma::span& col_span, const arma::span& slice_span)
200   {
201   arma_extra_debug_sigprint();
202 
203   uword n_rows   = 0;
204   uword n_cols   = 0;
205   uword n_slices = 0;
206 
207   if(row_span.whole || col_span.whole || slice_span.whole)
208     {
209     arma_debug_check(true, "size(): span::all not supported");
210     }
211   else
212     {
213     if((row_span.a > row_span.b) || (col_span.a > col_span.b) || (slice_span.a > slice_span.b))
214       {
215       arma_debug_check_bounds(true, "size(): span indices incorrectly used");
216       }
217     else
218       {
219       n_rows   =   row_span.b -   row_span.a + 1;
220       n_cols   =   col_span.b -   col_span.a + 1;
221       n_slices = slice_span.b - slice_span.a + 1;
222       }
223     }
224 
225   return SizeCube(n_rows, n_cols, n_slices);
226   }
227 
228 
229 
230 template<typename T1>
231 arma_warn_unused
232 inline
233 const SizeMat
size(const SpBase<typename T1::elem_type,T1> & X)234 size(const SpBase<typename T1::elem_type,T1>& X)
235   {
236   arma_extra_debug_sigprint();
237 
238   const SpProxy<T1> P(X.get_ref());
239 
240   return SizeMat( P.get_n_rows(), P.get_n_cols() );
241   }
242 
243 
244 
245 // explicit overload to workround ADL issues with C++17 std::size()
246 template<typename eT>
247 arma_warn_unused
248 inline
249 const SizeMat
size(const SpMat<eT> & X)250 size(const SpMat<eT>& X)
251   {
252   arma_extra_debug_sigprint();
253 
254   return SizeMat( X.n_rows, X.n_cols );
255   }
256 
257 
258 
259 template<typename T1>
260 arma_warn_unused
261 inline
262 uword
size(const SpBase<typename T1::elem_type,T1> & X,const uword dim)263 size(const SpBase<typename T1::elem_type,T1>& X, const uword dim)
264   {
265   arma_extra_debug_sigprint();
266 
267   const SpProxy<T1> P(X.get_ref());
268 
269   return SizeMat( P.get_n_rows(), P.get_n_cols() )( dim );
270   }
271 
272 
273 
274 
275 template<typename oT>
276 arma_warn_unused
277 inline
278 const SizeCube
size(const field<oT> & X)279 size(const field<oT>& X)
280   {
281   arma_extra_debug_sigprint();
282 
283   return SizeCube( X.n_rows, X.n_cols, X.n_slices );
284   }
285 
286 
287 
288 template<typename oT>
289 arma_warn_unused
290 inline
291 uword
size(const field<oT> & X,const uword dim)292 size(const field<oT>& X, const uword dim)
293   {
294   arma_extra_debug_sigprint();
295 
296   return SizeCube( X.n_rows, X.n_cols, X.n_slices )( dim );
297   }
298 
299 
300 
301 template<typename oT>
302 arma_warn_unused
303 inline
304 const SizeCube
size(const subview_field<oT> & X)305 size(const subview_field<oT>& X)
306   {
307   arma_extra_debug_sigprint();
308 
309   return SizeCube( X.n_rows, X.n_cols, X.n_slices );
310   }
311 
312 
313 
314 template<typename oT>
315 arma_warn_unused
316 inline
317 uword
size(const subview_field<oT> & X,const uword dim)318 size(const subview_field<oT>& X, const uword dim)
319   {
320   arma_extra_debug_sigprint();
321 
322   return SizeCube( X.n_rows, X.n_cols, X.n_slices )( dim );
323   }
324 
325 
326 
327 //! @}
328