vnl_matrix_update.h

来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· C头文件 代码 · 共 39 行

H
39
字号
// This is core/vnl/algo/vnl_matrix_update.h
#ifndef vnl_matrix_update_h_
#define vnl_matrix_update_h_

//:
// \file
// \brief Function to compute M=M+a*b'
// \author  Tim Cootes

#include <vnl/vnl_vector.h>
#include <vnl/vnl_matrix.h>
#include <vcl_cassert.h>

//: Perform rank 1 update of M:   M+=(a*b')
//  Requires a.size()==M.rows(),  b.size()==M.columns()
template<class T>
inline void vnl_matrix_update(vnl_matrix<T>& M,
                              const vnl_vector<T>& a,
                              const vnl_vector<T>& b)
{
  unsigned nr=M.rows();
  unsigned nc=M.columns();
  assert(a.size()==nr);
  assert(b.size()==nc);
  T** rows=M.data_array();
  for (unsigned i=0;i<nr;++i)
  {
    // Update row i of M
    double ai = a[i];
    T* row= rows[i]-1;
    const T* b_data=b.data_block()-1;
    // Fast loop through elements in row
    for (unsigned j=nc;j;--j) row[j] += ai*b_data[j];
  }
}

#endif // vnl_matrix_update_h_

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?