trace.hpp

来自「矩阵运算源码最新版本」· HPP 代码 · 共 48 行

HPP
48
字号
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef MTL_TRACE_INCLUDE#define MTL_TRACE_INCLUDE#include <boost/numeric/linear_algebra/identity.hpp>#include <boost/numeric/mtl/utility/exception.hpp>#include <boost/numeric/mtl/utility/tag.hpp>#include <boost/numeric/mtl/utility/category.hpp>#include <boost/numeric/mtl/concept/collection.hpp>namespace mtl {template <typename Matrix>typename Collection<Matrix>::value_typeinline trace(const Matrix& matrix){    using math::one;    typedef typename Collection<Matrix>::value_type value_type;    MTL_THROW_IF(num_rows(matrix) != num_cols(matrix), matrix_not_square());    // If matrix is empty then the result is the identity from the default-constructed value    if (num_rows(matrix) == 0) {	value_type ref;	return one(ref);    }    value_type value= matrix[0][0];    for (unsigned i= 1; i < num_rows(matrix); i++)	value*= matrix[i][i];	    return value;}} // namespace mtl#endif // MTL_TRACE_INCLUDE

⌨️ 快捷键说明

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