tnt_array1d_utils.h

来自「一个矩阵计算的库 包括几乎所有需要的矩阵运算 对3d计算和图形处理有很大帮助」· C头文件 代码 · 共 231 行

H
231
字号
/*** Template Numerical Toolkit (TNT)** Mathematical and Computational Sciences Division* National Institute of Technology,* Gaithersburg, MD USA*** This software was developed at the National Institute of Standards and* Technology (NIST) by employees of the Federal Government in the course* of their official duties. Pursuant to title 17 Section 105 of the* United States Code, this software is not subject to copyright protection* and is in the public domain. NIST assumes no responsibility whatsoever for* its use by other parties, and makes no guarantees, expressed or implied,* about its quality, reliability, or any other characteristic.**/#ifndef TNT_ARRAY1D_UTILS_H#define TNT_ARRAY1D_UTILS_H#include <cstdlib>#include <cassert>namespace TNT{template <class T>std::ostream& operator<<(std::ostream &s, const Array1D<T> &A){    int N=A.dim1();#ifdef TNT_DEBUG	s << "addr: " << (void *) &A[0] << "\n";#endif    s << N << "\n";    for (int j=0; j<N; j++)    {       s << A[j] << "\n";    }    s << "\n";    return s;}template <class T>std::istream& operator>>(std::istream &s, Array1D<T> &A){	int N;	s >> N;	Array1D<T> B(N);	for (int i=0; i<N; i++)		s >> B[i];	A = B;	return s;}template <class T>Array1D<T> operator+(const Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() != n )		return Array1D<T>();	else	{		Array1D<T> C(n);		for (int i=0; i<n; i++)		{			C[i] = A[i] + B[i];		}		return C;	}}template <class T>Array1D<T> operator-(const Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() != n )		return Array1D<T>();	else	{		Array1D<T> C(n);		for (int i=0; i<n; i++)		{			C[i] = A[i] - B[i];		}		return C;	}}template <class T>Array1D<T> operator*(const Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() != n )		return Array1D<T>();	else	{		Array1D<T> C(n);		for (int i=0; i<n; i++)		{			C[i] = A[i] * B[i];		}		return C;	}}template <class T>Array1D<T> operator/(const Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() != n )		return Array1D<T>();	else	{		Array1D<T> C(n);		for (int i=0; i<n; i++)		{			C[i] = A[i] / B[i];		}		return C;	}}template <class T>Array1D<T>&  operator+=(Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() == n)	{		for (int i=0; i<n; i++)		{				A[i] += B[i];		}	}	return A;}template <class T>Array1D<T>&  operator-=(Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() == n)	{		for (int i=0; i<n; i++)		{				A[i] -= B[i];		}	}	return A;}template <class T>Array1D<T>&  operator*=(Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() == n)	{		for (int i=0; i<n; i++)		{				A[i] *= B[i];		}	}	return A;}template <class T>Array1D<T>&  operator/=(Array1D<T> &A, const Array1D<T> &B){	int n = A.dim1();	if (B.dim1() == n)	{		for (int i=0; i<n; i++)		{				A[i] /= B[i];		}	}	return A;}} // namespace TNT#endif

⌨️ 快捷键说明

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