TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
Lazy expressions, functions and operations

Detailed Description

Classes that represent lazy expressions, functions and operations.

Classes

struct  nda::clef::expr< Tag, Ts >
 Single node of the expression tree. More...
 
struct  nda::clef::make_fun_impl< T, Is >
 Helper struct to simplify calls to nda::clef::eval. More...
 
struct  nda::clef::operation< Tag >
 Generic operation performed on expression nodes. More...
 
struct  nda::clef::operation< tags::divides >
 Specialization of nda::clef::operation for nda::clef::tags::divides. More...
 
struct  nda::clef::operation< tags::eq >
 Specialization of nda::clef::operation for nda::clef::tags::eq. More...
 
struct  nda::clef::operation< tags::function >
 Specialization of nda::clef::operation for nda::clef::tags::function. More...
 
struct  nda::clef::operation< tags::geq >
 Specialization of nda::clef::operation for nda::clef::tags::geq. More...
 
struct  nda::clef::operation< tags::greater >
 Specialization of nda::clef::operation for nda::clef::tags::greater. More...
 
struct  nda::clef::operation< tags::if_else >
 Specialization of nda::clef::operation for nda::clef::tags::if_else. More...
 
struct  nda::clef::operation< tags::leq >
 Specialization of nda::clef::operation for nda::clef::tags::leq. More...
 
struct  nda::clef::operation< tags::less >
 Specialization of nda::clef::operation for nda::clef::tags::less. More...
 
struct  nda::clef::operation< tags::loginot >
 Specialization of nda::clef::operation for nda::clef::tags::loginot. More...
 
struct  nda::clef::operation< tags::minus >
 Specialization of nda::clef::operation for nda::clef::tags::minus. More...
 
struct  nda::clef::operation< tags::multiplies >
 Specialization of nda::clef::operation for nda::clef::tags::multiplies. More...
 
struct  nda::clef::operation< tags::negate >
 Specialization of nda::clef::operation for nda::clef::tags::negate. More...
 
struct  nda::clef::operation< tags::plus >
 Specialization of nda::clef::operation for nda::clef::tags::plus. More...
 
struct  nda::clef::operation< tags::subscript >
 Specialization of nda::clef::operation for nda::clef::tags::subscript. More...
 
struct  nda::clef::operation< tags::terminal >
 Specialization of nda::clef::operation for nda::clef::tags::terminal. More...
 
struct  nda::clef::operation< tags::unaryplus >
 Specialization of nda::clef::operation for nda::clef::tags::unaryplus. More...
 
struct  nda::clef::tags::binary_op
 Tag for binary operator expressions. More...
 
struct  nda::clef::tags::divides
 Tag for binary / expressions. More...
 
struct  nda::clef::tags::eq
 Tag for binary == expressions. More...
 
struct  nda::clef::tags::function
 Tag for function call expressions. More...
 
struct  nda::clef::tags::geq
 Tag for binary >= expressions. More...
 
struct  nda::clef::tags::greater
 Tag for binary > expressions. More...
 
struct  nda::clef::tags::if_else
 Tag for conditional expressions. More...
 
struct  nda::clef::tags::leq
 Tag for binary <= expressions. More...
 
struct  nda::clef::tags::less
 Tag for binary < expressions. More...
 
struct  nda::clef::tags::loginot
 Tag for unary ! expressions. More...
 
struct  nda::clef::tags::minus
 Tag for binary - expressions. More...
 
struct  nda::clef::tags::multiplies
 Tag for binary * expressions. More...
 
struct  nda::clef::tags::negate
 Tag for unary - expressions. More...
 
struct  nda::clef::tags::plus
 Tag for binary + expressions. More...
 
struct  nda::clef::tags::subscript
 Tag for subscript expressions. More...
 
struct  nda::clef::tags::terminal
 Tag to indicate a terminal node in the expression tree. More...
 
struct  nda::clef::tags::unary_op
 Tag for unary operator expressions. More...
 
