comparison armadillo-2.4.4/include/armadillo_bits/fn_var.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) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup fn_var
15 //! @{
16
17
18
19 template<typename T1>
20 inline
21 const mtOp<typename T1::pod_type, T1, op_var>
22 var(const Base<typename T1::elem_type,T1>& X, const uword norm_type = 0, const uword dim = 0)
23 {
24 arma_extra_debug_sigprint();
25
26 return mtOp<typename T1::pod_type, T1, op_var>(X.get_ref(), norm_type, dim);
27 }
28
29
30
31 //! Immediate 'find the variance of a row vector' operation
32 template<typename eT>
33 inline
34 arma_warn_unused
35 typename get_pod_type<eT>::result
36 var(const Row<eT>& A, const uword norm_type = 0)
37 {
38 arma_extra_debug_sigprint();
39
40 const uword A_n_elem = A.n_elem;
41
42 arma_debug_check( (A_n_elem == 0), "var(): given object has no elements" );
43
44 return op_var::direct_var(A.mem, A_n_elem, norm_type);
45 }
46
47
48
49 //! Immediate 'find the variance of a column vector' operation
50 template<typename eT>
51 inline
52 arma_warn_unused
53 typename get_pod_type<eT>::result
54 var(const Col<eT>& A, const uword norm_type = 0)
55 {
56 arma_extra_debug_sigprint();
57
58 const uword A_n_elem = A.n_elem;
59
60 arma_debug_check( (A_n_elem == 0), "var(): given object has no elements" );
61
62 return op_var::direct_var(A.mem, A_n_elem, norm_type);
63 }
64
65
66
67 template<typename eT>
68 inline
69 arma_warn_unused
70 typename get_pod_type<eT>::result
71 var(const subview_row<eT>& A, const uword norm_type = 0)
72 {
73 arma_extra_debug_sigprint();
74
75 arma_debug_check( (A.n_elem == 0), "var(): given object has no elements" );
76
77 return op_var::direct_var(A, norm_type);
78 }
79
80
81
82 template<typename eT>
83 inline
84 arma_warn_unused
85 typename get_pod_type<eT>::result
86 var(const subview_col<eT>& A, const uword norm_type = 0)
87 {
88 arma_extra_debug_sigprint();
89
90 arma_debug_check( (A.n_elem == 0), "var(): given object has no elements" );
91
92 return op_var::direct_var(A.colptr(0), A.n_rows, norm_type);
93 }
94
95
96
97 template<typename eT>
98 inline
99 arma_warn_unused
100 typename get_pod_type<eT>::result
101 var(const diagview<eT>& A, const uword norm_type = 0)
102 {
103 arma_extra_debug_sigprint();
104
105 arma_debug_check( (A.n_elem == 0), "var(): given object has no elements" );
106
107 return op_var::direct_var(A, norm_type);
108 }
109
110
111
112 template<typename eT, typename T1>
113 inline
114 arma_warn_unused
115 typename get_pod_type<eT>::result
116 var(const subview_elem1<eT,T1>& A, const uword norm_type = 0)
117 {
118 arma_extra_debug_sigprint();
119
120 const Col<eT> X(A);
121
122 return var(X, norm_type);
123 }
124
125
126
127 //! @}