该库由美国国家标准与技术研究所的数学与计算科学学部开发
简介
模板数值工具包(TNT)是数值对象的接口和参考实现的集合,可用于C ++中的科学计算。 该工具包定义了用于数值应用程序中的基本数据结构的接口,例如多维数组和稀疏矩阵。 该软件包的目的是提供可重用的软件组件,以解决C ++代码的许多可移植性和维护性问题。相比于目前常用的eigen,这个库更简单,对三维数据的支持更好。
TNT提供了TNT组件的接口和实现之间的区别。 例如,有一个用于二维数组的TNT接口,该接口描述了如何访问单个元素以及如何在算法中使用某些信息(例如数组尺寸)。 但是,这样的接口可以有多种实现:一种使用表达式模板,一种使用BLAS内核,另一种用于提供调试信息。 通过仅指定接口,应用程序代码可以利用这种算法,同时在使用优化或可移植性策略时为库开发人员提供最大的灵活性。
这个库比较简单,只有24个头文件组成。
tnt.h tnt_array3d.h tnt_fortran_array2d_utils.h tnt_linalg.h tnt_stopwatch.h
tnt_array1d.h tnt_array3d_utils.h tnt_fortran_array3d.h tnt_math_utils.h tnt_subscript.h
tnt_array1d_utils.h tnt_fortran_array1d.h tnt_fortran_array3d_utils.h tnt_matrix.h tnt_vector.h
tnt_array2d.h tnt_fortran_array1d_utils.h tnt_i_refvec.h tnt_sparse_matrix.h tnt_version.h
tnt_array2d_utils.h tnt_fortran_array2d.h tnt_lapack.h tnt_sparse_vector.h
TNT 数据结构
TNT工具库
array I/O
math routines (hypot(), sign(), etc.)
Stopwatch class for timing measurements
使用TNT的算法库库
JAMA: 具备 QR, SVD, Cholesky and Eigenvector 求解器的线性代数库.
old (pre 1.0) TNT routines for LU, QR, and Eigenvalue problems
其提供的主要数据类型和接口如下:
class TNT::Array1D
class TNT::Array2D
class TNT::Array3D
class TNT::Fortran_Array1D
class TNT::Fortran_Array2D
class TNT::Fortran_Array3D
class TNT::Matrix
class TNT::Sparse_Matrix_CompRow
class TNT::Stopwatch
class TNT::Vector
Typedefs
typedef TNT_SUBSCRIPT_TYPE Subscript
Functions
template<class T> std::ostream& operator<< (std::ostream &s, const Array1D< T > &A)
std::istream& operator>> (std::istream &s, Array1D< T > &A)
Array1D<T>
operator+ (const Array1D< T > &A, const Array1D< T > &B)
Array1D<T>
operator- (const Array1D< T > &A, const Array1D< T > &B)
Array1D<T>
operator * (const Array1D< T > &A, const Array1D< T > &B)
Array1D<T>
operator/ (const Array1D< T > &A, const Array1D< T > &B)
Array1D<T>&
operator+= (Array1D< T > &A, const Array1D< T > &B)
Array1D<T>&
operator-= (Array1D< T > &A, const Array1D< T > &B)
Array1D<T>&
operator *= (Array1D< T > &A, const Array1D< T > &B)
Array1D<T>&
operator/= (Array1D< T > &A, const Array1D< T > &B)
template<class T> std::ostream& operator<< (std::ostream &s, const Array2D< T > &A)
std::istream& operator>> (std::istream &s, Array2D< T > &A)
Array2D<T>
operator+ (const Array2D< T > &A, const Array2D< T > &B)
Array2D<T>
operator- (const Array2D< T > &A, const Array2D< T > &B)
Array2D<T>
operator * (const Array2D< T > &A, const Array2D< T > &B)
Array2D<T>
operator/ (const Array2D< T > &A, const Array2D< T > &B)
Array2D<T>&
operator+= (Array2D< T > &A, const Array2D< T > &B)
Array2D<T>&
operator-= (Array2D< T > &A, const Array2D< T > &B)
Array2D<T>&
operator *= (Array2D< T > &A, const Array2D< T > &B)
Array2D<T>&
operator/= (Array2D< T > &A, const Array2D< T > &B)
Array2D<T>
matmult (const Array2D< T > &A, const Array2D< T > &B)
template<class T> std::ostream& operator<< (std::ostream &s, const Array3D< T > &A)
std::istream& operator>> (std::istream &s, Array3D< T > &A)
Array3D<T>
operator+ (const Array3D< T > &A, const Array3D< T > &B)
Array3D<T>
operator- (const Array3D< T > &A, const Array3D< T > &B)
Array3D<T>
operator * (const Array3D< T > &A, const Array3D< T > &B)
Array3D<T>
operator/ (const Array3D< T > &A, const Array3D< T > &B)
Array3D<T>&
operator+= (Array3D< T > &A, const Array3D< T > &B)
Array3D<T>&
operator-= (Array3D< T > &A, const Array3D< T > &B)
Array3D<T>&
operator *= (Array3D< T > &A, const Array3D< T > &B)
Array3D<T>&
operator/= (Array3D< T > &A, const Array3D< T > &B)
template<class T> std::ostream& operator<< (std::ostream &s, const Matrix< T > &A)
std::istream& operator>> (std::istream &s, Matrix< T > &A)
Matrix<T>
operator+ (const Matrix< T > &A, const Matrix< T > &B)
Matrix<T>
operator- (const Matrix< T > &A, const Matrix< T > &B)
Matrix<T>
mult_element (const Matrix< T > &A, const Matrix< T > &B)
Matrix<T>
transpose (const Matrix< T > &A)
Matrix<T>
matmult (const Matrix< T > &A, const Matrix< T > &B)
Matrix<T>
operator * (const Matrix< T > &A, const Matrix< T > &B)
int matmult (Matrix< T > &C, const Matrix< T > &A, const Matrix< T > &B)
Vector<T>
matmult (const Matrix< T > &A, const Vector< T > &x)
Vector<T>
operator * (const Matrix< T > &A, const Vector< T > &x)
template<class T> std::ostream& operator<< (std::ostream &s, const Fortran_Array1D< T > &A)
std::istream& operator>> (std::istream &s, Fortran_Array1D< T > &A)
Fortran_Array1D<T>
operator+ (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>
operator- (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>
operator * (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>
operator/ (const Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>&
operator+= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>&
operator-= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>&
operator *= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
Fortran_Array1D<T>&
operator/= (Fortran_Array1D< T > &A, const Fortran_Array1D< T > &B)
template<class T> std::ostream& operator<< (std::ostream &s, const Fortran_Array2D< T > &A)
std::istream& operator>> (std::istream &s, Fortran_Array2D< T > &A)
template<class T> std::ostream& operator<< (std::ostream &s, const Fortran_Array3D< T > &A)
std::istream& operator>> (std::istream &s, Fortran_Array3D< T > &A)
Real hypot (const Real &a, const Real &b)
Scalar min (const Scalar &a, const Scalar &b)
Scalar max (const Scalar &a, const Scalar &b)
Real abs (const Real &a)
template<class T> std::ostream& operator<< (std::ostream &s, const Vector< T > &A)
std::istream& operator>> (std::istream &s, Vector< T > &A)
Vector<T>
operator+ (const Vector< T > &A, const Vector< T > &B)
Vector<T>
operator- (const Vector< T > &A, const Vector< T > &B)
Vector<T>
operator * (const Vector< T > &A, const Vector< T > &B)
T dot_prod (const Vector< T > &A, const Vector< T > &B)
下面是一个简单的测试实例
#include <iostream>
#include <random>
#include <algorithm>
#include "tnt/tnt.h"
using namespace TNT;
int main()
{
std::cout << "Hello World!\n";
int ni = 5;
int nj = 10;
Array2D<double> a(ni, nj, 1.0);
default_random_engine e;
uniform_real_distribution<double> rand(0, 1);
for (int i = 0; i < a.dim1(); i++)
{
for (int j = 0; j < a.dim2(); j++) {
a[i][j] = rand(e);
}
}
std::cout << a << std::endl;
}
//运行结果
Hello World!
5 10
0.135477 0.835009 0.968868 0.221034 0.308167 0.547221 0.188382 0.992881 0.996461 0.967695
0.725839 0.98111 0.109862 0.798106 0.297029 0.00478348 0.112465 0.639763 0.878431 0.503663
0.797929 0.361294 0.211924 0.68136 0.398739 0.740647 0.474759 0.422088 0.173865 0.301913
0.79728 0.31655 0.872429 0.149114 0.994068 0.821903 0.125183 0.76375 0.490589 0.663606
0.125897 0.210209 0.0512164 0.0364413 0.408731 0.457989 0.487569 0.793975 0.920875 0.807531