Esempio n. 1
0
  void
  convert_matrix(const arma::Mat<Tfrom>& densemat,
                 csc_matrix<Tto, Idxto>& cscmat) {
    Idxto m = densemat.num_rows();
    Idxto n = densemat.num_cols();
    arma::Col<Idxto> new_col_offsets(n + 1, 0);
    arma::Col<Idxto> new_row_indices;
    arma::Col<Tto> new_values;

    // Compute column sizes, and fill vectors of row indices and values.
    for (Idxto j(0); j < n; ++j) {
      for (Idxto i(0); i < m; ++i) {
        if (densemat(i,j) != 0) {
          ++new_col_offsets[j];
          new_row_indices.push_back(i);
          new_values.push_back(densemat(i,j));
        }
      }
    }

    // Compute offsets.
    for (Idxto i(0); i < n; ++i)
      new_col_offsets[i+1] += new_col_offsets[i];
    for (Idxto i(n); i > 0; --i)
      new_col_offsets[i] = new_col_offsets[i-1];
    new_col_offsets[0] = 0;

    // Copy data over
    cscmat.reset_nocopy(m, n, new_col_offsets, new_row_indices, new_values);
  }
Esempio n. 2
0
 explicit csc_matrix(const arma::Mat<OtherT>& other)
   : base(other.num_rows(), other.num_cols()) {
   convert_matrix(other, *this);
 }