C ++防爆pression模板 [英] C++ Expression Templates

查看:143
本文介绍了C ++防爆pression模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用C的数值计算。我听说使用C ++防爆pression模板是科学计算更好。什么是简单来说C ++防爆pression模板?


    围绕
  1. 是否有书使用C ++防爆pression模板讨论数值方法/计算?


  2. 在什么样的方式,C ++防爆pression模板是比用纯C更好吗?



解决方案

  

什么是深入浅出的C ++防爆pression模板?


防爆pression模板是C ++模板元编程的一个类别,它推迟SUBEX评价pressions直到全部前pression是已知的,使得可以应用优化(特别是消除临时的)。


  

是否有周围本本使用C ++防爆pression模板讨论数值方法/计算?


我相信ET的是由托德Veldhuizen谁在15年前上发表了一篇论文发明的。 (似乎很多旧的链接,它是死的现在,但这里目前 是它的一个版本),关于它的一些材料是大卫Vandevoorde的和尼古拉约祖蒂斯 C ++模板:该完全指南


  

在什么样的方式,C ++防爆pression模板是比用纯C更好?


他们让你写在离pressive高水平这样你的code不失性能。例如,

 无效F(常量my_array<双> A1,常量my_array<双> A2)
{
  my_array<双> A3 = 1.2 * A1 + A1 * A2;
  // ..
}

可以到所有的方式优化

 为(my_array<双> :: SIZE_TYPE IDX = 0; IDX< a1.size(); ++ IDX)
  A3 [IDX] = 1.2 * A1 [IDX] + A1 [IDX] * A2 [IDX];

这是更快,但更难理解。

I currently use C for numerical computations. I've heard that using C++ Expression Templates is better for scientific computing. What are C++ Expression Templates in simple terms?

  1. Are there books around that discuss numerical methods/computations using C++ Expression Templates?

  2. In what way, C++ Expression Templates are better than using pure C?

解决方案

What are C++ Expression Templates in simple terms?

Expression templates are a category of C++ template meta programming which delays evaluation of subexpressions until the full expression is known, so that optimizations (especially the elimination of temporaries) can be applied.

Are there books around that discuss numerical methods/computations using C++ Expression Templates?

I believe ET's were invented by Todd Veldhuizen who published a paper on it 15 years ago. (It seems that many older links to it are dead by now, but currently here is a version of it.) Some material about it is in David Vandevoorde's and Nicolai Josuttis' C++ Templates: The Complete Guide.

In what way, C++ Expression Templates are better than using pure C?

They allow you to write your code in an expressive high level way without losing performance. For example,

void f(const my_array<double> a1, const my_array<double> a2) 
{ 
  my_array<double> a3 = 1.2 * a1 + a1 * a2; 
  // ..
}

can be optimized all the way down to

for( my_array<double>::size_type idx=0; idx<a1.size(); ++idx ) 
  a3[idx] = 1.2*a1[idx] + a1[idx]*a2[idx]; 

which is faster, but harder to understand.

这篇关于C ++防爆pression模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