struct  nda::clef::tags::unaryplus
 Tag for unary + expressions. More...
 

Macros

#define CLEF_IMPLEMENT_LAZY_CALL(...)
 Macro to make any function call operator lazy, i.e. accept lazy arguments and return a function call expression node.
 
#define CLEF_IMPLEMENT_LAZY_METHOD(TY, name)
 Macro to make any method lazy, i.e. accept lazy arguments and return a function call expression node.
 
#define CLEF_MAKE_FNT_LAZY(name)
 Macro to make any function lazy, i.e. accept lazy arguments and return a function call expression node.
 

Functions

template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::abs (A &&...__a)
 Lazy version of std::abs.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::acos (A &&...__a)
 Lazy version of std::acos.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::asin (A &&...__a)
 Lazy version of std::asin.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::atan (A &&...__a)
 Lazy version of std::atan.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::conj (A &&...__a)
 Lazy version of std::conj.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::cos (A &&...__a)
 Lazy version of std::cos.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::cosh (A &&...__a)
 Lazy version of std::cosh.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::exp (A &&...__a)
 Lazy version of std::exp.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::floor (A &&...__a)
 Lazy version of std::floor.
 
template<typename C , typename A , typename B >
__inline__ auto nda::clef::if_else (C &&c, A &&a, B &&b)
 Create a lazy ternary (if-else) expression.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::log (A &&...__a)
 Lazy version of std::log.
 
template<typename T >
auto nda::clef::make_expr (T &&t)
 Create a terminal expression node of an object.
 
template<typename F , typename... Args>
requires (is_any_lazy<Args...>)
auto nda::clef::make_expr_call (F &&f, Args &&...args)
 Create a function call expression from a callable object and a list of arguments.
 
template<typename T >
auto nda::clef::make_expr_from_clone (T &&t)
 Create a terminal expression node of an object.
 
template<typename T , typename... Args>
requires (is_any_lazy<Args...>)
auto nda::clef::make_expr_subscript (T &&t, Args &&...args)
 Create a subscript expression from an object and a list of arguments.
 
template<typename T , typename... Phs>
__inline__ auto nda::clef::make_function (T &&obj, Phs...)
 Factory function for nda::clef::make_fun_impl objects.
 
template<typename Tag , typename... Args>
__inline__ decltype(auto) nda::clef::op_dispatch (std::false_type, Args &&...args)
 Dispatch operations containing only non-lazy operands.
 
template<typename Tag , typename... Args>
__inline__ auto nda::clef::op_dispatch (std::true_type, Args &&...args)
 Dispatch operations containing at least one lazy operand.
 
template<typename L >
requires (is_any_lazy<L>)
__inline__ auto nda::clef::operator! (L &&l)
 Implementation of the lazy unary ! operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator* (L &&l, R &&r)
 Implementation of the lazy binary * operation.
 
template<typename L >
requires (is_any_lazy<L>)
__inline__ auto nda::clef::operator+ (L &&l)
 Implementation of the lazy unary + operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator+ (L &&l, R &&r)
 Implementation of the lazy binary + operation.
 
template<typename L >
requires (is_any_lazy<L>)
__inline__ auto nda::clef::operator- (L &&l)
 Implementation of the lazy unary - operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator- (L &&l, R &&r)
 Implementation of the lazy binary - operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator/ (L &&l, R &&r)
 Implementation of the lazy binary / operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator< (L &&l, R &&r)
 Implementation of the lazy binary < operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator<= (L &&l, R &&r)
 Implementation of the lazy binary <= operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator== (L &&l, R &&r)
 Implementation of the lazy binary == operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator> (L &&l, R &&r)
 Implementation of the lazy binary > operation.
 
template<typename L , typename R >
requires (is_any_lazy<L, R>)
__inline__ auto nda::clef::operator>= (L &&l, R &&r)
 Implementation of the lazy binary >= operation.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::pow (A &&...__a)
 Lazy version of std::pow.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::sin (A &&...__a)
 Lazy version of std::sin.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::sinh (A &&...__a)
 Lazy version of std::sinh.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::sqrt (A &&...__a)
 Lazy version of std::sqrt.
 
