⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vnl_trace.h

📁 DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.
💻 H
字号:
// This is core/vnl/vnl_trace.h
#ifndef vnl_trace_h_
#define vnl_trace_h_
#ifdef VCL_NEEDS_PRAGMA_INTERFACE
#pragma interface
#endif
//:
//  \file
//  \brief Calculate trace of a matrix
//  \author fsm
//
// \verbatim
//  Modifications
//   LSB (Manchester) 19/3/01 Documentation tidied
//   Peter Vanroose   27-Jun-2003  made inline and added trace(matrix_fixed)
// \endverbatim

#include <vnl/vnl_matrix.h>
#include <vnl/vnl_matrix_fixed.h>

//: Calculate trace of a matrix
// \relates vnl_matrix
template <class T>
T vnl_trace(vnl_matrix<T> const& M)
{
  T sum(0);
  const unsigned int N = M.rows()<M.cols() ? M.rows() : M.cols();
  for (unsigned int i=0; i<N; ++i)
    sum += M(i, i);
  return sum;
}

//: Calculate trace of a matrix
// \relates vnl_matrix_fixed
template <class T, unsigned int N1, unsigned int N2>
T vnl_trace(vnl_matrix_fixed<T,N1,N2> const& M)
{
  T sum(0);
  for (unsigned int i=0; i<N1 && i<N2; ++i)
    sum += M(i, i);
  return sum;
}

#endif // vnl_trace_h_

⌨️ 快捷键说明

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