directly avoid Proxy if possible
This commit is contained in:
@@ -68,9 +68,11 @@ class op_any
|
||||
static inline bool any_vec(T1& X);
|
||||
|
||||
|
||||
template<typename T1>
|
||||
static inline void apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim);
|
||||
template<typename eT>
|
||||
static inline void apply_mat_noalias(Mat<uword>& out, const Mat<eT>& X, const uword dim);
|
||||
|
||||
template<typename T1>
|
||||
static inline void apply_proxy_noalias(Mat<uword>& out, const Proxy<T1>& P, const uword dim);
|
||||
|
||||
template<typename T1>
|
||||
static inline void apply(Mat<uword>& out, const mtOp<uword, T1, op_any>& X);
|
||||
|
||||
@@ -269,17 +269,15 @@ op_any::any_vec(T1& X)
|
||||
|
||||
|
||||
|
||||
template<typename T1>
|
||||
template<typename eT>
|
||||
inline
|
||||
void
|
||||
op_any::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim)
|
||||
op_any::apply_mat_noalias(Mat<uword>& out, const Mat<eT>& X, const uword dim)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
const uword n_rows = P.get_n_rows();
|
||||
const uword n_cols = P.get_n_cols();
|
||||
|
||||
typedef typename Proxy<T1>::elem_type eT;
|
||||
const uword n_rows = X.n_rows;
|
||||
const uword n_cols = X.n_cols;
|
||||
|
||||
if(dim == 0) // traverse rows (ie. process each column)
|
||||
{
|
||||
@@ -287,28 +285,13 @@ op_any::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim)
|
||||
|
||||
uword* out_mem = out.memptr();
|
||||
|
||||
if(is_Mat<typename Proxy<T1>::stored_type>::value)
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
|
||||
const eT* colmem = X.colptr(col);
|
||||
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
const eT* colmem = U.M.colptr(col);
|
||||
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
if(colmem[row] != eT(0)) { out_mem[col] = uword(1); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
if(P.at(row,col) != eT(0)) { out_mem[col] = uword(1); break; }
|
||||
}
|
||||
if(colmem[row] != eT(0)) { out_mem[col] = uword(1); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,28 +301,57 @@ op_any::apply_helper(Mat<uword>& out, const Proxy<T1>& P, const uword dim)
|
||||
|
||||
uword* out_mem = out.memptr();
|
||||
|
||||
if(is_Mat<typename Proxy<T1>::stored_type>::value)
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
const unwrap<typename Proxy<T1>::stored_type> U(P.Q);
|
||||
const eT* colmem = X.colptr(col);
|
||||
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
const eT* colmem = U.M.colptr(col);
|
||||
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
if(colmem[row] != eT(0)) { out_mem[row] = uword(1); }
|
||||
}
|
||||
if(colmem[row] != eT(0)) { out_mem[row] = uword(1); }
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T1>
|
||||
inline
|
||||
void
|
||||
op_any::apply_proxy_noalias(Mat<uword>& out, const Proxy<T1>& P, const uword dim)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
typedef typename Proxy<T1>::elem_type eT;
|
||||
|
||||
const uword n_rows = P.get_n_rows();
|
||||
const uword n_cols = P.get_n_cols();
|
||||
|
||||
if(dim == 0) // traverse rows (ie. process each column)
|
||||
{
|
||||
out.zeros(1, n_cols);
|
||||
|
||||
uword* out_mem = out.memptr();
|
||||
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
if(P.at(row,col) != eT(0)) { out_mem[row] = uword(1); }
|
||||
}
|
||||
if(P.at(row,col) != eT(0)) { out_mem[col] = uword(1); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out.zeros(n_rows, 1);
|
||||
|
||||
uword* out_mem = out.memptr();
|
||||
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
if(P.at(row,col) != eT(0)) { out_mem[row] = uword(1); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -356,19 +368,39 @@ op_any::apply(Mat<uword>& out, const mtOp<uword, T1, op_any>& X)
|
||||
|
||||
const uword dim = X.aux_uword_a;
|
||||
|
||||
const Proxy<T1> P(X.m);
|
||||
|
||||
if(P.is_alias(out) == false)
|
||||
if( (is_Mat<T1>::value) || (is_Mat<typename Proxy<T1>::stored_type>::value) || (arma_config::openmp && Proxy<T1>::use_mp) )
|
||||
{
|
||||
op_any::apply_helper(out, P, dim);
|
||||
const quasi_unwrap<T1> U(X.m);
|
||||
|
||||
if(U.is_alias(out) == false)
|
||||
{
|
||||
op_any::apply_mat_noalias(out, U.M, dim);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat<uword> tmp;
|
||||
|
||||
op_any::apply_mat_noalias(tmp, U.M, dim);
|
||||
|
||||
out.steal_mem(tmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat<uword> out2;
|
||||
const Proxy<T1> P(X.m);
|
||||
|
||||
op_any::apply_helper(out2, P, dim);
|
||||
|
||||
out.steal_mem(out2);
|
||||
if(P.is_alias(out) == false)
|
||||
{
|
||||
op_any::apply_proxy_noalias(out, P, dim);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat<uword> tmp;
|
||||
|
||||
op_any::apply_proxy_noalias(tmp, P, dim);
|
||||
|
||||
out.steal_mem(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user