本文整理汇总了C++中typenameSpProxy::col方法的典型用法代码示例。如果您正苦于以下问题:C++ typenameSpProxy::col方法的具体用法?C++ typenameSpProxy::col怎么用?C++ typenameSpProxy::col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenameSpProxy
的用法示例。
在下文中一共展示了typenameSpProxy::col方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7:
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);
}
}
示例8: 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;
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
示例12: 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;
}
示例13: 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);
}
}
示例14: 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;
}
}
示例15: 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;
}
}