3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 13:53:40 +01:00

[clef] Fix placeholder () and [] operators

- had been forgotten.
- modified g(k,om) test
This commit is contained in:
Olivier Parcollet 2014-09-18 22:46:27 +02:00
parent c7a1a25846
commit c9a5856fb8
5 changed files with 26 additions and 6 deletions

View File

@ -1,3 +1,3 @@
link_libraries (triqs) link_libraries (triqs)
all_tests() all_tests()
add_subdirectory(multivar)

View File

@ -23,9 +23,13 @@ int main() {
// try to assign to expression // try to assign to expression
placeholder<0> k_; placeholder<0> k_;
placeholder<1> w_; placeholder<1> w_;
auto eps = make_expr( [](k_t const& k) { return -2 * (cos(k(0)) + cos(k(1))); }) ;
G(k_, w_) << 1 / (w_ - eps(k_) - 1 / (w_ + 2)); auto eps_k = -2 * (cos(k_(0)) + cos(k_(1)));
G(k_, w_) << 1 / (w_ - eps_k - 1 / (w_ + 2));
// same
// auto eps = make_expr( [](k_t const& k) { return -2 * (cos(k(0)) + cos(k(1))); }) ;
// G(k_, w_) << 1 / (w_ - eps(k_) - 1 / (w_ + 2));
// hdf5 // hdf5
h5::file file("ess_g_k_om.h5", H5F_ACC_TRUNC); h5::file file("ess_g_k_om.h5", H5F_ACC_TRUNC);

View File

@ -59,12 +59,19 @@ namespace triqs { namespace clef {
* Placeholder and corresponding traits * Placeholder and corresponding traits
* --------------------------------------------------------------------------------------------------- */ * --------------------------------------------------------------------------------------------------- */
template<int i, typename T> struct pair; // forward template<int i, typename T> struct pair; // forward
template<typename Tag, typename... T> struct expr; //forward
// a placeholder is an empty struct, labelled by an int. // a placeholder is an empty struct, labelled by an int.
template<int N> struct placeholder { template<int N> struct placeholder {
static_assert( (N>=0) && (N<64) , "Placeholder number limited to [0,63]"); static_assert( (N>=0) && (N<64) , "Placeholder number limited to [0,63]");
static constexpr int index = N; static constexpr int index = N;
template <typename RHS> pair<N,RHS> operator = (RHS && rhs) { return {std::forward<RHS>(rhs)};} template <typename RHS> pair<N,RHS> operator = (RHS && rhs) { return {std::forward<RHS>(rhs)};}
template <typename... T> expr<tags::function, placeholder, expr_storage_t<T>...> operator()(T&&... x) const {
return {tags::function{}, *this, std::forward<T>(x)...};
}
template <typename T> expr<tags::subscript, placeholder, expr_storage_t<T>> operator[](T&& x) const {
return {tags::subscript{}, *this, std::forward<T>(x)};
}
}; };
// placeholder will always be copied (they are empty anyway). // placeholder will always be copied (they are empty anyway).

View File

@ -58,12 +58,19 @@ namespace triqs { namespace clef {
* Placeholder and corresponding traits * Placeholder and corresponding traits
* --------------------------------------------------------------------------------------------------- */ * --------------------------------------------------------------------------------------------------- */
template<int i, typename T> struct pair; // forward template<int i, typename T> struct pair; // forward
template<typename Tag, typename... T> struct expr; //forward
// a placeholder is an empty struct, labelled by an int. // a placeholder is an empty struct, labelled by an int.
template<int N> struct placeholder { template<int N> struct placeholder {
static_assert( (N>=0) && (N<64) , "Placeholder number limited to [0,63]"); static_assert( (N>=0) && (N<64) , "Placeholder number limited to [0,63]");
static constexpr int index = N; static constexpr int index = N;
template <typename RHS> pair<N,RHS> operator = (RHS && rhs) { return {std::forward<RHS>(rhs)};} template <typename RHS> pair<N,RHS> operator = (RHS && rhs) { return {std::forward<RHS>(rhs)};}
template <typename... T> expr<tags::function, placeholder, expr_storage_t<T>...> operator()(T&&... x) const {
return {tags::function{}, *this, std::forward<T>(x)...};
}
template <typename T> expr<tags::subscript, placeholder, expr_storage_t<T>> operator[](T&& x) const {
return {tags::subscript{}, *this, std::forward<T>(x)};
}
}; };
// placeholder will always be copied (they are empty anyway). // placeholder will always be copied (they are empty anyway).

View File

@ -68,6 +68,8 @@ namespace lattice {
long index() const { return _index; } long index() const { return _index; }
bool at_end() const { return (_index == m->size()); } bool at_end() const { return (_index == m->size()); }
void reset() { _index = 0; } void reset() { _index = 0; }
double operator()(int i) const { return m->index_to_point(_index)(i);}
double operator[](int i) const { return m->index_to_point(_index)(i);}
}; };
/// Accessing a point of the mesh /// Accessing a point of the mesh