2 #ifndef vnl_sym_matrix_h_ 3 #define vnl_sym_matrix_h_ 13 # include <vcl_msvc_warnings.h> 18 #include "vnl/vnl_export.h" 37 nn_(nn) { setup_index(); }
68 inline T operator () (
unsigned i,
unsigned j)
const {
69 return (i > j) ? index_[i][j] : index_[j][i];
72 inline T& operator () (
unsigned i,
unsigned j) {
73 return (i > j) ? index_[i][j] : index_[j][i];
78 inline const T* operator [] (
unsigned i)
const {
84 inline T
fast (
unsigned i,
unsigned j)
const {
90 inline T&
fast (
unsigned i,
unsigned j) {
108 inline unsigned int size()
const {
return nn_ * (nn_ + 1) / 2; }
111 inline unsigned int rows()
const {
return nn_; }
115 inline unsigned int cols()
const {
return nn_; }
119 inline unsigned int columns()
const {
return nn_; }
122 inline void put (
unsigned r,
unsigned c, T
const&
v)
124 #if VNL_CONFIG_CHECK_BOUNDS 130 (r > c) ? index_[r][c] =
v : index_[c][r] =
v;
134 inline T
get (
unsigned r,
unsigned c)
const 136 #if VNL_CONFIG_CHECK_BOUNDS 142 return (r > c) ? index_[r][c] : index_[c][r];
150 inline void set_size(
int n);
160 void set_half_row (
const vnl_vector<T> &half_row,
unsigned i);
190 for (
unsigned i = 0; i <
nn_; ++i)
191 for (
unsigned j = 0; j <= i; ++j)
192 fast(i,j) = *(data++);
208 data_(
vnl_c_vector<T>::allocate_T(that.rows() * (that.rows() + 1) / 2)),
214 for (
unsigned i = 0; i <
nn_; ++i)
215 for (
unsigned j = 0; j <= i; ++j)
217 assert( that(i,j) == that(j,i) );
218 fast(i,j) = that(i,j);
224 data_(nullptr), index_(nullptr), nn_(0)
235 for (
unsigned i = 0; i < nn_; ++i)
236 for (
unsigned j = 0; j <= i; ++j)
237 ret(i,j) = ret(j,i) = fast(i,j);
245 if (n == (
int)nn_)
return;
257 template <
class T> VNL_EXPORT
260 template <
class T> VNL_EXPORT
263 template <
class T> VNL_EXPORT
271 #endif // vnl_sym_matrix_h_ static void deallocate(T **, const std::size_t n_when_allocated)
unsigned int cols() const
Return the number of columns.
const_iterator end() const
An ordinary mathematical matrix.
void swap(vnl_sym_matrix &m)
Swap contents of m with THIS.
vnl_sym_matrix< T > & update(vnl_sym_matrix< T > const &m, unsigned diag_start=0)
Replaces the symmetric submatrix of THIS matrix with the elements of matrix m.
unsigned int columns() const
Return the number of columns.
T const * data_block() const
Return pointer to the lower triangular elements as a contiguous 1D C array;.
vnl_c_vector interfaces to lowlevel memory-block operations.
void vnl_error_matrix_row_index(char const *fcn, int r)
Raise exception for invalid row index.
T fast(unsigned i, unsigned j) const
fast access, however i >= j.
void vnl_error_matrix_col_index(char const *fcn, int c)
Raise exception for invalid col index.
T get(unsigned r, unsigned c) const
get element.
unsigned int cols() const
Return the number of columns.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
const_iterator begin() const
vnl_sym_matrix(unsigned nn)
Construct a symmetric matrix of size nn by nn.
unsigned int rows() const
Return the number of rows.
T & fast(unsigned i, unsigned j)
fast access, however i >= j.
void put(unsigned r, unsigned c, T const &v)
set element.
bool operator==(int r1, vnl_finite_int< N > const &r2)
static void fill(T *x, unsigned, T const &v)
x[i] = v.
unsigned int size() const
Return the total number of elements stored by the matrix.
static T * allocate_T(const std::size_t n)
An ordinary mathematical matrix.
static T ** allocate_Tptr(const std::size_t n)
Memory allocation.
void swap(vnl_matrix< T > &A, vnl_matrix< T > &B)
Swap two matrices.
Mathematical vector class, templated by type of element.
void swap(vnl_sym_matrix< T > &a, vnl_sym_matrix< T > &b)
Swap the contents of a and b.
void set_size(int n)
Resize matrix to n by n.
T * data_block()
Return pointer to the lower triangular elements as a contiguous 1D C array;.
void setup_index()
Set up the index array.
vnl_sym_matrix< T > & operator/=(T v)
In-place arithmetic operations.
Math on blocks of memory.
vnl_sym_matrix()
Construct an empty symmetric matrix.
stores a symmetric matrix as just the diagonal and lower triangular part.
static void scale(T const *x, T *y, unsigned, T const &)
y[i] = a*x[i].
vnl_matrix< T > as_matrix() const
Convert a vnl_sym_matrix to a vnl_matrix.