44 using utility::is_in_ZRC;
48 namespace details_bgfs_expr {
52 template <
typename S>
struct scalar_wrap {
54 using target_t = void;
59 int size()
const {
return -1; }
60 int size1()
const {
return -1; }
61 int size2()
const {
return -1; }
64 template <
typename T> scalar_wrap(T &&x) : s(std::forward<T>(x)) {}
66 template <
typename... Keys> S operator[](Keys &&...)
const {
return s; }
68 template <
typename... Args>
inline S
operator()(Args &&...)
const {
return s; }
70 friend std::ostream &operator<<(std::ostream &sout, scalar_wrap
const &expr) {
return sout << expr.s; }
74 template <
typename T>
using node_t = std::conditional_t<utility::is_in_ZRC<T>::value, scalar_wrap<T>,
remove_rvalue_ref_t<T>>;
77 template <
typename A,
typename B>
struct same_or_void {
80 template <
typename A>
struct same_or_void<A, A> {
83 template <
typename A>
struct same_or_void<void, A> {
86 template <
typename A>
struct same_or_void<A, void> {
89 template <>
struct same_or_void<void, void> {
109 using L_t = std::decay_t<L>;
112 using R_t = std::decay_t<R>;
115 using mesh_t =
typename details_bgfs_expr::same_or_void<typename L_t::mesh_t, typename R_t::mesh_t>::type;
118 using target_t =
typename details_bgfs_expr::same_or_void<typename L_t::target_t, typename R_t::target_t>::type;
120 static_assert(!std::is_same<mesh_t, void>::value,
"Cannot combine two gf expressions with different variables");
121 static_assert(!std::is_same<target_t, void>::value,
"Cannot combine two gf expressions with different target");
141 template <
typename LL,
typename RR>
bgf_expr(LL &&l_, RR &&r_) :
l(std::forward<LL>(l_)),
r(std::forward<RR>(r_)) {}
147 auto size()
const {
return std::max(
l.size(),
r.size()); }
153 auto size1()
const {
return std::max(
l.size1(),
r.size1()); }
159 auto size2()
const {
return std::max(
l.size2(),
r.size2()); }
166 if constexpr (std::is_void_v<typename L_t::mesh_t>)
167 return r.block_names();
169 return l.block_names();
179 template <
typename... Keys>
decltype(
auto)
operator[](Keys &&...keys)
const {
189 template <
typename... Args>
decltype(
auto)
operator()(Args &&...args)
const {
206 using L_t = std::decay_t<L>;
230 auto size()
const {
return l.size(); }
239 template <
typename... Keys>
auto operator[](Keys &&...keys)
const {
return -
l.operator[](std::forward<Keys>(keys)...); }
242 template <
typename... Args>
auto operator()(Args &&...args)
const {
return -
l(std::forward<Args>(args)...); }
252#define DEFINE_OPERATOR(TAG, OP, TRAIT1, TRAIT2) \
253 template <typename A1, typename A2> \
254 std::enable_if_t<TRAIT1<A1>::value && TRAIT2<A2>::value, \
255 bgf_expr<utility::tags::TAG, details_bgfs_expr::node_t<A1>, details_bgfs_expr::node_t<A2>>> \
256 operator OP(A1 &&a1, A2 &&a2) { \
257 return {std::forward<A1>(a1), std::forward<A2>(a2)}; \
261 DEFINE_OPERATOR(plus, +, BlockGreenFunction, BlockGreenFunction);
262 DEFINE_OPERATOR(minus, -, BlockGreenFunction, BlockGreenFunction);
263 DEFINE_OPERATOR(multiplies, *, BlockGreenFunction, BlockGreenFunction);
264 DEFINE_OPERATOR(multiplies, *,
is_in_ZRC, BlockGreenFunction);
265 DEFINE_OPERATOR(multiplies, *, BlockGreenFunction,
is_in_ZRC);
266 DEFINE_OPERATOR(divides, /, BlockGreenFunction, BlockGreenFunction);
267 DEFINE_OPERATOR(divides, /,
is_in_ZRC, BlockGreenFunction);
268 DEFINE_OPERATOR(divides, /, BlockGreenFunction,
is_in_ZRC);
269#undef DEFINE_OPERATOR
273 template <
typename A1>
274 requires(BlockGreenFunction<A1>::value)
275 auto operator-(A1 &&a1) {
283#define DEFINE_OPERATOR(OP1, OP2) \
284 template <typename Mesh, typename Target, typename Layout, int Arity, typename T> \
285 void operator OP1(block_gf_view<Mesh, Target, Layout, Arity> g, T const &x) { \
288 template <typename Mesh, typename Target, typename Layout, int Arity, typename T> \
289 void operator OP1(block_gf<Mesh, Target, Layout, Arity> &g, T const &x) { \
293 DEFINE_OPERATOR(+=, +);
294 DEFINE_OPERATOR(-=, -);
295 DEFINE_OPERATOR(*=, *);
296 DEFINE_OPERATOR(/=, /);
298#undef DEFINE_OPERATOR
int size2() const
Get the number of blocks along the second index (block2_gf only).
const_view_type operator()() const
Make a const view of *this.
int size1() const
Get the number of blocks along the first index (block2_gf only).
int size() const
Get the total number of blocks.
Provides a non-owning view of a block Green's function.
constexpr int arity_of
Block arity of a type: T::arity if present, -1 otherwise.
#define TRIQS_CONCEPT_TAG_NAME(MyBeautifulConcept)
Helper macro that produces the name of the tag for TRIQS_DEFINE_CONCEPT_AND_ASSOCIATED_TRAIT.
typename remove_rvalue_ref< T >::type remove_rvalue_ref_t
Alias for the nested type in remove_rvalue_ref.
std::decay_t< R > R_t
Decayed type of the right operand.
typename details_bgfs_expr::same_or_void< typename L_t::target_t, typename R_t::target_t >::type target_t
Target type of the expression, deduced from the two operands.
auto size1() const
Get the number of blocks along the first dimension (for a block2 expression).
auto block_names() const
Get the block names of the expression.
typename details_bgfs_expr::same_or_void< typename L_t::mesh_t, typename R_t::mesh_t >::type mesh_t
Mesh type of the expression, deduced from the two operands.
bgf_expr(LL &&l_, RR &&r_)
Construct from the two operands.
friend std::ostream & operator<<(std::ostream &sout, bgf_expr const &expr)
Stream output of the expression.
std::decay_t< L > L_t
Decayed type of the left operand.
static constexpr int arity
Block arity of the expression (1 for triqs::gfs::block_gf, 2 for triqs::gfs::block2_gf).
auto size() const
Get the number of blocks of the expression.
auto size2() const
Get the number of blocks along the second dimension (for a block2 expression).
Lazy expression node representing the unary minus of a block Green's function operand.
auto operator[](Keys &&...keys) const
Evaluate the negated expression via subscript.
bgf_unary_m_expr(LL &&l_)
Construct from the operand.
auto size() const
Get the number of blocks of the expression.
auto operator()(Args &&...1) const
Evaluate the negated expression via call.
friend std::ostream & operator<<(std::ostream &sout, bgf_unary_m_expr const &expr)
Stream output of the expression.
std::decay_t< L > L_t
Decayed type of the operand.
auto block_names() const
Get the block names of the expression.
typename L_t::mesh_t mesh_t
Mesh type of the expression.
typename L_t::target_t target_t
Target type of the expression.
Trait identifying types that lie in .
Callable wrapper that evaluates the operation identified by Tag on two operands.