55 , store_diagonal_first_in_row(false)
64 , store_diagonal_first_in_row(false)
69 "This constructor can only be called if the provided argument "
70 "is the sparsity pattern for an empty matrix. This constructor can "
71 "not be used to copy-construct a non-empty sparsity pattern."));
80 const unsigned int max_per_row)
82 , store_diagonal_first_in_row(m == n)
91 const std::vector<unsigned int> &row_lengths)
93 , store_diagonal_first_in_row(m == n)
101 const unsigned int max_per_row)
104 reinit(m, m, max_per_row);
110 const std::vector<unsigned int> &row_lengths)
113 reinit(m, m, row_lengths);
119 const unsigned int max_per_row,
141 const size_type *
const original_row_start =
145 const size_type *
const original_row_end =
151 const size_type *
const original_last_before_side_diagonals =
152 (row > extra_off_diagonals ?
155 row - extra_off_diagonals) :
158 const size_type *
const original_first_after_side_diagonals =
159 (row <
rows - extra_off_diagonals - 1 ?
160 std::upper_bound(original_row_start,
162 row + extra_off_diagonals) :
170 next_free_slot =
std::copy(original_row_start,
171 original_last_before_side_diagonals,
176 ++i, ++next_free_slot)
177 *next_free_slot = row - i;
179 ++i, ++next_free_slot)
180 *next_free_slot = row + i;
183 next_free_slot =
std::copy(original_first_after_side_diagonals,
203 "This operator can only be called if the provided argument "
204 "is the sparsity pattern for an empty matrix. This operator can "
205 "not be used to copy a non-empty sparsity pattern."));
208 ExcMessage(
"This operator can only be called if the current object is "
219 const unsigned int max_per_row)
222 const std::vector<unsigned int> row_lengths(m, max_per_row);
223 reinit(m, n, row_lengths);
239 if ((m == 0) || (n == 0))
264 std::size_t vec_len = 0;
282 (row_lengths.
size() == 0 ?
285 *std::max_element(row_lengths.
begin(), row_lengths.
end())),
355 const std::size_t nonzero_elements =
360 std::unique_ptr<size_type[]> new_colnums(
new size_type[nonzero_elements]);
390 new_colnums[next_free_entry++] = tmp_entries[j];
394 next_row_start = next_free_entry;
411 (std::find(&new_colnums[
rowstart[line] + 1],
412 &new_colnums[next_row_start],
414 &new_colnums[next_row_start]),
417 (std::adjacent_find(&new_colnums[
rowstart[line] + 1],
418 &new_colnums[next_row_start]) ==
419 &new_colnums[next_row_start]),
431 colnums = std::move(new_colnums);
448 const bool do_diag_optimize = (sp.
n_rows() == sp.
n_cols());
449 std::vector<unsigned int> row_lengths(sp.
n_rows());
453 if (do_diag_optimize && !sp.
exists(i, i))
466 end_row = sp.
end(row);
468 for (; col_num != end_row; ++col_num)
471 if ((col != row) || !do_diag_optimize)
492 const bool do_diag_optimize = (dsp.
n_rows() == dsp.
n_cols());
495 std::vector<unsigned int> row_lengths(dsp.
n_rows());
497 if (row_index_set.size() == 0)
502 if (do_diag_optimize && !dsp.
exists(i, i))
510 if (row_index_set.is_element(i))
513 if (do_diag_optimize && !dsp.
exists(i, i))
522 row_lengths[i] = do_diag_optimize ? 1 : 0;
533 for (
unsigned int index = 0; index <
row_length; ++index)
536 if ((col != row) || !do_diag_optimize)
549 template <
typename number>
556 const bool matrix_is_square = (
matrix.m() ==
matrix.n());
558 std::vector<unsigned int> entries_per_row(
matrix.m(), 0);
562 if (
matrix(row, col) != 0)
563 ++entries_per_row[row];
564 if (matrix_is_square && (
matrix(row, row) == 0))
565 ++entries_per_row[row];
575 std::vector<size_type> column_indices;
576 column_indices.reserve(
577 entries_per_row.size() > 0 ?
578 *std::max_element(entries_per_row.begin(), entries_per_row.end()) :
582 column_indices.resize(entries_per_row[row]);
586 if (
matrix(row, col) != 0)
588 column_indices[current_index] = col;
595 if (matrix_is_square && (col == row))
597 column_indices[current_index] = row;
605 add_entries(row, column_indices.begin(), column_indices.end(),
true);
616 const std::vector<unsigned int> &row_lengths)
692 Utilities::lower_bound<const size_type *>(sorted_region_start,
731 template <
typename ForwardIterator>
734 ForwardIterator
begin,
736 const bool indices_are_sorted)
738 if (indices_are_sorted ==
true)
742 ForwardIterator it =
begin;
743 bool has_larger_entries =
false;
751 has_larger_entries =
true;
754 if (has_larger_entries ==
false)
755 for (; it !=
end; ++it)
767 for (ForwardIterator p =
begin; p !=
end; ++p)
774 for (ForwardIterator it =
begin; it !=
end; ++it)
816 std::pair<SparsityPatternBase::size_type, SparsityPatternBase::size_type>
835 return std::make_pair(row, col);
887 out <<
']' << std::endl;
908 out <<
colnums[j] <<
" " << -
static_cast<signed int>(i) << std::endl;
916 unsigned int m = this->
n_rows();
917 unsigned int n = this->
n_cols();
919 <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 "
920 << n + 2 <<
" " << m + 2
922 "<style type=\"text/css\" >\n"
930 << n + 2 <<
"\" height=\"" << m + 2
931 <<
"\" fill=\"rgb(128, 128, 128)\"/>\n"
932 " <rect x=\"1\" y=\"1\" width=\""
933 << n + 0.1 <<
"\" height=\"" << m + 0.1
934 <<
"\" fill=\"rgb(255, 255, 255)\"/>\n\n";
937 for (; it !=
end; ++it)
939 out <<
" <rect class=\"pixel\" x=\"" << it->column() + 1 <<
"\" y=\""
940 << it->row() + 1 <<
"\" width=\".9\" height=\".9\"/>\n";
942 out <<
"</svg>" << std::endl;
957 std::abs(
static_cast<int>(i -
colnums[j]))) >
b)
958 b = std::abs(
static_cast<signed int>(i -
colnums[j]));
977 out.write(
reinterpret_cast<const char *
>(
rowstart.get()),
979 reinterpret_cast<const char *
>(
rowstart.get()));
981 out.write(
reinterpret_cast<const char *
>(
colnums.get()),
983 reinterpret_cast<const char *
>(
colnums.get()));
1014 in.read(
reinterpret_cast<char *
>(
rowstart.get()),
1016 reinterpret_cast<char *
>(
rowstart.get()));
1021 in.read(
reinterpret_cast<char *
>(
colnums.get()),
1023 reinterpret_cast<char *
>(
colnums.get()));
1054 SparsityPattern::add_entries<const SparsityPattern::size_type *>(
1059 # ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
1062 std::vector<SparsityPattern::size_type>::const_iterator>(
1064 std::vector<size_type>::const_iterator,
1065 std::vector<size_type>::const_iterator,
1069 SparsityPattern::add_entries<std::vector<SparsityPattern::size_type>::iterator>(
1071 std::vector<size_type>::iterator,
1072 std::vector<size_type>::iterator,