本文整理汇总了C++中typenameSpProxy类的典型用法代码示例。如果您正苦于以下问题:C++ typenameSpProxy类的具体用法?C++ typenameSpProxy怎么用?C++ typenameSpProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了typenameSpProxy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pa
inline
arma_warn_unused
typename
enable_if2
<(is_arma_type<T1>::value) && (is_arma_sparse_type<T2>::value) && (is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
typename T1::elem_type
>::result
dot
(
const Base<typename T1::elem_type, T1>& x,
const SpBase<typename T2::elem_type, T2>& y
)
{
arma_extra_debug_sigprint();
const Proxy<T1> pa(x.get_ref());
const SpProxy<T2> pb(y.get_ref());
arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()");
typedef typename T1::elem_type eT;
eT result = eT(0);
typename SpProxy<T2>::const_iterator_type it = pb.begin();
// prefer_at_accessor won't save us operations
while(it.pos() < pb.get_n_nonzero())
{
result += (*it) * pa.at(it.row(), it.col());
++it;
}
return result;
}
开发者ID:ELEN4002-Lab-Project-2012,项目名称:ELEN4002-Lab-Project,代码行数:35,代码来源:fn_dot.hpp
示例2: result
inline
typename
enable_if2
<
(is_arma_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
Mat<typename T1::elem_type>
>::result
operator-
(
const T1& x,
const T2& y
)
{
arma_extra_debug_sigprint();
Mat<typename T1::elem_type> result(x);
const SpProxy<T2> pb(y.get_ref());
arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "subtraction" );
typename SpProxy<T2>::const_iterator_type it = pb.begin();
typename SpProxy<T2>::const_iterator_type it_end = pb.end();
while(it != it_end)
{
result.at(it.row(), it.col()) -= (*it);
++it;
}
return result;
}
开发者ID:Gyebro,项目名称:clion-projects,代码行数:32,代码来源:operator_minus.hpp
示例3:
inline
void
op_sp_plus::apply_inside_schur(SpMat<eT>& out, const T2& x, const SpToDOp<T3, op_sp_plus>& y)
{
arma_extra_debug_sigprint();
const SpProxy<T2> proxy2(x);
const SpProxy<T3> proxy3(y.m);
arma_debug_assert_same_size(proxy2.get_n_rows(), proxy2.get_n_cols(), proxy3.get_n_rows(), proxy3.get_n_cols(), "element-wise multiplication");
out.zeros(proxy2.get_n_rows(), proxy2.get_n_cols());
typename SpProxy<T2>::const_iterator_type it = proxy2.begin();
typename SpProxy<T2>::const_iterator_type it_end = proxy2.end();
const eT k = y.aux;
for(; it != it_end; ++it)
{
const uword it_row = it.row();
const uword it_col = it.col();
out.at(it_row, it_col) = (*it) * (proxy3.at(it_row, it_col) + k);
}
}
开发者ID:RcppCore,项目名称:RcppArmadillo,代码行数:26,代码来源:op_sp_plus_meat.hpp
示例4: P
arma_warn_unused
inline
Col<uword>
find(const SpBase<typename T1::elem_type,T1>& X, const uword k = 0)
{
arma_extra_debug_sigprint();
const SpProxy<T1> P(X.get_ref());
const uword n_rows = P.get_n_rows();
const uword n_nz = P.get_n_nonzero();
Mat<uword> tmp(n_nz,1);
uword* tmp_mem = tmp.memptr();
typename SpProxy<T1>::const_iterator_type it = P.begin();
for(uword i=0; i<n_nz; ++i)
{
const uword index = it.row() + it.col()*n_rows;
tmp_mem[i] = index;
++it;
}
Col<uword> out;
const uword count = (k == 0) ? uword(n_nz) : uword( (std::min)(n_nz, k) );
out.steal_mem_col(tmp, count);
return out;
}
开发者ID:RcppCore,项目名称:RcppArmadillo,代码行数:35,代码来源:fn_find.hpp
示例5: p
arma_hot
arma_warn_unused
inline
typename enable_if2<is_arma_sparse_type<T1>::value, typename T1::elem_type>::result
trace(const T1& x)
{
arma_extra_debug_sigprint();
const SpProxy<T1> p(x);
arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "trace(): matrix must be square sized" );
typedef typename T1::elem_type eT;
eT result = eT(0);
typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != it_end)
{
if(it.row() == it.col())
{
result += (*it);
}
++it;
}
return result;
}
开发者ID:DatawaveMarineScience,项目名称:OpenSEA,代码行数:31,代码来源:fn_trace.hpp
示例6: direct_dot_arma
inline
arma_warn_unused
typename
enable_if2
<(is_arma_sparse_type<T1>::value) && (is_arma_sparse_type<T2>::value) && (is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
typename T1::elem_type
>::result
dot
(
const SpBase<typename T1::elem_type, T1>& x,
const SpBase<typename T2::elem_type, T2>& y
)
{
arma_extra_debug_sigprint();
const SpProxy<T1> pa(x.get_ref());
const SpProxy<T2> pb(y.get_ref());
arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()");
typedef typename T1::elem_type eT;
if((&(x.get_ref()) == &(y.get_ref())) && (SpProxy<T1>::must_use_iterator == false))
{
// We can do it directly!
return op_dot::direct_dot_arma(pa.get_n_nonzero(), pa.get_values(), pa.get_values());
}
else
{
// Iterate over both objects and see when they are the same
eT result = eT(0);
typename SpProxy<T1>::const_iterator_type a_it = pa.begin();
typename SpProxy<T2>::const_iterator_type b_it = pb.begin();
while((a_it.pos() < pa.get_n_nonzero()) && (b_it.pos() < pb.get_n_nonzero()))
{
if(a_it == b_it)
{
result += (*a_it) * (*b_it);
++a_it;
++b_it;
}
else if((a_it.col() < b_it.col()) || ((a_it.col() == b_it.col()) && (a_it.row() < b_it.row())))
{
// a_it is "behind"
++a_it;
}
else
{
// b_it is "behind"
++b_it;
}
}
return result;
}
}
开发者ID:ELEN4002-Lab-Project-2012,项目名称:ELEN4002-Lab-Project,代码行数:59,代码来源:fn_dot.hpp
示例7: while
arma_hot
inline
uword
n_unique
(
const SpProxy<T1>& pa,
const SpProxy<T2>& pb,
const op_n_unique_type junk
)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typename SpProxy<T1>::const_iterator_type x_it = pa.begin();
typename SpProxy<T1>::const_iterator_type x_it_end = pa.end();
typename SpProxy<T2>::const_iterator_type y_it = pb.begin();
typename SpProxy<T2>::const_iterator_type y_it_end = pb.end();
uword total_n_nonzero = 0;
while( (x_it != x_it_end) || (y_it != y_it_end) )
{
if(x_it == y_it)
{
if(op_n_unique_type::eval((*x_it), (*y_it)) != typename T1::elem_type(0))
{
++total_n_nonzero;
}
++x_it;
++y_it;
}
else
{
if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end
{
if(op_n_unique_type::eval((*x_it), typename T1::elem_type(0)) != typename T1::elem_type(0))
{
++total_n_nonzero;
}
++x_it;
}
else // x is closer to the end
{
if(op_n_unique_type::eval(typename T1::elem_type(0), (*y_it)) != typename T1::elem_type(0))
{
++total_n_nonzero;
}
++y_it;
}
}
}
return total_n_nonzero;
}
开发者ID:Aeryltic,项目名称:labirynth,代码行数:58,代码来源:fn_n_unique.hpp
示例8: locs
arma_hot
inline
void
spop_htrans::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_htrans>& in, const typename arma_cx_only<typename T1::elem_type>::result* junk)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT;
typedef typename umat::elem_type ueT;
const SpProxy<T1> p(in.m);
const uword N = p.get_n_nonzero();
if(N == uword(0))
{
out.set_size(p.get_n_cols(), p.get_n_rows());
return;
}
umat locs(2, N);
Col<eT> vals(N);
eT* vals_ptr = vals.memptr();
typename SpProxy<T1>::const_iterator_type it = p.begin();
for(uword count = 0; count < N; ++count)
{
ueT* locs_ptr = locs.colptr(count);
locs_ptr[0] = it.col();
locs_ptr[1] = it.row();
vals_ptr[count] = std::conj(*it);
++it;
}
SpMat<eT> tmp(locs, vals, p.get_n_cols(), p.get_n_rows());
out.steal_mem(tmp);
}
开发者ID:Arritmic,项目名称:armadillo,代码行数:45,代码来源:spop_htrans_meat.hpp
示例9: locs
arma_hot
inline
void
spop_strans::apply_proxy(SpMat<typename T1::elem_type>& out, const T1& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename umat::elem_type ueT;
const SpProxy<T1> p(X);
const uword N = p.get_n_nonzero();
if(N == uword(0))
{
out.zeros(p.get_n_cols(), p.get_n_rows());
return;
}
umat locs(2, N);
Col<eT> vals(N);
eT* vals_ptr = vals.memptr();
typename SpProxy<T1>::const_iterator_type it = p.begin();
for(uword count = 0; count < N; ++count)
{
ueT* locs_ptr = locs.colptr(count);
locs_ptr[0] = it.col();
locs_ptr[1] = it.row();
vals_ptr[count] = (*it);
++it;
}
SpMat<eT> tmp(locs, vals, p.get_n_cols(), p.get_n_rows());
out.steal_mem(tmp);
}
开发者ID:EmanueleCannizzaro,项目名称:armadillo,代码行数:44,代码来源:spop_strans_meat.hpp
示例10: pa
inline
typename
enable_if2
<
(is_arma_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
Mat<typename T1::elem_type>
>::result
operator*
(
const T1& x,
const T2& y
)
{
arma_extra_debug_sigprint();
const Proxy<T1> pa(x);
const SpProxy<T2> pb(y);
arma_debug_assert_mul_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "matrix multiplication");
Mat<typename T1::elem_type> result(pa.get_n_rows(), pb.get_n_cols());
result.zeros();
if( (pa.get_n_elem() > 0) && (pb.get_n_nonzero() > 0) )
{
typename SpProxy<T2>::const_iterator_type y_col_it = pb.begin();
typename SpProxy<T2>::const_iterator_type y_col_it_end = pb.end();
const uword result_n_rows = result.n_rows;
while(y_col_it != y_col_it_end)
{
for(uword row = 0; row < result_n_rows; ++row)
{
result.at(row, y_col_it.col()) += pa.at(row, y_col_it.row()) * (*y_col_it);
}
++y_col_it;
}
}
return result;
}
开发者ID:dragly,项目名称:molecular-dynamics,代码行数:43,代码来源:operator_times.hpp
示例11: proxy
inline
void
op_sp_plus::apply(Mat<typename T1::elem_type>& out, const SpToDOp<T1,op_sp_plus>& in)
{
arma_extra_debug_sigprint();
// Note that T1 will be a sparse type, so we use SpProxy.
const SpProxy<T1> proxy(in.m);
out.set_size(proxy.get_n_rows(), proxy.get_n_cols());
out.fill(in.aux);
typename SpProxy<T1>::const_iterator_type it = proxy.begin();
typename SpProxy<T1>::const_iterator_type it_end = proxy.end();
for(; it != it_end; ++it)
{
out.at(it.row(), it.col()) += (*it);
}
}
开发者ID:RcppCore,项目名称:RcppArmadillo,代码行数:20,代码来源:op_sp_plus_meat.hpp
示例12: UB
inline
void
spglue_minus_mixed::sparse_minus_dense(Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type >::result>& out, const T1& X, const T2& Y)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check();
const quasi_unwrap<T2> UB(Y);
const Mat<eT2>& B = UB.M;
const uword B_n_elem = B.n_elem;
const eT2* B_mem = B.memptr();
out.set_size(B.n_rows, B.n_cols);
out_eT* out_mem = out.memptr();
for(uword i=0; i<B_n_elem; ++i)
{
out_mem[i] = out_eT(-B_mem[i]);
}
const SpProxy<T1> pa(X);
arma_debug_assert_same_size( pa.get_n_rows(), pa.get_n_cols(), out.n_rows, out.n_cols, "subtraction" );
typename SpProxy<T1>::const_iterator_type it = pa.begin();
typename SpProxy<T1>::const_iterator_type it_end = pa.end();
while(it != it_end)
{
out.at(it.row(), it.col()) += out_eT(*it);
++it;
}
}
开发者ID:RcppCore,项目名称:RcppArmadillo,代码行数:41,代码来源:spglue_minus_meat.hpp
示例13: UA
inline
void
spglue_minus_mixed::dense_minus_sparse(Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type >::result>& out, const T1& X, const T2& Y)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT1;
typedef typename T2::elem_type eT2;
typedef typename promote_type<eT1,eT2>::result out_eT;
promote_type<eT1,eT2>::check();
if(is_same_type<eT1,out_eT>::no)
{
out = conv_to< Mat<out_eT> >::from(X);
}
else
{
const quasi_unwrap<T1> UA(X);
const Mat<eT1>& A = UA.M;
out = reinterpret_cast< const Mat<out_eT>& >(A);
}
const SpProxy<T2> pb(Y);
arma_debug_assert_same_size( out.n_rows, out.n_cols, pb.get_n_rows(), pb.get_n_cols(), "subtraction" );
typename SpProxy<T2>::const_iterator_type it = pb.begin();
typename SpProxy<T2>::const_iterator_type it_end = pb.end();
while(it != it_end)
{
out.at(it.row(), it.col()) -= out_eT(*it);
++it;
}
}
开发者ID:RcppCore,项目名称:RcppArmadillo,代码行数:39,代码来源:spglue_minus_meat.hpp
示例14: pa
inline
typename
enable_if2
<
(is_arma_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
Mat<typename T1::elem_type>
>::result
operator/
(
const Base<typename T1::elem_type, T1>& x,
const SpBase<typename T2::elem_type, T2>& y
)
{
arma_extra_debug_sigprint();
const Proxy<T1> pa(x.get_ref());
const SpProxy<T2> pb(y.get_ref());
arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise division");
Mat<typename T1::elem_type> result(pa.get_n_rows(), pa.get_n_cols());
result.fill(Datum<typename T1::elem_type>::inf);
// Now divide each element
typename SpProxy<T2>::const_iterator_type it = pb.begin();
while(it.pos() < pb.get_n_nonzero())
{
if(Proxy<T1>::prefer_at_accessor == false)
{
const uword index = (it.col() * result.n_rows) + it.row();
result[index] = pa[index] / (*it);
}
else
{
result.at(it.row(), it.col()) = pa.at(it.row(), it.col()) / (*it);
}
++it;
}
return result;
}
开发者ID:ELEN4002-Lab-Project-2012,项目名称:ELEN4002-Lab-Project,代码行数:44,代码来源:operator_div.hpp
示例15: if
arma_hot
inline
typename T1::elem_type
dot_helper(const SpProxy<T1>& pa, const SpProxy<T2>& pb)
{
typedef typename T1::elem_type eT;
// Iterate over both objects and see when they are the same
eT result = eT(0);
typename SpProxy<T1>::const_iterator_type a_it = pa.begin();
typename SpProxy<T1>::const_iterator_type a_end = pa.end();
typename SpProxy<T2>::const_iterator_type b_it = pb.begin();
typename SpProxy<T2>::const_iterator_type b_end = pb.end();
while((a_it != a_end) && (b_it != b_end))
{
if(a_it == b_it)
{
result += (*a_it) * (*b_it);
++a_it;
++b_it;
}
else if((a_it.col() < b_it.col()) || ((a_it.col() == b_it.col()) && (a_it.row() < b_it.row())))
{
// a_it is "behind"
++a_it;
}
else
{
// b_it is "behind"
++b_it;
}
}
return result;
}
开发者ID:dragly,项目名称:molecular-dynamics,代码行数:39,代码来源:fn_dot.hpp
示例16: while
arma_hot
inline
void
spglue_plus::apply_noalias(SpMat<eT>& out, const SpProxy<T1>& pa, const SpProxy<T2>& pb)
{
arma_extra_debug_sigprint();
arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "addition");
if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) )
{
out.set_size(pa.get_n_rows(), pa.get_n_cols());
// Resize memory to correct size.
out.mem_resize(n_unique(pa, pb, op_n_unique_add()));
// Now iterate across both matrices.
typename SpProxy<T1>::const_iterator_type x_it = pa.begin();
typename SpProxy<T2>::const_iterator_type y_it = pb.begin();
typename SpProxy<T1>::const_iterator_type x_end = pa.end();
typename SpProxy<T2>::const_iterator_type y_end = pb.end();
uword cur_val = 0;
while( (x_it != x_end) || (y_it != y_end) )
{
if(x_it == y_it)
{
const eT val = (*x_it) + (*y_it);
if (val != eT(0))
{
access::rw(out.values[cur_val]) = val;
access::rw(out.row_indices[cur_val]) = x_it.row();
++access::rw(out.col_ptrs[x_it.col() + 1]);
++cur_val;
}
++x_it;
++y_it;
}
else
{
const uword x_it_row = x_it.row();
const uword x_it_col = x_it.col();
const uword y_it_row = y_it.row();
const uword y_it_col = y_it.col();
if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end
{
access::rw(out.values[cur_val]) = (*x_it);
access::rw(out.row_indices[cur_val]) = x_it_row;
++access::rw(out.col_ptrs[x_it_col + 1]);
++cur_val;
++x_it;
}
else
{
access::rw(out.values[cur_val]) = (*y_it);
access::rw(out.row_indices[cur_val]) = y_it_row;
++access::rw(out.col_ptrs[y_it_col + 1]);
++cur_val;
++y_it;
}
}
}
const uword out_n_cols = out.n_cols;
uword* col_ptrs = access::rwp(out.col_ptrs);
// Fix column pointers to be cumulative.
for(uword c = 1; c <= out_n_cols; ++c)
{
col_ptrs[c] += col_ptrs[c - 1];
}
}
else
{
if(pa.get_n_nonzero() == 0)
{
out = pb.Q;
return;
}
if(pb.get_n_nonzero() == 0)
{
out = pa.Q;
return;
}
}
}
开发者ID:dragly,项目名称:molecular-dynamics,代码行数:93,代码来源:spglue_plus_meat.hpp
示例17: p
arma_hot
inline
void
spop_sum::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_sum>& in)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const uword dim = in.aux_uword_a;
arma_debug_check( (dim > 1), "sum(): parameter 'dim' must be 0 or 1" );
const SpProxy<T1> p(in.m);
const uword p_n_rows = p.get_n_rows();
const uword p_n_cols = p.get_n_cols();
if(p.get_n_nonzero() == 0)
{
if(dim == 0) { out.zeros(1,p_n_cols); }
if(dim == 1) { out.zeros(p_n_rows,1); }
return;
}
if(dim == 0) // find the sum in each column
{
Row<eT> acc(p_n_cols, fill::zeros);
if(SpProxy<T1>::must_use_iterator)
{
typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != it_end) { acc[it.col()] += (*it); ++it; }
}
else
{
for(uword col = 0; col < p_n_cols; ++col)
{
acc[col] = arrayops::accumulate
(
&p.get_values()[p.get_col_ptrs()[col]],
p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col]
);
}
}
out = acc;
}
else
if(dim == 1) // find the sum in each row
{
Col<eT> acc(p_n_rows, fill::zeros);
typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != it_end) { acc[it.row()] += (*it); ++it; }
out = acc;
}
}
开发者ID:KaimingOuyang,项目名称:HPC-K-Means,代码行数:63,代码来源:spop_sum_meat.hpp
示例18: acc
inline
void
spop_mean::apply_noalias_fast
(
SpMat<typename T1::elem_type>& out,
const SpProxy<T1>& p,
const uword dim
)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
const uword p_n_rows = p.get_n_rows();
const uword p_n_cols = p.get_n_cols();
if( (p_n_rows == 0) || (p_n_cols == 0) || (p.get_n_nonzero() == 0) )
{
if(dim == 0) { out.zeros((p_n_rows > 0) ? 1 : 0, p_n_cols); }
if(dim == 1) { out.zeros(p_n_rows, (p_n_cols > 0) ? 1 : 0); }
return;
}
if(dim == 0) // find the mean in each column
{
Row<eT> acc(p_n_cols, fill::zeros);
if(SpProxy<T1>::must_use_iterator)
{
typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != it_end) { acc[it.col()] += (*it); ++it; }
acc /= T(p_n_rows);
}
else
{
for(uword col = 0; col < p_n_cols; ++col)
{
acc[col] = arrayops::accumulate
(
&p.get_values()[p.get_col_ptrs()[col]],
p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col]
) / T(p_n_rows);
}
}
out = acc;
}
else
if(dim == 1) // find the mean in each row
{
Col<eT> acc(p_n_rows, fill::zeros);
typename SpProxy<T1>::const_iterator_type it = p.begin();
typename SpProxy<T1>::const_iterator_type it_end = p.end();
while(it != it_end) { acc[it.row()] += (*it); ++it; }
acc /= T(p_n_cols);
out = acc;
}
if(out.is_finite() == false)
{
spop_mean::apply_noalias_slow(out, p, dim);
}
}
开发者ID:KaimingOuyang,项目名称:HPC-K-Means,代码行数:72,代码来源:spop_mean_meat.hpp
示例19: eT
inline
void
spop_mean::apply_noalias_slow
(
SpMat<typename T1::elem_type>& out,
const SpProxy<T1>& p,
const uword dim
)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const uword p_n_rows = p.get_n_rows();
const uword p_n_cols = p.get_n_cols();
if(dim == 0) // find the mean in each column
{
arma_extra_debug_print("spop_mean::apply_noalias(): dim = 0");
out.set_size((p_n_rows > 0) ? 1 : 0, p_n_cols);
if( (p_n_rows == 0) || (p.get_n_nonzero() == 0) ) { return; }
for(uword col = 0; col < p_n_cols; ++col)
{
// Do we have to use an iterator or can we use memory directly?
if(SpProxy<T1>::must_use_iterator)
{
typename SpProxy<T1>::const_iterator_type it = p.begin_col(col);
typename SpProxy<T1>::const_iterator_type end = p.begin_col(col + 1);
const uword n_zero = p_n_rows - (end.pos() - it.pos());
out.at(0,col) = spop_mean::iterator_mean(it, end, n_zero, eT(0));
}
else
{
out.at(0,col) = spop_mean::direct_mean
(
&p.get_values()[p.get_col_ptrs()[col]],
p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col],
p_n_rows
);
}
}
}
else
if(dim == 1) // find the mean in each row
{
arma_extra_debug_print("spop_mean::apply_noalias(): dim = 1");
out.set_size(p_n_rows, (p_n_cols > 0) ? 1 : 0);
if( (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { return; }
for(uword row = 0; row < p_n_rows; ++row)
{
// We must use an iterator regardless of how it is stored.
typename SpProxy<T1>::const_row_iterator_type it = p.begin_row(row);
typename SpProxy<T1>::const_row_iterator_type end = p.end_row(row);
const uword n_zero = p_n_cols - (end.pos() - it.pos());
out.at(row,0) = spop_mean::iterator_mean(it, end, n_zero, eT(0));
}
}
}
开发者ID:KaimingOuyang,项目名称:HPC-K-Means,代码行数:68,代码来源:spop_mean_meat.hpp
示例20: pa
inline
typename
enable_if2
<
(is_arma_sparse_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
SpMat<typename T1::elem_type>
>::result
operator%
(
const SpBase<typename T1::elem_type, T1>& x,
const SpBase<typename T2::elem_type, T2>& y
)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const SpProxy<T1> pa(x.get_ref());
const SpProxy<T2> pb(y.get_ref());
arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise multiplication");
SpMat<typename T1::elem_type> result(pa.get_n_rows(), pa.get_n_cols());
if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) )
{
// Resize memory to correct size.
result.mem_resize(n_unique(x, y, op_n_unique_mul()));
// Now iterate across both matrices.
typename SpProxy<T1>::const_iterator_type x_it = pa.begin();
typename SpProxy<T2>::const_iterator_type y_it = pb.begin();
typename SpProxy<T1>::const_iterator_type x_end = pa.end();
typename SpProxy<T2>::const_iterator_type y_end = pb.end();
uword cur_val = 0;
while((x_it != x_end) || (y_it != y_end))
{
if(x_it == y_it)
{
const eT val = (*x_it) * (*y_it);
if (val != eT(0))
{
access::rw(result.values[cur_val]) = val;
access::rw(result.row_indices[cur_val]) = x_it.row();
++access::rw(result.col_ptrs[x_it.col() + 1]);
++cur_val;
}
++x_it;
++y_it;
}
else
{
const uword x_it_row = x_it.row();
const uword x_it_col = x_it.col();
const uword y_it_row = y_it.row();
const uword y_it_col = y_it.col();
if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end
{
++x_it;
}
else
{
++y_it;
}
}
}
// Fix column pointers to be cumulative.
for(uword c = 1; c <= result.n_cols; ++c)
{
access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1];
}
}
return result;
}
开发者ID:PsycoTodd,项目名称:Armadillo_OpenCV_XCode_Framework,代码行数:82,代码来源:operator_schur.hpp
注:本文中的typenameSpProxy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论