"Fossies" - the Fresh Open Source Software Archive 
Member "armadillo-9.800.3/include/armadillo_bits/op_nonzeros_meat.hpp" (16 Jun 2016, 2925 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "op_nonzeros_meat.hpp" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
9.600.6_vs_9.700.2.
1 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
2 // Copyright 2008-2016 National ICT Australia (NICTA)
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ------------------------------------------------------------------------
15
16
17
18 //! \addtogroup op_nonzeros
19 //! @{
20
21
22
23 template<typename T1>
24 inline
25 void
26 op_nonzeros::apply_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
27 {
28 arma_extra_debug_sigprint();
29
30 typedef typename T1::elem_type eT;
31
32 const uword N_max = P.get_n_elem();
33
34 Mat<eT> tmp(N_max, 1);
35
36 eT* tmp_mem = tmp.memptr();
37
38 uword N_nz = 0;
39
40 if(Proxy<T1>::use_at == false)
41 {
42 typename Proxy<T1>::ea_type Pea = P.get_ea();
43
44 for(uword i=0; i<N_max; ++i)
45 {
46 const eT val = Pea[i];
47
48 if(val != eT(0)) { tmp_mem[N_nz] = val; ++N_nz; }
49 }
50 }
51 else
52 {
53 const uword n_rows = P.get_n_rows();
54 const uword n_cols = P.get_n_cols();
55
56 for(uword col=0; col < n_cols; ++col)
57 for(uword row=0; row < n_rows; ++row)
58 {
59 const eT val = P.at(row,col);
60
61 if(val != eT(0)) { tmp_mem[N_nz] = val; ++N_nz; }
62 }
63 }
64
65 out.steal_mem_col(tmp, N_nz);
66 }
67
68
69
70 template<typename T1>
71 inline
72 void
73 op_nonzeros::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_nonzeros>& X)
74 {
75 arma_extra_debug_sigprint();
76
77 typedef typename T1::elem_type eT;
78
79 const Proxy<T1> P(X.m);
80
81 if(P.get_n_elem() == 0) { out.set_size(0,1); return; }
82
83 if(P.is_alias(out))
84 {
85 Mat<eT> out2;
86
87 op_nonzeros::apply_noalias(out2, P);
88
89 out.steal_mem(out2);
90 }
91 else
92 {
93 op_nonzeros::apply_noalias(out, P);
94 }
95 }
96
97
98
99 template<typename T1>
100 inline
101 void
102 op_nonzeros_spmat::apply(Mat<typename T1::elem_type>& out, const SpToDOp<T1, op_nonzeros_spmat>& X)
103 {
104 arma_extra_debug_sigprint();
105
106 typedef typename T1::elem_type eT;
107
108 const SpProxy<T1> P(X.m);
109
110 const uword N = P.get_n_nonzero();
111
112 out.set_size(N,1);
113
114 if(N > 0)
115 {
116 if(is_SpMat<typename SpProxy<T1>::stored_type>::value)
117 {
118 const unwrap_spmat<typename SpProxy<T1>::stored_type> U(P.Q);
119
120 arrayops::copy(out.memptr(), U.M.values, N);
121 }
122 else
123 {
124 eT* out_mem = out.memptr();
125
126 typename SpProxy<T1>::const_iterator_type it = P.begin();
127
128 for(uword i=0; i<N; ++i) { out_mem[i] = (*it); ++it; }
129 }
130 }
131 }
132
133
134
135 //! @}