加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C表达式模板

发布时间:2020-12-16 04:55:02 所属栏目:百科 来源:网络整理
导读:我目前使用C进行数值计算.我听说使用C Expression Templates更适合科学计算.什么是C表达模板简单来说? 是否有书籍使用C表达模板讨论数值方法/计算? 以何种方式,C表达模板比使用纯C更好? 解决方法 What are C++ Expression Templates in simple terms? Exp
我目前使用C进行数值计算.我听说使用C Expression Templates更适合科学计算.什么是C表达模板简单来说?

>是否有书籍使用C表达模板讨论数值方法/计算?
>以何种方式,C表达模板比使用纯C更好?

解决方法

What are C++ Expression Templates in simple terms?

Expression templates是C模板元编程的一类,它延迟子表达式的评估,直到已知完整表达式,从而可以应用优化(尤其是消除临时).

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

我相信ET是由Todd Veldhuizen发明的,他在15年前发表了一篇论文. (似乎很多旧链接到现在已经死了,但目前here是它的一个版本.)有关它的一些材料是David Vandevoorde和Nicolai Josuttis’C++ Templates: The Complete Guide.

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

它们允许您以富有表现力的高级方式编写代码而不会降低性能.例如,

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

可以一直优化到

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

哪个更快,但更难理解.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读