2 #ifndef vnl_diag_matrix_h_ 3 #define vnl_diag_matrix_h_ 23 # include <vcl_msvc_warnings.h> 27 #include "vnl/vnl_export.h" 73 T determinant()
const;
79 inline T operator () (
unsigned i,
unsigned j)
const {
80 return (i != j) ? T(0) : diagonal_[i];
83 inline T& operator () (
unsigned i,
unsigned j) {
84 assert(i == j); (void)j;
87 inline T& operator() (
unsigned i) {
return diagonal_[i]; }
88 inline T
const& operator() (
unsigned i)
const {
return diagonal_[i]; }
90 inline T& operator[] (
unsigned i) {
return diagonal_[i]; }
91 inline T
const& operator[] (
unsigned i)
const {
return diagonal_[i]; }
117 inline unsigned int size()
const {
return diagonal_.
size(); }
120 inline unsigned int rows()
const {
return diagonal_.
size(); }
124 inline unsigned int cols()
const {
return diagonal_.
size(); }
131 inline void put (
unsigned r,
unsigned c, T
const&
v) {
134 #if VNL_CONFIG_CHECK_BOUNDS 135 if (r >= this->size())
142 inline T
get (
unsigned r,
unsigned c)
const {
145 #if VNL_CONFIG_CHECK_BOUNDS 146 if (r >= this->size())
177 template <
class T> VNL_EXPORT
184 unsigned len = diagonal_.size();
186 for (
unsigned i = 0; i < len; ++i)
189 for (j = 0; j < i; ++j)
191 for (j = i+1; j < len; ++j)
193 ret(i,i) = diagonal_[i];
203 unsigned len = diagonal_.
size();
206 for (
unsigned i = 0; i < len; ++i)
216 T
const* d = data_block();
217 unsigned len = diagonal_.size();
218 for (
unsigned i = 0; i < len; ++i)
230 for (
unsigned i = 0; i < A.
size(); ++i)
243 for (
unsigned i = 0; i < A.
rows(); ++i)
244 for (
unsigned j = 0; j < A.
columns(); ++j)
245 ret(i,j) = A(i,j) * D(j,j);
258 for (
unsigned i = 0; i < A.
rows(); ++i)
259 for (
unsigned j = 0; j < A.
columns(); ++j)
260 ret(i,j) = A(i,j) * d[i];
271 for (
unsigned i = 0; i < A.
size(); ++i)
282 const unsigned n = D.
size();
286 for (
unsigned j = 0; j < n; ++j)
307 for (
unsigned i = 0; i < A.
size(); ++i)
318 const unsigned n = D.
size();
322 for (
unsigned j = 0; j < n; ++j)
333 const unsigned n = D.
size();
337 for (
unsigned i = 0; i < n; ++i)
339 for (
unsigned j = 0; j < i; ++j)
341 for (
unsigned j = i+1; j < n; ++j)
343 ret(i,i) = d[i] - A(i,i);
368 #endif // vnl_diag_matrix_h_ vnl_diag_matrix & fill(T const &x)
unsigned int size() const
Return the total number of elements stored by the matrix.
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
unsigned int rows() const
Return the number of rows.
An ordinary mathematical matrix.
bool set_size(size_t n)
Resize to n elements.
const_iterator begin() const
unsigned int cols() const
Return the number of columns.
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
T get(unsigned r, unsigned c) const
get element with boundary checks.
size_t size() const
Return the length, number of elements, dimension of this vector.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
void vnl_error_matrix_row_index(char const *fcn, int r)
Raise exception for invalid row index.
vnl_diag_matrix & set(vnl_vector< T > const &v)
Set diagonal elements using vector.
vnl_vector< T > const & diagonal() const
Return diagonal elements as a vector.
vnl_diag_matrix & set_diagonal(vnl_vector< T > const &v)
Sets the diagonal elements of this matrix to the specified list of values.
vnl_vector< T > diagonal_
vnl_diag_matrix & fill_diagonal(T const &v)
Set all diagonal elements of matrix to specified value.
iterator end()
Iterator pointing to element beyond end of data.
vnl_diag_matrix(unsigned nn)
Construct an empty diagonal matrix.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
vnl_vector< T >::const_iterator const_iterator
vnl_diag_matrix(unsigned nn, T const &value)
Construct a diagonal matrix with diagonal elements equal to value.
iterator begin()
Iterator pointing to start of data.
An ordinary mathematical matrix.
void put(unsigned r, unsigned c, T const &v)
set element with boundary checks.
T const * data_block() const
void clear()
Make the vector as if it had been default-constructed.
unsigned int columns() const
Return the number of columns.
vnl_matrix< T > asMatrix() const
Convert a vnl_diag_matrix to a Matrix.
vnl_vector & fill(T const &v)
Set all values to v.
vnl_diag_matrix(vnl_vector< T > const &that)
Construct a diagonal matrix from a vnl_vector.
Mathematical vector class, templated by type of element.
vnl_diag_matrix< T > & operator/=(T v)
In-place arithmetic operation.
T const * const_iterator
Const iterator type.
const_iterator end() const
T determinant() const
Return determinant as product of diagonal values.
T * iterator
Type defs for iterators.
stores a diagonal matrix as a single vector.
unsigned int rows() const
Return the number of rows.
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
vnl_vector< T >::iterator iterator
vnl_matrix< T > as_ref() const
vnl_diag_matrix & invert_in_place()
Invert a vnl_diag_matrix in-situ.
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
unsigned int columns() const
Return the number of columns.
vnl_vector< T > get_diagonal() const
Return a vector (copy) with the content of the (main) diagonal.
vnl_diag_matrix & operator=(vnl_diag_matrix< T > const &that)
T * data_block()
Return pointer to the diagonal elements as a contiguous 1D C array;.