template<typename Expr , int N, typename D >
decltype(auto) nda::clef::sum (Expr const &ex, clef::pair< N, D > d)
 Sum an expression over a 1-dimensional domain.
 
template<typename Expr , typename D0 , typename D1 , typename... Ds>
auto nda::clef::sum (Expr const &ex, D0 &&d0, D1 &&d1, Ds &&...ds)
 Sum an expression over a multi-dimensional domain.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::tan (A &&...__a)
 Lazy version of std::tan.
 
template<typename... A>
requires (nda::clef::is_any_lazy<A...>)
auto nda::clef::tanh (A &&...__a)
 Lazy version of std::tanh.
 

Function Documentation

◆ if_else()

template<typename C , typename A , typename B >
__inline__ auto nda::clef::if_else ( C && c,
A && a,
B && b )

#include <nda/clef/operation.hpp>

Create a lazy ternary (if-else) expression.

Template Parameters
CType of the conditional expression.
AType of the return expression when the condition is true.
BType of the return expression when the condition is false.
Parameters
cConditional expression.
aReturn expression when the condition is true.
bReturn expression when the condition is false.
Returns
An nda::clef::expr object with the nda::clef::tags::ternary tag and the given operands forwarded as its child nodes.

Definition at line 222 of file operation.hpp.

◆ make_expr()

template<typename T >
auto nda::clef::make_expr ( T && t)

#include <nda/clef/make_lazy.hpp>

Create a terminal expression node of an object.

Template Parameters
TType of the object.
Parameters
tGiven object.
Returns
An nda::clef::expr with the nda::clef::tags::terminal tag containing either a copy of the object itself (if it is moved) or a reference to the object.

Definition at line 45 of file make_lazy.hpp.

◆ make_expr_call()

template<typename F , typename... Args>
requires (is_any_lazy<Args...>)
auto nda::clef::make_expr_call ( F && f,
Args &&... args )

#include <nda/clef/make_lazy.hpp>

Create a function call expression from a callable object and a list of arguments.

Note that this is equivalent to nda::clef::make_expr(t)(args...).

Template Parameters
FType of the callable object.
ArgsTypes of the arguments.
Parameters
fCallable object.
argsFunction arguments.
Returns
An nda::clef::expr with the nda::clef::tags::function tag containing the callable and the forwarded arguments.

Definition at line 74 of file make_lazy.hpp.

◆ make_expr_from_clone()

template<typename T >
auto nda::clef::make_expr_from_clone ( T && t)

#include <nda/clef/make_lazy.hpp>

Create a terminal expression node of an object.

Template Parameters
TType of the object.
Parameters
tGiven object.
Returns
An nda::clef::expr with the nda::clef::tags::terminal tag containing a copy of the object.

Definition at line 57 of file make_lazy.hpp.

◆ make_expr_subscript()

template<typename T , typename... Args>
requires (is_any_lazy<Args...>)
auto nda::clef::make_expr_subscript ( T && t,
Args &&... args )

#include <nda/clef/make_lazy.hpp>

Create a subscript expression from an object and a list of arguments.

Note that this is equivalent to nda::clef::make_expr(t)[args...].

Template Parameters
TType of the object to be subscripted.
ArgsTypes of the arguments.
Parameters
tObject to be subscripted.
argsSubscript arguments.
Returns
An nda::clef::expr with the nda::clef::tags::subscript tag containing the subscriptable object and the forwarded arguments.

Definition at line 93 of file make_lazy.hpp.

◆ make_function()

template<typename T , typename... Phs>
__inline__ auto nda::clef::make_function ( T && obj,
Phs...  )

#include <nda/clef/function.hpp>

Factory function for nda::clef::make_fun_impl objects.

The given arguments are used to construct a new nda::clef::make_fun_impl object. The first argument is forwarded to its constructor and the integer labels of the remaining placeholder arguments are used in its template argument list.

