This patch changes SparsityPattern and classes that use it.
std::cref(*cols),
std::placeholders::_1, std::placeholders::_2,
val.get(),
- cols->sparsity_pattern.rowstart,
- cols->sparsity_pattern.colnums,
+ cols->sparsity_pattern.rowstart.get(),
+ cols->sparsity_pattern.colnums.get(),
std::cref(src),
std::ref(dst)),
internal::SparseMatrix::minimum_parallel_grain_size/cols->chunk_size+1);
// like in vmult_add, but don't keep an iterator into dst around since we're
// not traversing it sequentially this time
const number *val_ptr = val.get();
- const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
+ const size_type *colnum_ptr = cols->sparsity_pattern.colnums.get();
for (size_type chunk_row=0; chunk_row<n_regular_chunk_rows; ++chunk_row)
{
n_chunk_rows);
const number *val_ptr = val.get();
- const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
+ const size_type *colnum_ptr = cols->sparsity_pattern.colnums.get();
typename Vector<somenumber>::const_iterator v_ptr = v.begin();
for (size_type chunk_row=0; chunk_row<n_regular_chunk_rows; ++chunk_row)
n_chunk_rows);
const number *val_ptr = val.get();
- const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
+ const size_type *colnum_ptr = cols->sparsity_pattern.colnums.get();
typename Vector<somenumber>::const_iterator u_ptr = u.begin();
for (size_type chunk_row=0; chunk_row<n_regular_chunk_rows; ++chunk_row)
n_chunk_rows);
const number *val_ptr = val.get();
- const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
+ const size_type *colnum_ptr = cols->sparsity_pattern.colnums.get();
typename Vector<somenumber>::iterator dst_ptr = dst.begin();
for (size_type chunk_row=0; chunk_row<n_regular_chunk_rows; ++chunk_row)
SparseLUDecomposition<number>::prebuild_lower_bound()
{
const size_type *const
- column_numbers = this->get_sparsity_pattern().colnums;
+ column_numbers = this->get_sparsity_pattern().colnums.get();
const std::size_t *const
- rowstart_indices = this->get_sparsity_pattern().rowstart;
+ rowstart_indices = this->get_sparsity_pattern().rowstart.get();
const size_type N = this->m();
prebuilt_lower_bound.resize (N);
// translating in essence the algorithm given at the end of section 10.3.2,
// using the names of variables used there
const SparsityPattern &sparsity = this->get_sparsity_pattern();
- const std::size_t *const ia = sparsity.rowstart;
- const size_type *const ja = sparsity.colnums;
+ const std::size_t *const ia = sparsity.rowstart.get();
+ const size_type *const ja = sparsity.colnums.get();
number *luval = this->SparseMatrix<number>::val.get();
const size_type N=dst.size();
const std::size_t *const rowstart_indices
- = this->get_sparsity_pattern().rowstart;
+ = this->get_sparsity_pattern().rowstart.get();
const size_type *const column_numbers
- = this->get_sparsity_pattern().colnums;
+ = this->get_sparsity_pattern().colnums.get();
// solve LUx=b in two steps:
// first Ly = b, then
const size_type N=dst.size();
const std::size_t *const rowstart_indices
- = this->get_sparsity_pattern().rowstart;
+ = this->get_sparsity_pattern().rowstart.get();
const size_type *const column_numbers
- = this->get_sparsity_pattern().colnums;
+ = this->get_sparsity_pattern().colnums.get();
// solve (LU)'x=b in two steps:
// first U'y = b, then
// unsorted case: first, search all the
// indices to find out which values we
// actually need to add.
- const size_type *const my_cols = cols->colnums;
+ const size_type *const my_cols = cols->colnums.get();
size_type index = cols->rowstart[row];
const size_type next_row_index = cols->rowstart[row+1];
// First, search all the indices to find
// out which values we actually need to
// set.
- const size_type *my_cols = cols->colnums;
+ const size_type *my_cols = cols->colnums.get();
std::size_t index = cols->rowstart[row], next_index = index;
const std::size_t next_row_index = cols->rowstart[row+1];
<number,InVector,OutVector>,
std::placeholders::_1, std::placeholders::_2,
val.get(),
- cols->rowstart,
- cols->colnums,
+ cols->rowstart.get(),
+ cols->colnums.get(),
std::cref(src),
std::ref(dst),
false),
<number,InVector,OutVector>,
std::placeholders::_1, std::placeholders::_2,
val.get(),
- cols->rowstart,
- cols->colnums,
+ cols->rowstart.get(),
+ cols->colnums.get(),
std::cref(src),
std::ref(dst),
true),
(std::bind (&internal::SparseMatrix::matrix_norm_sqr_on_subrange
<number,Vector<somenumber> >,
std::placeholders::_1, std::placeholders::_2,
- val.get(), cols->rowstart, cols->colnums,
+ val.get(),
+ cols->rowstart.get(),
+ cols->colnums.get(),
std::cref(v)),
0, m(),
internal::SparseMatrix::minimum_parallel_grain_size);
(std::bind (&internal::SparseMatrix::matrix_scalar_product_on_subrange
<number,Vector<somenumber> >,
std::placeholders::_1, std::placeholders::_2,
- val.get(), cols->rowstart, cols->colnums,
+ val.get(),
+ cols->rowstart.get(),
+ cols->colnums.get(),
std::cref(u),
std::cref(v)),
0, m(),
(std::bind (&internal::SparseMatrix::residual_sqr_on_subrange
<number,Vector<somenumber>,Vector<somenumber> >,
std::placeholders::_1, std::placeholders::_2,
- val.get(), cols->rowstart, cols->colnums,
+ val.get(),
+ cols->rowstart.get(),
+ cols->colnums.get(),
std::cref(u),
std::cref(b),
std::ref(dst)),
#endif
#include <boost/serialization/split_member.hpp>
+#include <memory>
#include <vector>
#include <iostream>
#include <algorithm>
* compressed after this function finishes.
*/
SparsityPattern (const SparsityPattern &original,
- const unsigned int max_per_row,
- const size_type extra_off_diagonals);
+ const unsigned int max_per_row,
+ const size_type extra_off_diagonals);
/**
* Destructor.
*/
- ~SparsityPattern ();
+ ~SparsityPattern () = default;
/**
* Copy operator. For this the same holds as for the copy constructor: it is
* region that is used. The actual number of elements that was allocated is
* stored in #max_dim.
*/
- std::size_t *rowstart;
+ std::unique_ptr<std::size_t[]> rowstart;
/**
* Array of column numbers. In this array, we store for each non-zero
* sorted, such that finding whether an element exists and determining its
* position can be done by a binary search.
*/
- size_type *colnums;
+ std::unique_ptr<size_type[]> colnums;
/**
* Store whether the compress() function was called for this object.
Assert (is_valid_entry() == true, ExcInvalidIterator());
const std::size_t *insert_point =
- std::upper_bound(sparsity_pattern->rowstart,
- sparsity_pattern->rowstart + sparsity_pattern->rows + 1,
+ std::upper_bound(sparsity_pattern->rowstart.get(),
+ sparsity_pattern->rowstart.get() + sparsity_pattern->rows + 1,
index_within_sparsity);
- return insert_point - sparsity_pattern->rowstart - 1;
+ return insert_point - sparsity_pattern->rowstart.get() - 1;
}
ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row;
- ar &boost::serialization::make_array(rowstart, max_dim + 1);
- ar &boost::serialization::make_array(colnums, max_vec_len);
+ ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
+ ar &boost::serialization::make_array(colnums.get(), max_vec_len);
}
ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row;
- if (rowstart != nullptr)
- delete[] rowstart;
- rowstart = new std::size_t[max_dim + 1];
+ rowstart.reset (new std::size_t[max_dim + 1]);
+ colnums.reset (new size_type[max_vec_len]);
- if (colnums != nullptr)
- delete[] colnums;
- colnums = new size_type[max_vec_len];
-
- ar &boost::serialization::make_array(rowstart, max_dim + 1);
- ar &boost::serialization::make_array(colnums, max_vec_len);
+ ar &boost::serialization::make_array(rowstart.get(), max_dim + 1);
+ ar &boost::serialization::make_array(colnums.get(), max_vec_len);
}
-SparsityPattern::~SparsityPattern ()
-{
- if (rowstart != nullptr) delete[] rowstart;
- if (colnums != nullptr) delete[] colnums;
-}
-
-
-
SparsityPattern &
SparsityPattern::operator = (const SparsityPattern &s)
{
// delete empty matrices
if ((m==0) || (n==0))
{
- if (rowstart) delete[] rowstart;
- if (colnums) delete[] colnums;
- rowstart = nullptr;
- colnums = nullptr;
+ rowstart.reset();
+ colnums.reset();
+
max_vec_len = max_dim = rows = cols = 0;
// if dimension is zero: ignore max_per_row
max_row_length = 0;
compressed = false;
+
return;
}
if (vec_len == 0)
{
vec_len = 1;
- if (colnums)
- {
- delete[] colnums;
- colnums = nullptr;
- }
-
max_vec_len = vec_len;
- colnums = new size_type[max_vec_len];
+ colnums.reset (new size_type[max_vec_len]);
}
max_row_length = (row_lengths.size() == 0 ?
// and try to delete the memory a second time.
if (rows > max_dim)
{
- if (rowstart)
- {
- delete[] rowstart;
- rowstart = nullptr;
- }
-
max_dim = rows;
- rowstart = new std::size_t[max_dim+1];
+ rowstart.reset (new std::size_t[max_dim+1]);
}
// allocate memory for the column numbers if necessary
if (vec_len > max_vec_len)
{
- if (colnums)
- {
- delete[] colnums;
- colnums = nullptr;
- }
-
max_vec_len = vec_len;
- colnums = new size_type[max_vec_len];
+ colnums.reset (new size_type[max_vec_len]);
}
// set the rowstart array
&colnums[rowstart[rows]],
std::bind(std::not_equal_to<size_type>(), std::placeholders::_1, invalid_entry));
// now allocate the respective memory
- size_type *new_colnums = new size_type[nonzero_elements];
+ std::unique_ptr<size_type[]> new_colnums (new size_type[nonzero_elements]);
// reserve temporary storage to store the entries of one row
// set iterator-past-the-end
rowstart[rows] = next_row_start;
- // set colnums to the newly allocated array and delete the old one
- delete[] colnums;
- colnums = new_colnums;
+ // set colnums to the newly allocated array and delete previous content
+ // in the process
+ colnums = std::move(new_colnums);
// store the size
max_vec_len = nonzero_elements;
AssertThrow (c == '[', ExcIO());
// reallocate space
- if (rowstart)
- delete[] rowstart;
- if (colnums)
- delete[] colnums;
-
- rowstart = new std::size_t[max_dim+1];
- colnums = new size_type[max_vec_len];
+ rowstart.reset (new std::size_t[max_dim+1]);
+ colnums.reset (new size_type[max_vec_len]);
// then read data
in.read (reinterpret_cast<char *>(&rowstart[0]),