Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Преобразование матрицы в CSC формат
- /// </summary>
- /// <returns> матрица в формате CSC </returns>
- CSC_Matrix<T> toCSC()
- {
- vector <int> colptr(_M + 1);
- for (int i = 0; i < _NNZ; ++i)
- {
- int col = _cols[i];
- if (col != _M - 1) ++colptr[col + 2];
- }
- for (int i = 3; i <= _M; ++i)
- colptr[i] += colptr[i - 1];
- vector <T> values(_NNZ);
- vector <int> rows(_NNZ);
- for (int i = 0; i < _N; ++i)
- for (int j = _rowptr[i]; j < _rowptr[i + 1]; ++j)
- {
- int col = _cols[j];
- T value = _values[j];
- int pos = colptr[col + 1]++;
- rows[pos] = i;
- values[pos] = value;
- }
- CSC_Matrix<T> *res = new CSC_Matrix<T>(_N, _M, _NNZ, values, rows, colptr);
- return *res;
- }
Add Comment
Please, Sign In to add comment