Questions tagged [expression-templates]

Expression templates is a C++ template metaprogramming technique in which templates are used to represent part of an expression as a compile-time structure representing a flattened abstract syntax tree of said expression. It enables idioms like lazy evaluation and inter-procedurale optimization within the language itself.

Expression templates is a C++ template metaprogramming technique in which templates are used to represent part of an expression as a compile-time structure representing a flattened abstract syntax tree of said expression. It enables idioms like lazy evaluation and inter-procedural optimization within the language itself.

Seminal works on Expression Templates go back to Vandevoorde et al in their 2002 book 'C++ Templates: The Complete Guide' and Veldhuizen in the 1995 paper called 'Expression Templates'.

Classically, Expression Templates are used to capture arbitrary large expressions without any creation of temporaries. Said expression are usually transformed and turned into actual code within the proper evaluation context. Linear algebra libraries are the most frequent example of this technique but other domains like parser generator (Boost.spirit) or State Machine description (Boost.MSM) are known.

If many people still write Expression Templates by hand, Boost.proto provide a framework to develop them without all the required boilerplate. It also provides tree manipulation functions that simplify transformation of said expression.

Expression Template is often tied to Domain Specific Language as they provide an efficient way to implement hem inside C++.

110 questions
0
votes
0 answers

Partial evaluation of expression template

I'm planing on writing a 3D-SEM library, in which I need to evaluate expressions such as: integral(mesh, f*v); With f a function and v is a test function. The expression f*v can effectively be rewritten as a rank 6 tensor: and the integral is then…
0
votes
1 answer

Vector concatenation in Eigen returning an expression

Is there a way to concatenate vectors in Eigen without having to duplicate data? Here how to concatenate Vectors in Eigen? and here Eigen how to concatenate matrix along a specific dimension? concatenation is done by allocating memory for a new…
marco
  • 167
  • 6
0
votes
1 answer

Template Argument Deduction issues

This is a follow-on question to my earlier post on writing a matrix-algebra header. I am using expression templates to avoid the creation of temporaries. Lazy-evaluation is great for matrix operations performed coefficient-wise such as +, -, +=, -=,…
Quasar
  • 501
  • 4
  • 16
0
votes
2 answers

Designing a Matrix class - expression template issues

I would like to design a Matrixclass that uses expression templates and avoids temporaries. I would like to start with something very simple, so I decided to just implement matrix addition, first. I created a class AddExp to represent a compound…
Quasar
  • 501
  • 4
  • 16
0
votes
3 answers

Why doesn't this Blitz++ code compile?

I'm a blitz++ newbie. So far, so good, but I'm a bit mystified why the commented out line in the code below fails to compile with error: conversion from ‘blitz::_bz_tinyMatExpr
timday
  • 24,582
  • 12
  • 83
  • 135
0
votes
2 answers

Shared Ownership of existing ressource programming pattern

I know that questions on shared ownership on existing ressources have been asked quite a few times before, but somehow I failed to find an answer to my specific problem. Please correct me if I am wrong. I am working an an expression template…
joergbrech
  • 2,056
  • 1
  • 5
  • 17
0
votes
1 answer

C++ - How to program functions that work on temporaries and don't allocate

I am trying to implement a fixed size array class that will represent small size vectors. I wanted to have typical vector operations defined, like multiplication by scalar and sum with another vector. The problem is I cannot get the same performance…
0
votes
0 answers

How to construct expression templates from operations on fundamental data types?

I'm trying to build expression templates from maths operations in order to correctly sequence unsequenced operations (such as opertor+). The reason is because operator co_await with operator+ appears to be unsequenced (resulting in incorrect results…
David Ledger
  • 2,033
  • 1
  • 12
  • 27
0
votes
2 answers

How to write fast c++ lazy evaluation code in Fastor or Xtensor?

I am a newbie in c++, and heard that libraries like eigen, blaze, Fastor and Xtensor with lazy-evaluation and simd are fast for vectorized operation. I measured the time collapsed in some doing basic numeric operation by the following…
0
votes
0 answers

Template constructor parameter base type check in C++

Im trying to write some simple math libary in C++ using Expression templates. template class MatSum : public MatExpression> { E1 const& _u; E2 const& _v; public: MatSum(E1 const& u, E2 const& v) :_u(u),…
Marko Taht
  • 1,448
  • 1
  • 20
  • 40
0
votes
0 answers

Expression Template Operators with Variadic Templates

Using variadic templates we can write a function add, which takes any number of input parameters, and then returns a single Expression (to be lazily evaluated). When called for a specific index i, this expression sums all elements at i for all the…
0
votes
2 answers

Concatenating const_string's

How do I concatenate two const_string's? Its home http://conststring.sourceforge.net/ says citation: It also uses expression templates for concatenation, effectively eliminating overhead resulting from creation intermediate temporary objects. So I…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
0
votes
0 answers

Eigen deduce Template Expression type

In short: I am trying to deduce the return value (which is an expression template) of a function that performs a unary operation on a matrix. In this case the operation is to compute a covariance matrix. I followed the Eigen documentation…
robert
  • 1
  • 1
0
votes
2 answers

C++ expression templates ambiguous operator overloading

Im trying to implement vector and matrix expression templates.Both have the operator+ overload but i get ambiguous operator error. How can i overload operators for both matrix and vector while retaining the effects of expression templates? Here is…
Marko Taht
  • 1,448
  • 1
  • 20
  • 40
0
votes
1 answer

No match for operator+ , and no match for vector construction call in c++

I am trying to implement Matrix Addition using expression templates. I am facing some trouble. Here is my matrix code: #include #include #include template class MatrixExpression { public: double…