--- /dev/null
+New: The print_formatted() functions of the following matrix classes
+now offer the option to specify a string that separates row entries:
+<br>
+SparseMatrixEZ, SparseMatrix, LAPACKFullMatrix, FullMatrix,
+ChunkSparseMatrix, BlockSparseMatrix, CUDAWrappers::SparseMatrix
+<br>
+(Marc Fehling, 2023/10/15)
*/
/** @{ */
/**
- * Print the matrix in the usual format, i.e. as a matrix and not as a list
+ * Print the matrix in the usual format, i.e., as a matrix and not as a list
* of nonzero elements. For better readability, elements not in the matrix
* are displayed as empty space, while matrix elements which are explicitly
* set to zero are displayed as such.
*
* The parameters allow for a flexible setting of the output format:
- * <tt>precision</tt> and <tt>scientific</tt> are used to determine the
- * number format, where <tt>scientific = false</tt> means fixed point
- * notation. A zero entry for <tt>width</tt> makes the function compute a
- * width, but it may be changed to a positive value, if output is crude.
+ * @p precision and @p scientific are used to determine the number format,
+ * where <code>scientific = false</code> means fixed point notation. A zero
+ * entry for @p width makes the function compute a width, but it may be
+ * changed to a positive value, if output is crude.
*
- * Additionally, a character for an empty value may be specified.
+ * Additionally, a character for an empty value may be specified in
+ * @p zero_string, and a character to separate row entries can be set in
+ * @p separator.
*
- * Finally, the whole matrix can be multiplied with a common denominator to
- * produce more readable output, even integers.
+ * Finally, the whole matrix can be multiplied with a common @p denominator
+ * to produce more readable output, even integers.
*
- * @attention This function may produce <b>large</b> amounts of output if
+ * @attention This function may produce @em large amounts of output if
* applied to a large matrix!
*/
void
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
- const double denominator = 1.) const;
+ const double denominator = 1.,
+ const char *separator = " ") const;
/** @} */
/**
* @addtogroup Exceptions
const bool scientific,
const unsigned int width,
const char *zero_string,
- const double denominator) const
+ const double denominator,
+ const char *separator) const
{
for (size_type r = 0; r < this->n_block_rows(); ++r)
for (size_type c = 0; c < this->n_block_cols(); ++c)
{
out << "Component (" << r << ',' << c << ')' << std::endl;
- this->block(r, c).print_formatted(
- out, precision, scientific, width, zero_string, denominator);
+ this->block(r, c).print_formatted(out,
+ precision,
+ scientific,
+ width,
+ zero_string,
+ denominator,
+ separator);
}
}
print(std::ostream &out) const;
/**
- * Print the matrix in the usual format, i.e. as a matrix and not as a list
+ * Print the matrix in the usual format, i.e., as a matrix and not as a list
* of nonzero elements. For better readability, elements not in the matrix
* are displayed as empty space, while matrix elements which are explicitly
* set to zero are displayed as such.
*
* The parameters allow for a flexible setting of the output format:
- * <tt>precision</tt> and <tt>scientific</tt> are used to determine the
- * number format, where <tt>scientific = false</tt> means fixed point
- * notation. A zero entry for <tt>width</tt> makes the function compute a
- * width, but it may be changed to a positive value, if output is crude.
+ * @p precision and @p scientific are used to determine the number format,
+ * where <code>scientific = false</code> means fixed point notation. A zero
+ * entry for @p width makes the function compute a width, but it may be
+ * changed to a positive value, if output is crude.
*
- * Additionally, a character for an empty value may be specified.
+ * Additionally, a character for an empty value may be specified in
+ * @p zero_string, and a character to separate row entries can be set in
+ * @p separator.
*
- * Finally, the whole matrix can be multiplied with a common denominator to
- * produce more readable output, even integers.
+ * Finally, the whole matrix can be multiplied with a common @p denominator
+ * to produce more readable output, even integers.
*
- * @attention This function may produce <b>large</b> amounts of output if
+ * @attention This function may produce @em large amounts of output if
* applied to a large matrix!
*/
void
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
- const double denominator = 1.) const;
+ const double denominator = 1.,
+ const char *separator = " ") const;
/**
* Print the actual pattern of the matrix. For each entry with an absolute
const bool scientific,
const unsigned int width_,
const char *zero_string,
- const double denominator) const
+ const double denominator,
+ const char *separator) const
{
AssertThrow(out.fail() == false, ExcIO());
for (size_type j = 0; j < n(); ++j)
if (cols->sparsity_pattern(i, j) != SparsityPattern::invalid_entry)
out << std::setw(width)
- << val[cols->sparsity_pattern(i, j)] * denominator << ' ';
+ << val[cols->sparsity_pattern(i, j)] * denominator << separator;
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
out << std::endl;
};
AssertThrow(out.fail() == false, ExcIO());
const bool diagonal_first = true) const;
/**
- * Print the matrix in the usual format, i.e. as a matrix and not as a list
+ * Print the matrix in the usual format, i.e., as a matrix and not as a list
* of nonzero elements. For better readability, elements not in the matrix
* are displayed as empty space, while matrix elements which are explicitly
* set to zero are displayed as such.
*
* The parameters allow for a flexible setting of the output format:
- * <tt>precision</tt> and <tt>scientific</tt> are used to determine the
- * number format, where <tt>scientific = false</tt> means fixed point
- * notation. A zero entry for <tt>width</tt> makes the function compute a
- * width, but it may be changed to a positive value, if output is crude.
+ * @p precision and @p scientific are used to determine the number format,
+ * where <code>scientific = false</code> means fixed point notation. A zero
+ * entry for @p width makes the function compute a width, but it may be
+ * changed to a positive value, if output is crude.
*
- * Additionally, a character for an empty value may be specified.
+ * Additionally, a character for an empty value may be specified in
+ * @p zero_string, and a character to separate row entries can be set in
+ * @p separator.
*
- * Finally, the whole matrix can be multiplied with a common denominator to
- * produce more readable output, even integers.
+ * Finally, the whole matrix can be multiplied with a common @p denominator
+ * to produce more readable output, even integers.
*
- * @attention This function may produce <b>large</b> amounts of output if
+ * @attention This function may produce @em large amounts of output if
* applied to a large matrix!
*/
void
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
- const double denominator = 1.) const;
+ const double denominator = 1.,
+ const char *separator = " ") const;
/** @} */
/**
const bool scientific,
const unsigned int width_,
const char *zero_string,
- const double denominator) const
+ const double denominator,
+ const char *separator) const
{
Assert(column_index_dev != nullptr, ExcNotInitialized());
Assert(val_dev != nullptr, ExcNotInitialized());
{
if (k == cols[j])
{
- out << std::setw(width) << val[j] * Number(denominator) << ' ';
+ out << std::setw(width) << val[j] * Number(denominator)
+ << separator;
++j;
}
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
}
out << std::endl;
};
*
* The parameters allow for a flexible setting of the output format:
*
- * @arg <tt>precision</tt> denotes the number of trailing digits.
+ * @param out This specifies the stream to write to.
*
- * @arg <tt>scientific</tt> is used to determine the number format, where
- * <tt>scientific</tt> = <tt>false</tt> means fixed point notation.
+ * @param precision denotes the number of trailing digits.
*
- * @arg <tt>width</tt> denotes the with of each column. A zero entry for
- * <tt>width</tt> makes the function compute a width, but it may be changed
+ * @param scientific is used to determine the number format, where
+ * <code>scientific = false</code> means fixed point notation.
+ *
+ * @param width denotes the with of each column. A zero entry for
+ * @p width makes the function compute a width, but it may be changed
* to a positive value, if output is crude.
*
- * @arg <tt>zero_string</tt> specifies a string printed for zero entries.
+ * @param zero_string specifies a string printed for zero entries.
*
- * @arg <tt>denominator</tt> Multiply the whole matrix by this common
+ * @param denominator Multiply the whole matrix by this common
* denominator to get nicer numbers.
*
- * @arg <tt>threshold</tt>: all entries with absolute value smaller than
+ * @param threshold all entries with absolute value smaller than
* this are considered zero.
+ *
+ * @param separator specifies a string printed to separate row entries.
*/
void
print_formatted(std::ostream &out,
const unsigned int width = 0,
const char *zero_string = " ",
const double denominator = 1.,
- const double threshold = 0.) const;
+ const double threshold = 0.,
+ const char *separator = " ") const;
/**
* Determine an estimate for the memory consumption (in bytes) of this
const unsigned int width_,
const char *zero_string,
const double denominator,
- const double threshold) const
+ const double threshold,
+ const char *separator) const
{
unsigned int width = width_;
// we might have complex numbers, so use abs also to check for nan
// since there is no isnan on complex numbers
if (numbers::is_nan(std::abs((*this)(i, j))))
- out << std::setw(width) << (*this)(i, j) << ' ';
+ out << std::setw(width) << (*this)(i, j) << separator;
else if (std::abs((*this)(i, j)) > threshold)
- out << std::setw(width) << (*this)(i, j) * number(denominator) << ' ';
+ out << std::setw(width) << (*this)(i, j) * number(denominator)
+ << separator;
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
out << std::endl;
};
* @param threshold all entries with absolute value smaller than
* this are considered zero.
*
+ * @param separator specifies a string printed to separate row entries.
+ *
* @note The entries stored resemble a matrix only if the state is either
* LAPACKSupport::matrix or LAPACK::inverse_matrix. Otherwise, calling this
* function is not allowed.
const unsigned int width = 0,
const char *zero_string = " ",
const double denominator = 1.,
- const double threshold = 0.) const;
+ const double threshold = 0.,
+ const char *separator = " ") const;
private:
/**
const bool diagonal_first = true) const;
/**
- * Print the matrix in the usual format, i.e. as a matrix and not as a list
+ * Print the matrix in the usual format, i.e., as a matrix and not as a list
* of nonzero elements. For better readability, elements not in the matrix
* are displayed as empty space, while matrix elements which are explicitly
* set to zero are displayed as such.
*
* The parameters allow for a flexible setting of the output format:
- * <tt>precision</tt> and <tt>scientific</tt> are used to determine the
- * number format, where <tt>scientific = false</tt> means fixed point
- * notation. A zero entry for <tt>width</tt> makes the function compute a
- * width, but it may be changed to a positive value, if output is crude.
+ * @p precision and @p scientific are used to determine the number format,
+ * where <code>scientific = false</code> means fixed point notation. A zero
+ * entry for @p width makes the function compute a width, but it may be
+ * changed to a positive value, if output is crude.
*
- * Additionally, a character for an empty value may be specified.
+ * Additionally, a character for an empty value may be specified in
+ * @p zero_string, and a character to separate row entries can be set in
+ * @p separator.
*
- * Finally, the whole matrix can be multiplied with a common denominator to
- * produce more readable output, even integers.
+ * Finally, the whole matrix can be multiplied with a common @p denominator
+ * to produce more readable output, even integers.
*
- * @attention This function may produce <b>large</b> amounts of output if
+ * @attention This function may produce @em large amounts of output if
* applied to a large matrix!
*/
void
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
- const double denominator = 1.) const;
+ const double denominator = 1.,
+ const char *separator = " ") const;
/**
* Print the actual pattern of the matrix. For each entry with an absolute
const bool scientific,
const unsigned int width_,
const char *zero_string,
- const double denominator) const
+ const double denominator,
+ const char *separator) const
{
Assert(cols != nullptr, ExcNeedsSparsityPattern());
Assert(val != nullptr, ExcNotInitialized());
for (size_type j = 0; j < n(); ++j)
if ((*cols)(i, j) != SparsityPattern::invalid_entry)
out << std::setw(width)
- << val[cols->operator()(i, j)] * number(denominator) << ' ';
+ << val[cols->operator()(i, j)] * number(denominator) << separator;
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
out << std::endl;
};
AssertThrow(out.fail() == false, ExcIO());
print(std::ostream &out) const;
/**
- * Print the matrix in the usual format, i.e. as a matrix and not as a list
+ * Print the matrix in the usual format, i.e., as a matrix and not as a list
* of nonzero elements. For better readability, elements not in the matrix
* are displayed as empty space, while matrix elements which are explicitly
* set to zero are displayed as such.
*
- * The parameters allow for a flexible setting of the output format: @p
- * precision and @p scientific are used to determine the number format,
- * where @p scientific = @p false means fixed point notation. A zero entry
- * for @p width makes the function compute a width, but it may be changed to
- * a positive value, if output is crude.
+ * The parameters allow for a flexible setting of the output format:
+ * @p precision and @p scientific are used to determine the number format,
+ * where <code>scientific = false</code> means fixed point notation. A zero
+ * entry for @p width makes the function compute a width, but it may be
+ * changed to a positive value, if output is crude.
*
- * Additionally, a character for an empty value may be specified.
+ * Additionally, a character for an empty value may be specified in
+ * @p zero_string, and a character to separate row entries can be set in
+ * @p separator.
*
- * Finally, the whole matrix can be multiplied with a common denominator to
- * produce more readable output, even integers.
+ * Finally, the whole matrix can be multiplied with a common @p denominator
+ * to produce more readable output, even integers.
*
- * This function may produce @em large amounts of output if applied to a
- * large matrix!
+ * @attention This function may produce @em large amounts of output if
+ * applied to a large matrix!
*/
void
print_formatted(std::ostream &out,
const bool scientific = true,
const unsigned int width = 0,
const char *zero_string = " ",
- const double denominator = 1.) const;
+ const double denominator = 1.,
+ const char *separator = " ") const;
/**
* Write the data of this object in binary mode to a file.
const bool scientific,
const unsigned int width_,
const char *zero_string,
- const double denominator) const
+ const double denominator,
+ const char *separator) const
{
AssertThrow(out.fail() == false, ExcIO());
Assert(m() != 0, ExcNotInitialized());
{
const Entry *entry = locate(i, j);
if (entry)
- out << std::setw(width) << entry->value * denominator << ' ';
+ out << std::setw(width) << entry->value * denominator << separator;
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
}
out << std::endl;
};
const unsigned int width_,
const char *zero_string,
const double denominator,
- const double threshold) const
+ const double threshold,
+ const char *separator) const
{
unsigned int width = width_;
// we might have complex numbers, so use abs also to check for nan
// since there is no isnan on complex numbers
if (numbers::is_nan(std::abs((*this)(i, j))))
- out << std::setw(width) << (*this)(i, j) << ' ';
+ out << std::setw(width) << (*this)(i, j) << separator;
else if (std::abs(this->el(i, j)) > threshold)
- out << std::setw(width) << this->el(i, j) * denominator << ' ';
+ out << std::setw(width) << this->el(i, j) * denominator << separator;
else
- out << std::setw(width) << zero_string << ' ';
+ out << std::setw(width) << zero_string << separator;
out << std::endl;
}