vnl_matrix_update.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_matrix_update.h
2 #ifndef vnl_matrix_update_h_
3 #define vnl_matrix_update_h_
4 //:
5 // \file
6 // \brief Function to compute M=M+a*b'
7 // \author Tim Cootes
8 
9 #include <vnl/vnl_vector.h>
10 #include <vnl/vnl_matrix.h>
11 #include <cassert>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 
16 //: Perform rank 1 update of M: M+=(a*b')
17 // Requires a.size()==M.rows(), b.size()==M.columns()
18 // \relatesalso vnl_matrix
19 template<class T>
21  const vnl_vector<T>& a,
22  const vnl_vector<T>& b)
23 {
24  unsigned nr=M.rows();
25  unsigned nc=M.columns();
26  assert(a.size()==nr);
27  assert(b.size()==nc);
28  T** rows=M.data_array();
29  for (unsigned i=0;i<nr;++i)
30  {
31  // Update row i of M
32  double ai = a[i];
33  T* row= rows[i]-1;
34  const T* b_data=b.data_block()-1;
35  // Fast loop through elements in row
36  for (unsigned j=nc;j;--j) row[j] += ai*b_data[j];
37  }
38 }
39 
40 #endif // vnl_matrix_update_h_
An ordinary mathematical matrix.
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
Definition: vnl_vector.h:230
void vnl_matrix_update(vnl_matrix< T > &M, const vnl_vector< T > &a, const vnl_vector< T > &b)
Perform rank 1 update of M: M+=(a*b').
An ordinary mathematical matrix.
Definition: vnl_adjugate.h:22
T const *const * data_array() const
Access the 2D array, so that elements can be accessed with array[row][col] directly.
Definition: vnl_matrix.h:609
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179
unsigned int columns() const
Return the number of columns.
Definition: vnl_matrix.h:187