#include <deal.II/lac/identity_matrix.h>
#include <deal.II/lac/exceptions.h>
+#include <memory>
+
+
DEAL_II_NAMESPACE_OPEN
template <typename number> class Vector;
SmartPointer<const ChunkSparsityPattern,ChunkSparseMatrix<number> > cols;
/**
- * Array of values for all the nonzero entries. The position within the
- * matrix, i.e. the row and column number for a given entry can only be
- * deduced using the sparsity pattern. The same holds for the more common
- * operation of finding an entry by its coordinates.
+ * Array of values for all the nonzero entries. The position of an
+ * entry within the matrix, i.e., the row and column number for a
+ * given value in this array can only be deduced using the sparsity
+ * pattern. The same holds for the more common operation of finding
+ * an entry by its coordinates.
*/
- number *val;
+ std::unique_ptr<number[]> val;
/**
* Allocated size of #val. This can be larger than the actually used part if
// the padding elements in chunks that overlap the boundaries of the actual
// matrix -- but since multiplication with a number does not violate the
// invariant of keeping these elements at zero nothing can happen
- number *val_ptr = val;
- const number *const end_ptr = val +
+ number *val_ptr = val.get();
+ const number *const end_ptr = val.get() +
cols->sparsity_pattern.n_nonzero_elements()
*
chunk_size * chunk_size;
// the padding elements in chunks that overlap the boundaries of the actual
// matrix -- but since multiplication with a number does not violate the
// invariant of keeping these elements at zero nothing can happen
- number *val_ptr = val;
- const number *const end_ptr = val +
+ number *val_ptr = val.get();
+ const number *const end_ptr = val.get() +
cols->sparsity_pattern.n_nonzero_elements()
*
chunk_size * chunk_size;
const size_type irregular_col = n/chunk_size;
typename OutVector::iterator dst_ptr = dst.begin()+chunk_size*begin_row;
- const number *val_ptr= &values[rowstart[begin_row]*chunk_size*chunk_size];
+ const number *val_ptr = &values[rowstart[begin_row]*chunk_size*chunk_size];
const size_type *colnum_ptr = &colnums[rowstart[begin_row]];
for (unsigned int chunk_row=begin_row; chunk_row<last_regular_row;
++chunk_row)
ChunkSparseMatrix<number>::~ChunkSparseMatrix ()
{
cols = nullptr;
-
- if (val != nullptr)
- delete[] val;
}
std::bind(&internal::ChunkSparseMatrix::template
zero_subrange<number>,
std::placeholders::_1, std::placeholders::_2,
- val),
+ val.get()),
grain_size);
else if (matrix_size > 0)
std::memset (&val[0], 0, matrix_size*sizeof(number));
if (cols->empty())
{
- if (val != nullptr)
- delete[] val;
- val = nullptr;
+ val.reset ();
max_len = 0;
return;
}
chunk_size * chunk_size;
if (N > max_len || max_len == 0)
{
- if (val != nullptr)
- delete[] val;
- val = new number[N];
+ val.reset (new number[N]);
max_len = N;
}
ChunkSparseMatrix<number>::clear ()
{
cols = nullptr;
- if (val) delete[] val;
- val = nullptr;
+ val.reset ();
max_len = 0;
}
<number,InVector,OutVector>,
std::cref(*cols),
std::placeholders::_1, std::placeholders::_2,
- val,
+ val.get(),
cols->sparsity_pattern.rowstart,
cols->sparsity_pattern.colnums,
std::cref(src),
// 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;
+ const number *val_ptr = val.get();
const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
for (size_type chunk_row=0; chunk_row<n_regular_chunk_rows; ++chunk_row)
n_chunk_rows-1 :
n_chunk_rows);
- const number *val_ptr = val;
+ const number *val_ptr = val.get();
const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
typename Vector<somenumber>::const_iterator v_ptr = v.begin();
n_chunk_rows-1 :
n_chunk_rows);
- const number *val_ptr = val;
+ const number *val_ptr = val.get();
const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
typename Vector<somenumber>::const_iterator u_ptr = u.begin();
n_chunk_rows-1 :
n_chunk_rows);
- const number *val_ptr = val;
+ const number *val_ptr = val.get();
const size_type *colnum_ptr = cols->sparsity_pattern.colnums;
typename Vector<somenumber>::iterator dst_ptr = dst.begin();
AssertThrow (c == '[', ExcIO());
// reallocate space
- delete[] val;
- val = new number[max_len];
+ val.reset (new number[max_len]);
// then read data
in.read (reinterpret_cast<char *>(&val[0]),