模板化(犰狳)类的模板化函数

时间:2017-07-26 18:46:31

标签: c++ templates armadillo

以下函数应该提取行索引, 列索引和类型稀疏矩阵的非零 吨。

template<typename T>
tuple<uvec,uvec,Col<T>> find(SpMat<T> A)
{
    SpMat<T>::const_iterator start = A.begin();
    SpMat<T>::const_iterator end   = A.end();

    auto n = std::distance(start,end);
    uvec row_ind(n);
    uvec col_ind(n);
    Col<T> nz_vals(n);

    int i = 0;
    for(SpMat<T>::const_iterator it = start; it != end; ++it)
    {
        row_ind[i] = it.row();
        col_ind[i] = it.col();
        nz_vals[i] = (*it);
       i++;
    }
    return make_tuple(row_ind, col_ind, nz_vals);
}

不幸的是它不起作用。另一方面,如果我用double替换typeparameter,它就会起作用

typedef double T;
tuple<uvec,uvec,Col<T>> find(SpMat<T> A)
{
    SpMat<T>::const_iterator start = A.begin();
    SpMat<T>::const_iterator end   = A.end();

    auto n = std::distance(start,end);
    uvec row_ind(n);
    uvec col_ind(n);
    Col<T> nz_vals(n);

    int i = 0;
    for(SpMat<T>::const_iterator it = start; it != end; ++it)
    {
        row_ind[i] = it.row();
        col_ind[i] = it.col();
        nz_vals[i] = (*it);
       i++;
    }
    return make_tuple(row_ind, col_ind, nz_vals);
}

任何人都可以解释这种行为吗?

0 个答案:

没有答案