1 // Copyright (C) 2006  Davis E. King (davis@dlib.net)
2 // License: Boost Software License   See LICENSE.txt for the full license.
3 #undef DLIB_MATRIx_MAT_ABSTRACT_Hh_
4 #ifdef DLIB_MATRIx_MAT_ABSTRACT_Hh_
5 
6 #include "matrix_abstract.h"
7 #inclue <vector>
8 #include "../array/array_kernel_abstract.h"
9 #include "../array2d/array2d_kernel_abstract.h"
10 
11 namespace dlib
12 {
13 
14 // ----------------------------------------------------------------------------------------
15 
16     template <
17         typename EXP
18         >
19     const matrix_exp<EXP>& mat (
20         const matrix_exp<EXP>& m
21     );
22     /*!
23         ensures
24             - returns m
25               (i.e. this function just returns the input matrix without any modifications)
26     !*/
27 
28 // ----------------------------------------------------------------------------------------
29 
30     template <
31         typename image_type
32         >
33     const matrix_exp mat (
34         const image_type& img
35     );
36     /*!
37         requires
38             - image_type == an image object that implements the interface defined in
39               dlib/image_processing/generic_image.h or image_type is a image_view or
40               const_image_view object.
41         ensures
42             - This function converts any kind of generic image object into a dlib::matrix
43               expression.  Therefore, it is capable of converting objects like dlib::array2d
44               of dlib::cv_image.
45             - returns a matrix R such that:
46                 - R.nr() == array.nr()
47                 - R.nc() == array.nc()
48                 - for all valid r and c:
49                   R(r, c) == array[r][c]
50     !*/
51 
52 // ----------------------------------------------------------------------------------------
53 
54     template <
55         typename T,
56         typename MM
57         >
58     const matrix_exp mat (
59         const array<T,MM>& m
60     );
61     /*!
62         ensures
63             - returns a matrix R such that:
64                 - is_col_vector(R) == true
65                 - R.size() == m.size()
66                 - for all valid r:
67                   R(r) == m[r]
68     !*/
69 
70 // ----------------------------------------------------------------------------------------
71 
72     template <
73         typename value_type,
74         typename alloc
75         >
76     const matrix_exp mat (
77         const std::vector<value_type,alloc>& vector
78     );
79     /*!
80         ensures
81             - returns a matrix R such that:
82                 - is_col_vector(R) == true
83                 - R.size() == vector.size()
84                 - for all valid r:
85                   R(r) == vector[r]
86     !*/
87 
88 // ----------------------------------------------------------------------------------------
89 
90     template <
91         typename value_type,
92         typename alloc
93         >
94     const matrix_exp mat (
95         const std_vector_c<value_type,alloc>& vector
96     );
97     /*!
98         ensures
99             - returns a matrix R such that:
100                 - is_col_vector(R) == true
101                 - R.size() == vector.size()
102                 - for all valid r:
103                   R(r) == vector[r]
104     !*/
105 
106 // ----------------------------------------------------------------------------------------
107 
108     template <
109         typename T
110         >
111     const matrix_exp mat (
112         const T* ptr,
113         long nr
114     );
115     /*!
116         requires
117             - nr >= 0
118             - ptr == a pointer to at least nr T objects (or the NULL pointer if nr==0)
119         ensures
120             - returns a matrix M such that:
121                 - M.nr() == nr
122                 - m.nc() == 1
123                 - for all valid i:
124                   M(i) == ptr[i]
125             - Note that the returned matrix doesn't take "ownership" of
126               the pointer and thus will not delete or free it.
127     !*/
128 
129 // ----------------------------------------------------------------------------------------
130 
131     template <
132         typename T
133         >
134     const matrix_exp mat (
135         const T* ptr,
136         long nr,
137         long nc
138     );
139     /*!
140         requires
141             - nr >= 0
142             - nc >= 0
143             - ptr == a pointer to at least nr*nc T objects (or the NULL pointer if nr*nc==0)
144         ensures
145             - returns a matrix M such that:
146                 - M.nr() == nr
147                 - m.nc() == nc
148                 - for all valid r and c:
149                   M(r,c) == ptr[r*nc + c]
150                   (i.e. the pointer is interpreted as a matrix laid out in memory
151                   in row major order)
152             - Note that the returned matrix doesn't take "ownership" of
153               the pointer and thus will not delete or free it.
154     !*/
155 
156 // ----------------------------------------------------------------------------------------
157 
158     template <
159         typename T
160         >
161     const matrix_exp mat (
162         const T* ptr,
163         long nr,
164         long nc,
165         long stride
166     );
167     /*!
168         requires
169             - nr >= 0
170             - nc >= 0
171             - stride > 0
172             - ptr == a pointer to at least (nr-1)*stride+nc T objects (or the NULL pointer if nr*nc==0)
173         ensures
174             - returns a matrix M such that:
175                 - M.nr() == nr
176                 - m.nc() == nc
177                 - for all valid r and c:
178                   M(r,c) == ptr[r*stride + c]
179                   (i.e. the pointer is interpreted as a matrix laid out in memory
180                   in row major order, with a row stride of the given stride amount.)
181             - Note that the returned matrix doesn't take "ownership" of
182               the pointer and thus will not delete or free it.
183     !*/
184 
185 // ----------------------------------------------------------------------------------------
186 
187     template <
188         typename T
189         >
190     const matrix_exp mat (
191         const ::arma::Mat<T>& m
192     );
193     /*!
194         ensures
195             - Converts a matrix from the Armadillo library into a dlib matrix.
196             - returns a matrix R such that:
197                 - R.nr() == m.n_rows
198                 - R.nc() == m.n_cols
199                 - for all valid r:
200                   R(r,c) == m(r,c)
201     !*/
202 
203 // ----------------------------------------------------------------------------------------
204 
205     template <
206         typename _Scalar,
207         int _Rows,
208         int _Cols,
209         int _Options,
210         int _MaxRows,
211         int _MaxCols
212         >
213     const matrix_exp mat (
214         const ::Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>& m
215     );
216     /*!
217         ensures
218             - Converts a matrix from the Eigen library into a dlib matrix.
219             - returns a matrix R such that:
220                 - R.nr() == m.rows()
221                 - R.nc() == m.cols()
222                 - for all valid r:
223                   R(r,c) == m(r,c)
224     !*/
225 
226 // ----------------------------------------------------------------------------------------
227 
228     matrix<double,1,1>      mat (double value);
229     matrix<float,1,1>       mat (float value);
230     matrix<long double,1,1> mat (long double value);
231     /*!
232         ensures
233             - Converts a scalar into a matrix containing just that scalar and returns the
234               results.
235     !*/
236 
237 // ----------------------------------------------------------------------------------------
238 
239 }
240 
241 #endif // DLIB_MATRIx_MAT_ABSTRACT_Hh_
242 
243 
244