-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathop_omit_meat.hpp
More file actions
230 lines (162 loc) · 5.71 KB
/
op_omit_meat.hpp
File metadata and controls
230 lines (162 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// SPDX-License-Identifier: Apache-2.0
//
// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
// Copyright 2008-2016 National ICT Australia (NICTA)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
//! \addtogroup op_omit
//! @{
template<typename T1>
inline
void
op_omit::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_omit>& in)
{
arma_debug_sigprint();
typedef typename T1::elem_type eT;
const uword omit_mode = in.aux_uword_a;
if(arma_config::fast_math_warn)
{
if(omit_mode == 1) { arma_warn(1, "omit_nan(): detection of NaN is not reliable in fast math mode"); }
if(omit_mode == 2) { arma_warn(1, "omit_nonfinite(): detection of non-finite values is not reliable in fast math mode"); }
}
auto is_omitted_1 = [](const eT& x) -> bool { return arma_isnan(x); };
auto is_omitted_2 = [](const eT& x) -> bool { return arma_isnonfinite(x); };
if(omit_mode == 1) { op_omit::apply(out, in.m, is_omitted_1); }
if(omit_mode == 2) { op_omit::apply(out, in.m, is_omitted_2); }
}
template<typename T1, typename functor>
inline
void
op_omit::apply(Mat<typename T1::elem_type>& out, const T1& X, functor is_omitted)
{
arma_debug_sigprint();
typedef typename T1::elem_type eT;
if(is_Mat<T1>::value || is_subview_col<T1>::value || is_Mat<typename Proxy<T1>::stored_type>::value || (arma_config::openmp && Proxy<T1>::use_mp))
{
const quasi_unwrap<T1> U(X);
const eT* X_mem = U.M.memptr();
const uword N = U.M.n_elem;
Mat<eT> Y(N, 1, arma_nozeros_indicator());
eT* Y_mem = Y.memptr();
uword count = 0;
for(uword i=0; i < N; ++i)
{
const eT val = X_mem[i];
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
out.steal_mem_col(Y, count);
}
else
{
const Proxy<T1> P(X);
const uword N = P.get_n_elem();
Mat<eT> Y(N, 1, arma_nozeros_indicator());
eT* Y_mem = Y.memptr();
uword count = 0;
if(Proxy<T1>::use_at == false)
{
const typename Proxy<T1>::ea_type Pea = P.get_ea();
for(uword i=0; i < N; ++i)
{
const eT val = Pea[i];
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
}
else
{
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
for(uword c=0; c < n_cols; ++c)
for(uword r=0; r < n_rows; ++r)
{
const eT val = P.at(r,c);
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
}
out.steal_mem_col(Y, count);
}
}
//
template<typename T1>
inline
void
op_omit_cube::apply(Mat<typename T1::elem_type>& out, const CubeToMatOp<T1, op_omit_cube>& in)
{
arma_debug_sigprint();
typedef typename T1::elem_type eT;
const uword omit_mode = in.aux_uword;
if(arma_config::fast_math_warn)
{
if(omit_mode == 1) { arma_warn(1, "omit_nan(): detection of NaN is not reliable in fast math mode"); }
if(omit_mode == 2) { arma_warn(1, "omit_nonfinite(): detection of non-finite values is not reliable in fast math mode"); }
}
auto is_omitted_1 = [](const eT& x) -> bool { return arma_isnan(x); };
auto is_omitted_2 = [](const eT& x) -> bool { return arma_isnonfinite(x); };
if(omit_mode == 1) { op_omit_cube::apply(out, in.m, is_omitted_1); }
if(omit_mode == 2) { op_omit_cube::apply(out, in.m, is_omitted_2); }
}
template<typename T1, typename functor>
inline
void
op_omit_cube::apply(Mat<typename T1::elem_type>& out, const T1& X, functor is_omitted)
{
arma_debug_sigprint();
typedef typename T1::elem_type eT;
if(is_Cube<T1>::value || is_Cube<typename ProxyCube<T1>::stored_type>::value || (arma_config::openmp && ProxyCube<T1>::use_mp))
{
const unwrap_cube<T1> U(X);
const eT* X_mem = U.M.memptr();
const uword N = U.M.n_elem;
Mat<eT> Y(N, 1, arma_nozeros_indicator());
eT* Y_mem = Y.memptr();
uword count = 0;
for(uword i=0; i < N; ++i)
{
const eT val = X_mem[i];
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
out.steal_mem_col(Y, count);
}
else
{
const ProxyCube<T1> P(X);
const uword N = P.get_n_elem();
Mat<eT> Y(N, 1, arma_nozeros_indicator());
eT* Y_mem = Y.memptr();
uword count = 0;
if(ProxyCube<T1>::use_at == false)
{
const typename ProxyCube<T1>::ea_type Pea = P.get_ea();
for(uword i=0; i < N; ++i)
{
const eT val = Pea[i];
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
}
else
{
const uword n_r = P.get_n_rows();
const uword n_c = P.get_n_cols();
const uword n_s = P.get_n_slices();
for(uword s=0; s < n_s; ++s)
for(uword c=0; c < n_c; ++c)
for(uword r=0; r < n_r; ++r)
{
const eT val = P.at(r,c,s);
if(is_omitted(val) == false) { Y_mem[count] = val; ++count; }
}
}
out.steal_mem_col(Y, count);
}
}
//! @}