Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/op_diagmat_meat.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-2012 NICTA (www.nicta.com.au) | |
2 // Copyright (C) 2008-2012 Conrad Sanderson | |
3 // | |
4 // This Source Code Form is subject to the terms of the Mozilla Public | |
5 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
7 | |
8 | |
9 //! \addtogroup op_diagmat | |
10 //! @{ | |
11 | |
12 | |
13 | |
14 template<typename T1> | |
15 inline | |
16 void | |
17 op_diagmat::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_diagmat>& X) | |
18 { | |
19 arma_extra_debug_sigprint(); | |
20 | |
21 typedef typename T1::elem_type eT; | |
22 | |
23 const Proxy<T1> P(X.m); | |
24 | |
25 const uword n_rows = P.get_n_rows(); | |
26 const uword n_cols = P.get_n_cols(); | |
27 | |
28 const bool P_is_vec = (n_rows == 1) || (n_cols == 1); | |
29 | |
30 | |
31 if(P.is_alias(out) == false) | |
32 { | |
33 if(P_is_vec) // generate a diagonal matrix out of a vector | |
34 { | |
35 const uword N = (n_rows == 1) ? n_cols : n_rows; | |
36 | |
37 out.zeros(N, N); | |
38 | |
39 if(Proxy<T1>::prefer_at_accessor == false) | |
40 { | |
41 typename Proxy<T1>::ea_type P_ea = P.get_ea(); | |
42 | |
43 for(uword i=0; i < N; ++i) { out.at(i,i) = P_ea[i]; } | |
44 } | |
45 else | |
46 { | |
47 if(n_rows == 1) | |
48 { | |
49 for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(0,i); } | |
50 } | |
51 else | |
52 { | |
53 for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,0); } | |
54 } | |
55 } | |
56 } | |
57 else // generate a diagonal matrix out of a matrix | |
58 { | |
59 arma_debug_check( (n_rows != n_cols), "diagmat(): given matrix is not square" ); | |
60 | |
61 out.zeros(n_rows, n_rows); | |
62 | |
63 for(uword i=0; i < n_rows; ++i) { out.at(i,i) = P.at(i,i); } | |
64 } | |
65 } | |
66 else // we have aliasing | |
67 { | |
68 if(P_is_vec) // generate a diagonal matrix out of a vector | |
69 { | |
70 const uword N = (n_rows == 1) ? n_cols : n_rows; | |
71 | |
72 podarray<eT> tmp(N); | |
73 eT* tmp_mem = tmp.memptr(); | |
74 | |
75 if(Proxy<T1>::prefer_at_accessor == false) | |
76 { | |
77 typename Proxy<T1>::ea_type P_ea = P.get_ea(); | |
78 | |
79 for(uword i=0; i < N; ++i) { tmp_mem[i] = P_ea[i]; } | |
80 } | |
81 else | |
82 { | |
83 if(n_rows == 1) | |
84 { | |
85 for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(0,i); } | |
86 } | |
87 else | |
88 { | |
89 for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,0); } | |
90 } | |
91 } | |
92 | |
93 out.zeros(N, N); | |
94 | |
95 for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } | |
96 } | |
97 else // generate a diagonal matrix out of a matrix | |
98 { | |
99 arma_debug_check( (n_rows != n_cols), "diagmat(): given matrix is not square" ); | |
100 | |
101 if( (Proxy<T1>::has_subview == false) && (Proxy<T1>::fake_mat == false) ) | |
102 { | |
103 // NOTE: we have aliasing and it's not due to a subview, hence we're assuming that the output matrix already has the correct size | |
104 | |
105 for(uword i=0; i < n_rows; ++i) | |
106 { | |
107 const eT val = P.at(i,i); | |
108 | |
109 arrayops::inplace_set(out.colptr(i), eT(0), n_rows); | |
110 | |
111 out.at(i,i) = val; | |
112 } | |
113 } | |
114 else | |
115 { | |
116 podarray<eT> tmp(n_rows); | |
117 eT* tmp_mem = tmp.memptr(); | |
118 | |
119 for(uword i=0; i < n_rows; ++i) { tmp_mem[i] = P.at(i,i); } | |
120 | |
121 out.zeros(n_rows, n_rows); | |
122 | |
123 for(uword i=0; i < n_rows; ++i) { out.at(i,i) = tmp_mem[i]; } | |
124 } | |
125 } | |
126 } | |
127 } | |
128 | |
129 | |
130 | |
131 //! @} |