1 #ifndef __cxx_test_project_matrix_h__ 2 #define __cxx_test_project_matrix_h__ 18 template<
typename Scalar>
42 assert((1 <= i) && (i <=
size));
43 assert((1 <= j) && (j <=
size));
71 template <
typename OUTPUT_STREAM>
73 const unsigned int precision = 3,
74 const bool scientific =
true,
75 const unsigned int width_ = 0,
76 const char *zero_string =
"*",
77 const double denominator = 1.,
78 const double threshold = 0.)
const 80 unsigned int width = width_;
81 os <<
"(" <<
size <<
"x" <<
size <<
") Matrix" << std::endl;
84 std::ios::fmtflags old_flags = os.flags();
85 unsigned int old_precision = os.precision (precision);
88 os.setf (std::ios::scientific, std::ios::floatfield);
93 os.setf (std::ios::fixed, std::ios::floatfield);
98 for (
int i1 = 1 ; i1 <=
size; i1++) {
99 for (
int i2 = 1; i2 <=
size; i2++) {
100 if (std::fabs((*
this)(i1,i2)) > threshold)
101 os << std::setw(width)
102 << (*this)(i1,i2) * Scalar(denominator) <<
' ';
104 os << std::setw(width) << zero_string <<
' ';
106 if (i1 !=
size) os << std::endl;
111 os.flags (old_flags);
112 os.precision(old_precision);
int get_size() const
get the number of rows/columns
Namespace for core components.
Scalar * get_values()
get the array of elements of the matrix
Scalar & operator()(int i, int j)
access and change individual elements
const Scalar * get_values() const
get the array of elements of the matrix
virtual ~Matrix()
destructor, delete memory created during construction
Matrix(int _size)
constructor of an _size by _size matrix
void print_formatted(OUTPUT_STREAM &os, const unsigned int precision=3, const bool scientific=true, const unsigned int width_=0, const char *zero_string="*", const double denominator=1., const double threshold=0.) const
print the matrix in some nice form
int size
the number of rows/columns
Scalar * values
the entries of the matrix (row-wise)
A dense quadratic matrix of arbitrary size.
Scalar operator()(int i, int j) const
access individual elements