The following example shows how to turn a binary lazy expression ex into a callable object f that takes two arguments:

auto ex = i_ + j_;
auto f = nda::clef::make_function(ex, i_, j_);
auto res = f(1, 2); // int res = 3;
auto res2 = f(1.5, 2); // double res2 = 3.5;
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition function.hpp:100
A placeholder is an empty struct, labelled by an int.
Note
There is no check if the given placeholders actually match placeholders in the object to be evaluated.
Template Parameters
TType of the object.
PhsTypes of the placeholders.
Parameters
objObject to be stored in the nda::clef::make_fun_impl object.
Returns
A callable nda::clef::make_fun_impl object that takes as many arguments as placeholders were given.

Definition at line 100 of file function.hpp.

◆ op_dispatch() [1/2]

template<typename Tag , typename... Args>
__inline__ decltype(auto) nda::clef::op_dispatch ( std::false_type ,
Args &&... args )

#include <nda/clef/operation.hpp>

Dispatch operations containing only non-lazy operands.

Since all operands are non-lazy, the operation is performed immediately by calling the corresponding nda::clef::operation with the forwarded operands.

Template Parameters
TagTag of the operation.
ArgsTypes of the operands.
Parameters
argsOperands.
Returns
Result of actually performing the operation on the operands.

Definition at line 255 of file operation.hpp.

◆ op_dispatch() [2/2]

template<typename Tag , typename... Args>
__inline__ auto nda::clef::op_dispatch ( std::true_type ,
Args &&... args )

#include <nda/clef/operation.hpp>

Dispatch operations containing at least one lazy operand.

Since at least one operand is lazy, the operation is not performed immediately. Instead, a new nda::clef::expr object is created with the given operation and operands.

Template Parameters
TagTag of the operation.
ArgsTypes of the operands.
Parameters
argsOperands.
Returns
An nda::clef::expr for the given operation and operands.

Definition at line 239 of file operation.hpp.

◆ sum() [1/2]

template<typename Expr , int N, typename D >
decltype(auto) nda::clef::sum ( Expr const & ex,
clef::pair< N, D > d )

#include <nda/clef/sum.hpp>

Sum an expression over a 1-dimensional domain.

The following example sums the squared elements of a vector:

auto domain = std::vector{1, 2, 3};
auto ex = i_ * i_;
auto res = nda::clef::sum(ex, i_ = domain); // int res = 14;
decltype(auto) sum(Expr const &ex, clef::pair< N, D > d)
Sum an expression over a 1-dimensional domain.
Definition sum.hpp:76
Template Parameters
ExprType of the expression.
NInteger label of the placeholder to be replaced by the domain.
DType of the domain.
Parameters
exLazy expression.
dPair containing the nda::clef::placeholder and the domain.
Returns
Either the result of the summation or a new lazy expression.

Definition at line 76 of file sum.hpp.

◆ sum() [2/2]

template<typename Expr , typename D0 , typename D1 , typename... Ds>
auto nda::clef::sum ( Expr const & ex,
D0 && d0,
D1 && d1,
Ds &&... ds )

#include <nda/clef/sum.hpp>

Sum an expression over a multi-dimensional domain.

The following example sums an expression over a 2-dimensional domain:

auto domain1 = std::vector{1, 2, 3};
auto domain2 = std::vector{4, 5, 6};
auto ex = i_ + j_;
auto res = nda::clef::sum(ex, i_ = domain1, j_ = domain2); // int res = 63;
Template Parameters
ExprType of the expression.
D0nda::clef::pair type.
D1nda::clef::pair type.
DsParameter pack of the remaining nda::clef::pair types.
Parameters
exLazy expression.
d0Pair containing an nda::clef::placeholder and a domain.
d1Pair containing an nda::clef::placeholder and another domain.
dsParameter pack of the remaining pairs.
Returns
Either the result of the summation or a new lazy expression.

Definition at line 109 of file sum.hpp.