diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index ff1f80e1..363644b1 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -19,49 +19,9 @@ else (Sphinx_Math_Generator_MathJax) endif (Sphinx_Math_Generator_MathJax) # the local extensions.... -file(COPY ../foreignlibs/breathe ../foreignlibs/doxylink ../foreignlibs/mpl ../foreignlibs/autocompile DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ../foreignlibs/breathe ../foreignlibs/doxylink ../foreignlibs/mpl ../foreignlibs/autorun ../foreignlibs/triqs_example DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -# The compiler flags for autocompile -set(TRIQS_LIBRARY_ALL ${TRIQS_LIBRARY_BOOST} ${TRIQS_LIBRARY_PYTHON} ${TRIQS_LIBRARY_MPI} ${TRIQS_LIBRARY_HDF5} ${TRIQS_LIBRARY_LAPACK} ${TRIQS_LIBRARY_FFTW} ${TRIQS_LIBRARY_GMP} ${TRIQS_LIBRARY_GSL} ) -set(TRIQS_INCLUDE_ALL ${TRIQS_INCLUDE_BOOST} ${TRIQS_INCLUDE_PYTHON} ${TRIQS_INCLUDE_MPI} ${TRIQS_INCLUDE_HDF5} ${TRIQS_INCLUDE_LAPACK} ${TRIQS_INCLUDE_FFTW} ${TRIQS_INCLUDE_GMP} ${TRIQS_INCLUDE_GSL} ) - -set( link_libs " ${TRIQS_LIBRARY_ALL}") -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - list (REMOVE_DUPLICATES link_libs) -endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") -string(REPLACE "debug" " " TMP "${link_libs}") -string(REPLACE "optimized" " " TMP "${TMP}") - -set(DOC_AUTOCOMPILE_INCLUDE ${CMAKE_SOURCE_DIR} ${TRIQS_INCLUDE_ALL}) -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(DOC_AUTOCOMPILE_LINK "${TRIQS_LIBRARY_BOOST} -L ${CMAKE_BINARY_DIR}/triqs -ltriqs ${TMP}") - set(DOC_AUTOCOMPILE_DEFINITIONS -std=c++0x -DBOOST_PP_VARIADICS=1 -stdlib=libc++ -I/System/Library/Frameworks/vecLib.framework/Versions/A/Headers) -else() - set(DOC_AUTOCOMPILE_LINK "${TRIQS_LIBRARY_BOOST} -L ${CMAKE_BINARY_DIR}/triqs -ltriqs ${TMP} -Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR} ") - set(DOC_AUTOCOMPILE_DEFINITIONS -std=c++0x -DBOOST_PP_VARIADICS=1 ) -endif() -set(DOC_AUTOCOMPILE_LD_LIBRARY_PATH "${CMAKE_BINARY_DIR}/triqs") -set(DOC_AUTOCOMPILE_DEFINITIONS ${DOC_AUTOCOMPILE_DEFINITIONS} -DTRIQS_BUILDING_LIBRARY -I ${CMAKE_BINARY_DIR}/Config ) - -# debug -#message( " Link libs ${DOC_AUTOCOMPILE_LINK}") - -EXECUTE_PROCESS(COMMAND sh -c "ln -sf ${CMAKE_BINARY_DIR}/triqs/libtriqs.so ${CMAKE_CURRENT_BINARY_DIR}") - -# Dive and find the doxygen sources -add_subdirectory(reference/c++) - -# Build the doxygen -set(DOXYGEN_HTML_OUTPUT ./html/doxy_triqs) -find_package(Doxygen REQUIRED) - -# debug -get_property(DOXYGEN_SOURCES GLOBAL PROPERTY DOXYGEN_SOURCES) -string(REPLACE ";" " " DOXYGEN_SOURCES_LIST "${DOXYGEN_SOURCES}") -#message(STATUS "Doxygen sources are ${DOXYGEN_SOURCES}") - -# Prepare the Doxyfile -configure_file(${TRIQS_SOURCE_DIR}/cmake/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) +#EXECUTE_PROCESS(COMMAND sh -c "ln -sf ${CMAKE_BINARY_DIR}/triqs/libtriqs.so ${CMAKE_CURRENT_BINARY_DIR}") # Generate the conf.py FILE(GLOB_RECURSE SOURCES *.rst) @@ -70,6 +30,41 @@ EXECUTE_PROCESS(COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/html") set(DOC_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}) include(${TRIQS_SOURCE_DIR}/cmake/BuildSphinx.cmake) +# for the C++ compilation of tests +include_directories( ${CMAKE_SOURCE_DIR} ) + +#set( link_libs " ${TRIQS_LIBRARY_ALL}") +SET( link_libs ${LAPACK_LIBS} ${BOOST_LIBRARY} ) +IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list (REMOVE_DUPLICATES link_libs) +ENDIF( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +link_libraries( ${link_libs} triqs) + +macro(all_tests ) +FILE(GLOB ExampleList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +FOREACH(example ${ExampleList}) + STRING(REPLACE ".cpp" "" example_short ${example}) + add_executable( doc_${example_short} ${CMAKE_CURRENT_SOURCE_DIR}/${example}) + add_dependencies(docs_sphinx doc_${example_short}) ## so that all code examples are compiled before the doc + add_test_C_simple( doc_${example_short} ) + #add_test ( ${example_short} ${example_short}) +ENDFOREACH() +endmacro() + +# Dive and find the doxygen sources +add_subdirectory(reference/c++) +add_subdirectory(tutorials/c++) + +# Build the doxygen +set(DOXYGEN_HTML_OUTPUT ./html/doxy_triqs) +find_package(Doxygen REQUIRED) +get_property(DOXYGEN_SOURCES GLOBAL PROPERTY DOXYGEN_SOURCES) +string(REPLACE ";" " " DOXYGEN_SOURCES_LIST "${DOXYGEN_SOURCES}") +#message(STATUS "Doxygen sources are ${DOXYGEN_SOURCES}") + +# Prepare the Doxyfile +configure_file(${TRIQS_SOURCE_DIR}/cmake/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + # Set dependencies GET_PROPERTY(PYTHON_DYNAMIC_MODULES_LIST GLOBAL PROPERTY PYTHON_DYNAMIC_MODULES_LIST) foreach (mod ${PYTHON_DYNAMIC_MODULES_LIST}) diff --git a/doc/_tools/split_code.py b/doc/_tools/split_code.py new file mode 100644 index 00000000..c1236646 --- /dev/null +++ b/doc/_tools/split_code.py @@ -0,0 +1,49 @@ +import glob,re,os + +def work(arg, dirname, names): + + for fil in glob.glob(dirname+ "/*.rst") : + + fi = fil[:-4] + lines = open(fil).readlines() + out = open(fi + ".rst", 'w') + def get_decal(line) : return len(line) - len(line.lstrip()) + + reading = False + ex_list = [] + for line in lines : + + if re.match("\s*.. compileblock\s*::.*",line) : + assert not reading + decal = get_decal(line) + reading = True + current_ex = [] + out.write(decal*' ' + ".. triqs_example:: ./" + fi.rsplit('/',1)[-1] + "_%s"%len(ex_list) + ".cpp\n") + continue + + if reading : + if line.strip()=='' or get_decal(line) > decal : + current_ex.append(line) + continue + else : + reading = False + ex_list.append(current_ex) + + out.write(line) + + if reading : ex_list.append(current_ex) + + for n,ex in enumerate(ex_list) : + filename = fi + "_%s.cpp"%n + out = open(filename,'w') + print filename + for l in ex : + out.write(l) + #os.system("vim -c '% + +os.path.walk('./', work, None) + +# then +#find . -name "*_?.cpp" | xargs mvim +#macro ggVG Ctrl K +# :bufdo execute "normal! @a" | w:bufdo execute "normal! @a" | w diff --git a/doc/conf.py.in b/doc/conf.py.in index d8644264..4e376935 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -22,7 +22,7 @@ import sys, os # --------------------- sys.path +=[ #"@CMAKE_BINARY_DIR@/doc/breathe", -"@CMAKE_BINARY_DIR@/doc/mpl","@CMAKE_BINARY_DIR@/doc/autocompile", +"@CMAKE_BINARY_DIR@/doc/mpl", "@CMAKE_BINARY_DIR@/doc/autorun", "@CMAKE_BINARY_DIR@/doc/triqs_example", "@CMAKE_BINARY_DIR@/doc/sandbox","@CMAKE_BINARY_DIR@/doc"] # Add any Sphinx extension module names here, as strings. They can be extensions @@ -40,15 +40,7 @@ extensions += [ # 'inheritance_diagram', 'numpydoc'] -extensions += ['autocompile','autorun'] - -##options for autocompile module: c++ execution -autocompile_opts = dict(compiler = "@CMAKE_CXX_COMPILER@", - link = "@DOC_AUTOCOMPILE_LINK@".replace(';',' '), - ld_library_path = "@DOC_AUTOCOMPILE_LD_LIBRARY_PATH@".replace(';',' '), - include =''.join([ " -I%s"%arg for arg in "@DOC_AUTOCOMPILE_INCLUDE@".split(';')] ), - definitions =''.join([ " %s"%arg for arg in "@DOC_AUTOCOMPILE_DEFINITIONS@".split(';')] ) - ) +extensions += ['autorun', 'triqs_example'] ##options for autorun module: python execution autorun_languages = {} diff --git a/doc/overview.rst b/doc/overview.rst deleted file mode 100644 index 517acd81..00000000 --- a/doc/overview.rst +++ /dev/null @@ -1,209 +0,0 @@ -TRIQS in a nutshell -=================== - -TRIQS is a toolbox containing **ready-to-use applications**, **python modules** as well as **C++ libraries** aimed at physicists in the field of quantum interacting systems. - -Applications ------------- - -Interface to Wien2k for LDA+DMFT calculation -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -TRIQS allows you to turn band-structure calculations obtained from the Wien2k package to inputs to full-fledged LDA+DMFT calculations in a few lines! - - - -[example here] - -To learn more, see - -Solvers for impurity models -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -TRIQS comes with powerful numerical solvers for quantum impurity models. - - -[example here] - -To learn more, see - -Python modules --------------- - -Green's functions -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -With TRIQS, the manipulation of Green's functions is made easy: construction of Green's functions in frequency and time domains (imaginary and real), Fourier transforms, visualization, tail computation... - - - -.. runblock:: python - - # Import the Green's functions - from pytriqs.gf.local import GfImFreq, iOmega_n, inverse - - # Create the Matsubara-frequency Green's function and initialize it - gw = GfImFreq(indices = [1], beta = 50, n_points = 1000, name = "imp") - gw <<= inverse( iOmega_n + 0.5 ) - - - # Create an imaginary-time Green's function and plot it - gt = GFBloc_ImTime(Indices = [1], Beta = 50) - gt <<= InverseFourier(gw) - - #from pytriqs.plot.mpl_interface import oplot - #oplot(g, '-o', x_window = (0,10)) - - print gt(0.5) - - -To learn more, see - -Lattice tools -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -With TRIQS, build a tight-binding model on any lattice in a few lines, and extract its density of states, dispersion... - - -[example here] - -.. runblock:: python - - print 2+2 # this will give output - - -To learn more, see - -C++ libraries -------------- - - -Monte-Carlo library -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Set up a Monte-Carlo simulation in a few lines: you write the configuration, moves and measures, while TRIQS takes care of the Metropolis algorithm and parallelization of the code. - - -.. compileblock:: - - #include - #include - #include - - // the configuration: a spin, the inverse temperature, the external field - struct configuration { - int spin; double beta, h; - configuration(double beta_, double h_) : spin(-1), beta(beta_), h(h_) {} - }; - - // a move: flip the spin - struct flip { - configuration & config; - - flip(configuration & config_) : config(config_) {} - - double attempt() { return std::exp(-2*config.spin*config.h*config.beta); } - double accept() { config.spin*= -1; return 1.0; } - void reject() {} - }; - - // a measurement: the magnetization - struct compute_m { - configuration & config; - double Z, M; - - compute_m(configuration & config_) : config(config_), Z(0), M(0) {} - - void accumulate(double sign) { Z += sign; M += sign * config.spin; } - - void collect_results(boost::mpi::communicator const &c) { - double sum_Z, sum_M; - boost::mpi::reduce(c, Z, sum_Z, std::plus(), 0); - boost::mpi::reduce(c, M, sum_M, std::plus(), 0); - - if (c.rank() == 0) { - std::cout << "Magnetization: " << sum_M / sum_Z << std::endl << std::endl; - } - } - }; - - int main(int argc, char* argv[]) { - - // initialize mpi - boost::mpi::environment env(argc, argv); - boost::mpi::communicator world; - - // greeting - if (world.rank() == 0) std::cout << "Isolated spin" << std::endl; - - // prepare the MC parameters - int N_Cycles = 500000; - int Length_Cycle = 10; - int N_Warmup_Cycles = 1000; - std::string Random_Name = ""; - int Random_Seed = 374982 + world.rank() * 273894; - int Verbosity = (world.rank() == 0 ? 2 : 0); - - // construct a Monte Carlo loop - triqs::mc_tools::mc_generic SpinMC(N_Cycles, Length_Cycle, N_Warmup_Cycles, - Random_Name, Random_Seed, Verbosity); - - // parameters of the model - double beta = 0.3; - double field = 0.5; - - // construct configuration - configuration config(beta, field); - - // add moves and measures - SpinMC.add_move(flip(config), "flip move"); - SpinMC.add_measure(compute_m(config), "magnetization measure"); - - // Run and collect results - SpinMC.start(1.0, triqs::utility::clock_callback(600)); - SpinMC.collect_results(world); - - return 0; - } - -To learn more, see - -Array library -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Create, manipulate and store powerful multi-dimensional arrays: - - -.. highlight:: c - - -.. compileblock:: - - #include - using triqs::arrays::array; - int main(){ - array A(20); - } - -To learn more, see - -Expression library: CLEF -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Write mathematical expressions in a seamless and computationally efficient way: - - - .. compileblock:: - - #include - int main () { - triqs::clef::placeholder <1> x_; - - auto e1 = cos(2*x_+1); - auto e2 = abs(2*x_-1); - auto e3 = floor(2*x_-1); - auto e4 = pow(2*x_+1,2); - } - - -To learn more, see diff --git a/doc/reference/c++/CMakeLists.txt b/doc/reference/c++/CMakeLists.txt index e2bc51d3..a0f81c22 100644 --- a/doc/reference/c++/CMakeLists.txt +++ b/doc/reference/c++/CMakeLists.txt @@ -1,3 +1,4 @@ + add_all_subdirectories_with_cmakelist() diff --git a/doc/reference/c++/arrays/CMakeLists.txt b/doc/reference/c++/arrays/CMakeLists.txt index 12643128..7dd9c19b 100644 --- a/doc/reference/c++/arrays/CMakeLists.txt +++ b/doc/reference/c++/arrays/CMakeLists.txt @@ -8,3 +8,7 @@ set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES #${TRIQS_SOURCE_DIR}/triqs/arrays/vector.hpp ) +all_tests() +add_subdirectory(containers) + + diff --git a/doc/reference/c++/arrays/IO.rst b/doc/reference/c++/arrays/IO.rst index 2332206d..361aa047 100644 --- a/doc/reference/c++/arrays/IO.rst +++ b/doc/reference/c++/arrays/IO.rst @@ -14,26 +14,4 @@ MPI The `value classes` (array, matrix, vector) can be bcasted, reduced, with the boost.mpi library, e.g. : -.. compileblock:: - - #include - #include - using triqs::arrays::array;using triqs::clef::placeholder; - - int main() { - boost::mpi::environment env;//argc, argv); - boost::mpi::communicator world; - - array A (2,2), B(2,2),C(2,2); - placeholder<0> i_; placeholder<1> j_; - A(i_,j_) << (1+world.rank())*(10*i_+ j_); - - if (world.rank() ==0) std::cout<<" A = "< >(),0); - - int s= world.size(); - if (world.rank() ==0) std::cout<<" C = "<( (s*(s+1)/2) * A) < +#include +using triqs::arrays::array; +using triqs::clef::placeholder; + +int main() { + boost::mpi::environment env; // argc, argv); + boost::mpi::communicator world; + + array A(2, 2), B(2, 2), C(2, 2); + placeholder<0> i_; + placeholder<1> j_; + A(i_, j_) << (1 + world.rank()) * (10 * i_ + j_); + + if (world.rank() == 0) std::cout << " A = " << A << std::endl; + + boost::mpi::reduce(world, A, C, std::plus>(), 0); + + int s = world.size(); + if (world.rank() == 0) std::cout << " C = " << C << " should be " << array((s * (s + 1) / 2) * A) << std::endl; +} + diff --git a/doc/reference/c++/arrays/algebras.rst b/doc/reference/c++/arrays/algebras.rst index dabaaeb0..d8086bad 100644 --- a/doc/reference/c++/arrays/algebras.rst +++ b/doc/reference/c++/arrays/algebras.rst @@ -10,26 +10,7 @@ Arrays and matrices can be combined in formal algebraic expressions, which model This algebraic expressions can therefore be used in assignment array/matrix contructors. For example: -.. compileblock:: - - #include - using triqs::arrays::array; using triqs::clef::placeholder; - int main() { - // init - placeholder<0> i_; placeholder<1> j_; - array A (2,2), B(2,2); - A(i_,j_) << i_ + j_ ; - B(i_,j_) << i_ - j_ ; - - // use expressions - array C = A+ 2*B; - array D = 0.5 * A; // Type promotion is automatic - std::cout<< "A= "<< A<< std::endl; - std::cout<< "B= "<< B<< std::endl; - std::cout<< "C= "<< C<< std::endl; - std::cout<< "D= "<< D<< std::endl; - } - +.. triqs_example:: ./algebras_0.cpp Arrays vs matrices ---------------------- @@ -37,16 +18,7 @@ Because their multiplication is not the same, arrays and matrices algebras can n Mixing them in expression would therefore be meaningless and it is therefore not allowed. However, you can always use e.g. `matrix_view` from a array of rank 2 : -.. compileblock:: - - #include - using namespace triqs::arrays; - int main() { - array A(2,2); matrix M(2,2); - //M + A; // --> ERROR. Rejected by the compiler. - M + make_matrix_view(A); //--> OK. - } - +.. triqs_example:: ./algebras_1.cpp .. note:: Making such a view is very cheap, it only copies the index systems. Nevertheless diff --git a/doc/reference/c++/arrays/algebras_0.cpp b/doc/reference/c++/arrays/algebras_0.cpp new file mode 100644 index 00000000..5b02d4a8 --- /dev/null +++ b/doc/reference/c++/arrays/algebras_0.cpp @@ -0,0 +1,20 @@ +#include +using triqs::arrays::array; +using triqs::clef::placeholder; +int main() { + // init + placeholder<0> i_; + placeholder<1> j_; + array A(2, 2), B(2, 2); + A(i_, j_) << i_ + j_; + B(i_, j_) << i_ - j_; + + // use expressions + array C = A + 2 * B; + array D = 0.5 * A; // Type promotion is automatic + std::cout << "A= " << A << std::endl; + std::cout << "B= " << B << std::endl; + std::cout << "C= " << C << std::endl; + std::cout << "D= " << D << std::endl; +} + diff --git a/doc/reference/c++/arrays/algebras_1.cpp b/doc/reference/c++/arrays/algebras_1.cpp new file mode 100644 index 00000000..20ed6d3b --- /dev/null +++ b/doc/reference/c++/arrays/algebras_1.cpp @@ -0,0 +1,9 @@ +#include +using namespace triqs::arrays; +int main() { + array A(2, 2); + matrix M(2, 2); + // M + A; // --> ERROR. Rejected by the compiler. + M + make_matrix_view(A); //--> OK. +} + diff --git a/doc/reference/c++/arrays/blas_lapack.rst b/doc/reference/c++/arrays/blas_lapack.rst index 77ad21c2..588a834a 100644 --- a/doc/reference/c++/arrays/blas_lapack.rst +++ b/doc/reference/c++/arrays/blas_lapack.rst @@ -25,19 +25,7 @@ The * operator map the matrix x matrix and matrix x vector product. Example : matrix * matrix and * vector ... -.. - compileblock:: - #include - using triqs::arrays::matrix; using triqs::clef::placeholder; - int main() { - // declare an init 2 matrices - placeholder<0> i_; placeholder<1> j_; - matrix A (2,2), B(2,2), C; - A(i_,j_) << i_ + j_ ; B(i_,j_) << 2*i_ + j_ ; - C= A*B; - std::cout<< " C = " << C<< std::endl; - } - +.. triqs_example:: ./blas_lapack_0.cpp For types that lapack do not use, a generic version of the matrix product is provided. (same syntax, the dispatch is made at compile time depending of the type of the matrices). diff --git a/doc/reference/c++/arrays/blas_lapack_0.cpp b/doc/reference/c++/arrays/blas_lapack_0.cpp new file mode 100644 index 00000000..835c8e4b --- /dev/null +++ b/doc/reference/c++/arrays/blas_lapack_0.cpp @@ -0,0 +1,14 @@ +#include +using triqs::arrays::matrix; +using triqs::clef::placeholder; +int main() { + // declare an init 2 matrices + placeholder<0> i_; + placeholder<1> j_; + matrix A(2, 2), B(2, 2), C; + A(i_, j_) << i_ + j_; + B(i_, j_) << 2 * i_ + j_; + C = A * B; + std::cout << " C = " << C << std::endl; +} + diff --git a/doc/reference/c++/arrays/concepts.rst b/doc/reference/c++/arrays/concepts.rst index 307672dd..ed767da9 100644 --- a/doc/reference/c++/arrays/concepts.rst +++ b/doc/reference/c++/arrays/concepts.rst @@ -186,46 +186,7 @@ For example: * A simple solution : - .. compileblock :: - - #include - #include - namespace triqs { namespace arrays { // better to put it in this namespace for ADL... - - template class immutable_diagonal_matrix_view { - - array_view data; // the diagonal stored as a 1d array - - public: - - immutable_diagonal_matrix_view(array_view v) : data (v) {} // constructor - - // the ImmutableMatrix concept - typedef indexmaps::cuboid::domain_t<2> domain_type; - domain_type domain() const { auto s = data.shape()[0]; return {s,s}; } - typedef T value_type; - T operator()(size_t i, size_t j) const { return (i==j ? data(i) : 0);} // just kronecker... - - friend std::ostream & operator<<(std::ostream & out, immutable_diagonal_matrix_view const & d) - {return out<<"diagonal_matrix "< struct ImmutableMatrix> : std::true_type{}; - }} - - /// TESTING - using namespace triqs::arrays; - int main(int argc, char **argv) { - auto a = array {1,2,3,4}; - auto d = immutable_diagonal_matrix_view{a}; - std::cout << "domain = " << d.domain()<< std::endl; - std::cout << "d = "<< d << std::endl; - std::cout << "2*d = "<< make_matrix(2*d) << std::endl; - std::cout << "d*d = "<< matrix(d*d) << std::endl; - } - - + .. triqs_example:: ./concepts_0.cpp * Discussion * Of course, this solution is not perfect. Several algorithms could be optimised if we know that a matrix is diagonal. diff --git a/doc/reference/c++/arrays/concepts_0.cpp b/doc/reference/c++/arrays/concepts_0.cpp new file mode 100644 index 00000000..07333aad --- /dev/null +++ b/doc/reference/c++/arrays/concepts_0.cpp @@ -0,0 +1,42 @@ +#include +#include +namespace triqs { +namespace arrays { // better to put it in this namespace for ADL... + + template class immutable_diagonal_matrix_view { + + array_view data; // the diagonal stored as a 1d array + + public: + immutable_diagonal_matrix_view(array_view v) : data(v) {} // constructor + + // the ImmutableMatrix concept + typedef indexmaps::cuboid::domain_t<2> domain_type; + domain_type domain() const { + auto s = data.shape()[0]; + return {s, s}; + } + typedef T value_type; + T operator()(size_t i, size_t j) const { return (i == j ? data(i) : 0); } // just kronecker... + + friend std::ostream &operator<<(std::ostream &out, immutable_diagonal_matrix_view const &d) { + return out << "diagonal_matrix " << d.data; + } + }; + + // Marking this class as belonging to the Matrix & Vector algebra. + template struct ImmutableMatrix> : std::true_type {}; +} +} + +/// TESTING +using namespace triqs::arrays; +int main(int argc, char **argv) { + auto a = array{1, 2, 3, 4}; + auto d = immutable_diagonal_matrix_view{a}; + std::cout << "domain = " << d.domain() << std::endl; + std::cout << "d = " << d << std::endl; + std::cout << "2*d = " << make_matrix(2 * d) << std::endl; + std::cout << "d*d = " << matrix(d * d) << std::endl; +} + diff --git a/doc/reference/c++/arrays/containers/CMakeLists.txt b/doc/reference/c++/arrays/containers/CMakeLists.txt new file mode 100644 index 00000000..1e301193 --- /dev/null +++ b/doc/reference/c++/arrays/containers/CMakeLists.txt @@ -0,0 +1,3 @@ +all_tests() + + diff --git a/doc/reference/c++/arrays/containers/STL.rst b/doc/reference/c++/arrays/containers/STL.rst index bd2af59a..b0a8b9ae 100644 --- a/doc/reference/c++/arrays/containers/STL.rst +++ b/doc/reference/c++/arrays/containers/STL.rst @@ -22,46 +22,4 @@ Examples:: Some examples of usage : -.. compileblock:: - - #include - #include - #include - #include - using triqs::arrays::array; using triqs::arrays::matrix; using triqs::clef::placeholder; - int main(){ - - // For example, one can make a vector of arrays ... :: - - array A (2,3); - std::vector > VV; - VV.push_back(A); - - // ... or a map :: - std::map > MAP; - MAP[1] = A; - - // We can put a std::vector in an array ... :: - // --> should make a direct constructor for this.. + factory in the reverse direction... - std::vector V (10,2); - array B(V.size()), C(V.size()); - std::copy(V.begin(),V.end(),B.begin()); - - // ... or in reverse :: - B*=2; - std::copy(B.begin(),B.end(),V.begin()); - - // ... or use other algorithms of std:: - std::cout<<" max(B) "<< * std::max_element(B.begin(),B.end())< i_; - B(i_) << 3*i_ ; - std::cout<<" B "<< B << std::endl; - std::replace_if (B.begin(), B.end(), [](int i) { return i>21;}, 0); - std::cout<<" B "<< B << std::endl; - - } - - - +.. triqs_example:: ./STL_0.cpp diff --git a/doc/reference/c++/arrays/containers/STL_0.cpp b/doc/reference/c++/arrays/containers/STL_0.cpp new file mode 100644 index 00000000..cdd5790b --- /dev/null +++ b/doc/reference/c++/arrays/containers/STL_0.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +using triqs::arrays::array; +using triqs::arrays::matrix; +using triqs::clef::placeholder; +int main() { + + // For example, one can make a vector of arrays ... :: + + array A(2, 3); + std::vector> VV; + VV.push_back(A); + + // ... or a map :: + std::map> MAP; + MAP[1] = A; + + // We can put a std::vector in an array ... :: + // --> should make a direct constructor for this.. + factory in the reverse direction... + std::vector V(10, 2); + array B(V.size()), C(V.size()); + std::copy(V.begin(), V.end(), B.begin()); + + // ... or in reverse :: + B *= 2; + std::copy(B.begin(), B.end(), V.begin()); + + // ... or use other algorithms of std:: + std::cout << " max(B) " << *std::max_element(B.begin(), B.end()) << std::endl; + + // or replace + placeholder<0> i_; + B(i_) << 3 * i_; + std::cout << " B " << B << std::endl; + std::replace_if(B.begin(), B.end(), [](int i) { return i > 21; }, 0); + std::cout << " B " << B << std::endl; +} + diff --git a/doc/reference/c++/arrays/containers/call.rst b/doc/reference/c++/arrays/containers/call.rst index ae776596..e4ffebd3 100644 --- a/doc/reference/c++/arrays/containers/call.rst +++ b/doc/reference/c++/arrays/containers/call.rst @@ -30,19 +30,7 @@ It must be called with exactly `rank` size_t (or it is a compile time error). Example ^^^^^^^^^ -.. compileblock:: - - #include - using namespace triqs::arrays; - int main(){ - array A(2,3); - A() = 0; // assign 0 to A - A(0,0) = 5; - A(1,1) = 2 * A(0,0); - std::cout <<"A = "<< A << std::endl; - } - - +.. triqs_example:: ./call_0.cpp Another :: A(1, range(0,2) ) // 1d slice @@ -78,20 +66,7 @@ The return type of the () operator is : Example ^^^^^^^^^^^^ -.. compileblock:: - - #include - using namespace triqs::arrays; - int main(){ - array A(4,4); - for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) A(i,j) = i+ 10*j; - array_view V = A(range(0,2), range(0,2)); - std::cout <<"V = "<< V << std::endl; - V = -V; - std::cout <<"A = "<< A << std::endl; - } - - +.. triqs_example:: ./call_1.cpp .. toctree:: :hidden: @@ -117,22 +92,7 @@ Example * **Example** : -.. compileblock:: - - #include - using triqs::arrays::array; using triqs::clef::placeholder; - - int main(){ - placeholder<0> i_; placeholder<1> j_; - array A(2,2), B(2,2); - - A(i_,j_) << i_ + 2*j_ ; - B(i_,j_) << A(j_,i_)/2; - - std::cout << "A = "< - #include - using triqs::arrays::vector; using triqs::arrays::range; - int main () { - triqs::arrays::vector V(3), W(3); - V() = 3; W()=5; // initialize - auto VV = V(range (0,2)); - auto VW = W(range (0,2)); - - std::cout << "V = "<< V << " W = " << W<< " V view "<< VV<< " W view "<< VW<< std::endl; - deep_swap(V,W); - std::cout << "V = "<< V << " W = " << W<< " V view "<< VV<< " W view "<< VW<< std::endl; - deep_swap(VV,VW); - std::cout << "V = "<< V << " W = " << W<< " V view "<< VV<< " W view "<< VW<< std::endl; - } - - - +.. triqs_example:: ./swap_1.cpp diff --git a/doc/reference/c++/arrays/containers/swap_0.cpp b/doc/reference/c++/arrays/containers/swap_0.cpp new file mode 100644 index 00000000..1c99d792 --- /dev/null +++ b/doc/reference/c++/arrays/containers/swap_0.cpp @@ -0,0 +1,18 @@ +#include +#include +using triqs::arrays::vector; +using triqs::arrays::range; +int main() { + triqs::arrays::vector V(3), W(4); + V() = 3; + W() = 4; // initialize + auto VV = V(range(0, 2)); + auto VW = W(range(0, 2)); + + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; + swap(V, W); + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; + swap(VV, VW); + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; +} + diff --git a/doc/reference/c++/arrays/containers/swap_1.cpp b/doc/reference/c++/arrays/containers/swap_1.cpp new file mode 100644 index 00000000..0468c562 --- /dev/null +++ b/doc/reference/c++/arrays/containers/swap_1.cpp @@ -0,0 +1,18 @@ +#include +#include +using triqs::arrays::vector; +using triqs::arrays::range; +int main() { + triqs::arrays::vector V(3), W(3); + V() = 3; + W() = 5; // initialize + auto VV = V(range(0, 2)); + auto VW = W(range(0, 2)); + + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; + deep_swap(V, W); + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; + deep_swap(VV, VW); + std::cout << "V = " << V << " W = " << W << " V view " << VV << " W view " << VW << std::endl; +} + diff --git a/doc/reference/c++/arrays/debug.rst b/doc/reference/c++/arrays/debug.rst index 5ebc8a20..cbe1d7a5 100644 --- a/doc/reference/c++/arrays/debug.rst +++ b/doc/reference/c++/arrays/debug.rst @@ -18,21 +18,7 @@ In both cases, if the indices are not within the domain of defintion, an excepti will be thrown. It's .what() returns the file and line where the exception occurs, with the stack of all in C++, e.g. : -.. compileblock:: - - #define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK - #include - using triqs::arrays::array; - int main(){ - try { - array A(2,2); A() = 3; - std::cout << A(0,3) << std::endl; - } - //catch (triqs::arrays::key_error & e) { std::cout<< e.what()<< std::endl;} - catch (std::exception & e) { std::cout<< e.what()<< std::endl;} // or like this : triqs::arrays::key_error derives from std::exception - } - - +.. triqs_example:: ./debug_0.cpp .. note:: Bound Checking is not necessarly used for debugging. You may used it for a given array, catching exception. Beware however that bound checking comes with some performance penalty. diff --git a/doc/reference/c++/arrays/debug_0.cpp b/doc/reference/c++/arrays/debug_0.cpp new file mode 100644 index 00000000..25859b35 --- /dev/null +++ b/doc/reference/c++/arrays/debug_0.cpp @@ -0,0 +1,15 @@ +#define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK +#include +using triqs::arrays::array; +int main() { + try { + array A(2, 2); + A() = 3; + std::cout << A(0, 3) << std::endl; + } + // catch (triqs::arrays::key_error & e) { std::cout<< e.what()<< std::endl;} + catch (std::exception& e) { + std::cout << e.what() << std::endl; + } // or like this : triqs::arrays::key_error derives from std::exception +} + diff --git a/doc/reference/c++/arrays/foreach.rst b/doc/reference/c++/arrays/foreach.rst index 4294409e..2e1c73ce 100644 --- a/doc/reference/c++/arrays/foreach.rst +++ b/doc/reference/c++/arrays/foreach.rst @@ -50,16 +50,7 @@ in the order specified by the TraversalOrder flag of the array. Example : -.. compileblock:: - - #include - using triqs::arrays::array; - int main(){ - array A (2,3); - foreach (A, [&A](size_t i, size_t j) { A(i,j) = i+j;}); - std::cout<<" A "<< A << std::endl; - } - +.. triqs_example:: ./foreach_0.cpp .. note:: You *can* pass a std::function as Function, but it is not recommended in critical parts of the code. @@ -91,15 +82,6 @@ Synopsis:: * The for loop are automatically organised to optimize the traversal order of A using the TraversalOrder flag of the array. -.. compileblock:: - - #include - using triqs::arrays::array; - int main(){ - array A (2,3); - assign_foreach (A, [](size_t i, size_t j) { return i+j;}); - std::cout<<" A "<< A << std::endl; - } - +.. triqs_example:: ./foreach_1.cpp .. note:: Cf the note of the *foreach* function. diff --git a/doc/reference/c++/arrays/foreach_0.cpp b/doc/reference/c++/arrays/foreach_0.cpp new file mode 100644 index 00000000..601622b0 --- /dev/null +++ b/doc/reference/c++/arrays/foreach_0.cpp @@ -0,0 +1,8 @@ +#include +using triqs::arrays::array; +int main() { + array A(2, 3); + foreach(A, [&A](size_t i, size_t j) { A(i, j) = i + j; }); + std::cout << " A " << A << std::endl; +} + diff --git a/doc/reference/c++/arrays/foreach_1.cpp b/doc/reference/c++/arrays/foreach_1.cpp new file mode 100644 index 00000000..2ce217bd --- /dev/null +++ b/doc/reference/c++/arrays/foreach_1.cpp @@ -0,0 +1,8 @@ +#include +using triqs::arrays::array; +int main() { + array A(2, 3); + assign_foreach(A, [](size_t i, size_t j) { return i + j; }); + std::cout << " A " << A << std::endl; +} + diff --git a/doc/reference/c++/arrays/h5_rw.rst b/doc/reference/c++/arrays/h5_rw.rst index 78edb45b..428cd697 100644 --- a/doc/reference/c++/arrays/h5_rw.rst +++ b/doc/reference/c++/arrays/h5_rw.rst @@ -6,25 +6,8 @@ Simple read/write operations of an array (or a view) Given an array (or an array_view), the functions `h5::write` and `h5::read` write and read it to/from the file or any subgroup thereof. For example : -.. compileblock:: - - #include - using triqs::arrays::array; using triqs::arrays::matrix; - int main(){ - - array A(2,2); A() = 3; // declare and init - - H5::H5File file("store_A.h5",H5F_ACC_TRUNC); // open the file - h5_write(file,"A",A); // write the array as 'A' into the file - - //array B; // read the file into B - matrix B; // read the file into B - h5_read (file, "A",B); - std::cout << "B = "< +using triqs::arrays::array; +using triqs::arrays::matrix; +int main() { + + array A(2, 2); + A() = 3; // declare and init + + H5::H5File file("store_A.h5", H5F_ACC_TRUNC); // open the file + h5_write(file, "A", A); // write the array as 'A' into the file + + // array B; // read the file into B + matrix B; // read the file into B + h5_read(file, "A", B); + std::cout << "B = " << B << std::endl; + h5_write(file, "B", B); +} + diff --git a/doc/reference/c++/arrays/h5_stack.rst b/doc/reference/c++/arrays/h5_stack.rst deleted file mode 100644 index a6481ec2..00000000 --- a/doc/reference/c++/arrays/h5_stack.rst +++ /dev/null @@ -1,51 +0,0 @@ -.. highlight:: c - -h5::array_stack : stacking arrays or scalars -================================================================ - -h5::array_stack writes a sequences of arrays of the same shape (or of scalars) into an hdf5 array with one more dimension, unlimited in the stacking direction. - -It is typically used to store a Monte-Carlo data series for later analysis. - -* If the base of the stack is an array of rank R, the resulting hdf5 array will be of rank R+1. - -* If the base of the stack is a simple number (double, int, ...), R=0. - -* The syntax is simple : - - * The << operator piles up an array/scalar onto the stack. - * The ++ operator advances by one slice in the stack. - * The () operator returns a view on the current slice of the stack. - -* The stack is bufferized in memory (`bufsize` parameter), so that the file access does not happen too often. - -* NB : beware to complex numbers ---> REF TO COMPLEX - -Reference ------------- - -Here is the :doxy:`full C++ documentation` for this class. - -.. : - Breathe Documentation - -------------------------- - - .. doxygenclass:: triqs::arrays::array_stack - :project: arrays - :members: - - - -Tutorial ------------ - -A simple example with a stack of double: - -.. literalinclude:: examples_code/h5_stack_ex_sca.cpp - -A simple example with a stack of array of rank 2 : - -.. literalinclude:: examples_code/h5_stack_ex.cpp - - - diff --git a/doc/reference/c++/arrays/lazy.rst b/doc/reference/c++/arrays/lazy.rst index 8cf0f4b9..e8d97bfd 100644 --- a/doc/reference/c++/arrays/lazy.rst +++ b/doc/reference/c++/arrays/lazy.rst @@ -18,21 +18,7 @@ Interaction with CLEF expressions * **Example** : -.. compileblock:: - - #include - using triqs::arrays::array; using triqs::clef::placeholder; - int main(){ - placeholder<0> i_; placeholder<1> j_; - array A(2,2), B(2,2); - - A(i_,j_) << i_ + 2*j_ ; - B(i_,j_) << A(j_,i_)/2; - - std::cout << "A = "< - using namespace triqs::clef; - - int main() { - int N = 5; - double pi = std::acos(-1); - - // automatic assignment of vector - placeholder <0> k_; - std::vector V(N); - make_expr(V) [k_] << cos( (2* pi* k_)/ N ); - - // chaining them ... - placeholder <1> i_; - std::vector> W(3, std::vector(N)); - make_expr(W)[i_] [k_] << i_ + cos( (2* pi* k_)/ N ); - - // check result... - for (size_t u=0; u 1.e-10) throw "error!"; - for (size_t w=0; w 1.e-10) throw "error!"; - } - +.. triqs_example:: ./assign_0.cpp **Details** The synopsis of the `triqs_clef_auto_assign` functions is :: @@ -92,26 +66,4 @@ into :: A complete example : -.. compileblock:: - - #include - #include - using namespace triqs::clef; - - struct Obj{ - double v; - TRIQS_CLEF_IMPLEMENT_LAZY_CALL(); - // - template friend void triqs_clef_auto_assign (Obj & x, Fnt f) { - std::cout<< " called triqs_clef_auto_assign "<< f(x.v++)< x_; - std::cout<< f.v << std::endl; - f(x_ ) << 8*x_ ; - std::cout<< f.v << std::endl; - } - +.. triqs_example:: ./assign_1.cpp diff --git a/doc/reference/c++/clef/assign_0.cpp b/doc/reference/c++/clef/assign_0.cpp new file mode 100644 index 00000000..72724f36 --- /dev/null +++ b/doc/reference/c++/clef/assign_0.cpp @@ -0,0 +1,26 @@ +#include "triqs/clef.hpp" +#include +using namespace triqs::clef; + +int main() { + int N = 5; + double pi = std::acos(-1); + + // automatic assignment of vector + placeholder<0> k_; + std::vector V(N); + make_expr(V)[k_] << cos((2 * pi * k_) / N); + + // chaining them ... + placeholder<1> i_; + std::vector> W(3, std::vector(N)); + make_expr(W)[i_][k_] << i_ + cos((2 * pi * k_) / N); + + // check result... + for (size_t u = 0; u < V.size(); ++u) + if (std::abs(V[u] - cos((2 * pi * u) / N)) > 1.e-10) throw "error!"; + for (size_t w = 0; w < W.size(); ++w) + for (size_t u = 0; u < W[w].size(); ++u) + if (std::abs(W[w][u] - (w + cos((2 * pi * u) / N))) > 1.e-10) throw "error!"; +} + diff --git a/doc/reference/c++/clef/assign_1.cpp b/doc/reference/c++/clef/assign_1.cpp new file mode 100644 index 00000000..0cd9f7cc --- /dev/null +++ b/doc/reference/c++/clef/assign_1.cpp @@ -0,0 +1,21 @@ +#include +#include +using namespace triqs::clef; + +struct Obj { + double v; + TRIQS_CLEF_IMPLEMENT_LAZY_CALL(); + // + template friend void triqs_clef_auto_assign(Obj& x, Fnt f) { + std::cout << " called triqs_clef_auto_assign " << f(x.v++) << std::endl; + } +}; + +int main() { + Obj f{2}; + placeholder<3> x_; + std::cout << f.v << std::endl; + f(x_) << 8 * x_; + std::cout << f.v << std::endl; +} + diff --git a/doc/reference/c++/clef/expressions_eval.rst b/doc/reference/c++/clef/expressions_eval.rst index 5c3dd9b5..f583c179 100644 --- a/doc/reference/c++/clef/expressions_eval.rst +++ b/doc/reference/c++/clef/expressions_eval.rst @@ -22,16 +22,7 @@ The evaluation can be : Complete evaluation -------------------- -.. compileblock:: - - #include - using namespace triqs::clef; - int main () { - placeholder<1> x_; placeholder<2> y_; - std::cout << eval (x_ + 2*y_ , x_=1, y_ =2) << std::endl; - std::cout << eval (x_ + 2*y_ , y_=2, x_ =1) << std::endl; - } - +.. triqs_example:: ./expressions_eval_0.cpp Note that : * The order of placeholder does not matter in calling eval. diff --git a/doc/reference/c++/clef/expressions_eval_0.cpp b/doc/reference/c++/clef/expressions_eval_0.cpp new file mode 100644 index 00000000..281eaa22 --- /dev/null +++ b/doc/reference/c++/clef/expressions_eval_0.cpp @@ -0,0 +1,9 @@ +#include +using namespace triqs::clef; +int main() { + placeholder<1> x_; + placeholder<2> y_; + std::cout << eval(x_ + 2 * y_, x_ = 1, y_ = 2) << std::endl; + std::cout << eval(x_ + 2 * y_, y_ = 2, x_ = 1) << std::endl; +} + diff --git a/doc/reference/c++/clef/expressions_form.rst b/doc/reference/c++/clef/expressions_form.rst index 289d1454..83356c97 100644 --- a/doc/reference/c++/clef/expressions_form.rst +++ b/doc/reference/c++/clef/expressions_form.rst @@ -44,26 +44,7 @@ CLEF expressions are made of : Examples : -.. compileblock:: - - #include - #include - using namespace triqs::clef; - int main () { - placeholder<0> i_; placeholder<1> x_; placeholder<2> y_; - std::vector V; - - // arithmetic - auto e = x_ + 2* y_; - - // simple math function - auto e1 = cos(2*x_+1); - auto e2 = abs(2*x_-1); - - // making V lazy - auto e0 = make_expr(V)[i_]; - } - +.. triqs_example:: ./expressions_form_0.cpp Note that : * Expressions do not compute anything, they just store the expression tree. diff --git a/doc/reference/c++/clef/expressions_form_0.cpp b/doc/reference/c++/clef/expressions_form_0.cpp new file mode 100644 index 00000000..9411f5da --- /dev/null +++ b/doc/reference/c++/clef/expressions_form_0.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace triqs::clef; +int main() { + placeholder<0> i_; + placeholder<1> x_; + placeholder<2> y_; + std::vector V; + + // arithmetic + auto e = x_ + 2 * y_; + + // simple math function + auto e1 = cos(2 * x_ + 1); + auto e2 = abs(2 * x_ - 1); + + // making V lazy + auto e0 = make_expr(V)[i_]; +} + diff --git a/doc/reference/c++/clef/function.rst b/doc/reference/c++/clef/function.rst index ac60e076..e9aa2c9f 100644 --- a/doc/reference/c++/clef/function.rst +++ b/doc/reference/c++/clef/function.rst @@ -74,50 +74,4 @@ clef::function can be assigned with the = operator, Cf example below. Examples --------- - .. compileblock:: - - #include - #include - using namespace triqs::clef; - - int main() { - placeholder<0> x_; placeholder<1> y_; - { // with one variable - auto f = make_function(2*x_ + 1, x_); - std::cout << f(3) << std::endl; - std::function F(f); - } - { //with two variables - auto f = make_function(2*x_ + y_ + 1, x_, y_); - std::cout << f(3,4) << std::endl; - std::function F(f); - } - { // Make a function partially - auto f = make_function( 2*x_ + y_ + 1, x_); - // f is a lazy expression expression with placeholder y_, returning a function... - auto f1 = eval (f, y_=1); // f1 is a function x-> 2*x + 2 - std::cout << f1 (10) << std::endl; - } - { // Currying a function - //auto f = make_function ( make_function( 2*x_ + y_ + 1, x_), y_); - auto f = y_ >> ( x_ >> 2*x_ + y_ + 1); - // f a function y-> x-> 2x+y+1 - // f(y) returns a function x-> 2x+y+1 - auto g = f(3); - std::cout << g (10) << std::endl; - } - { // playing with clef::function and std::function - triqs::clef::function f2,g2; - f2(x_,y_) = x_ + y_; - std::cout << f2(2,3) << std::endl; - - std::function sf2 = f2; - std::cout << sf2(2,3) << std::endl; - - g2(x_,y_) = x_ - y_ + f2(x_,2*y_); - - std::function sf = x_>> 2*x_ + 1; - std::cout << sf(3) << std::endl; - } - } - + .. triqs_example:: ./function_0.cpp diff --git a/doc/reference/c++/clef/function_0.cpp b/doc/reference/c++/clef/function_0.cpp new file mode 100644 index 00000000..9cc1d76e --- /dev/null +++ b/doc/reference/c++/clef/function_0.cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace triqs::clef; + +int main() { + placeholder<0> x_; + placeholder<1> y_; + { // with one variable + auto f = make_function(2 * x_ + 1, x_); + std::cout << f(3) << std::endl; + std::function F(f); + } + { // with two variables + auto f = make_function(2 * x_ + y_ + 1, x_, y_); + std::cout << f(3, 4) << std::endl; + std::function F(f); + } + { // Make a function partially + auto f = make_function(2 * x_ + y_ + 1, x_); + // f is a lazy expression expression with placeholder y_, returning a function... + auto f1 = eval(f, y_ = 1); // f1 is a function x-> 2*x + 2 + std::cout << f1(10) << std::endl; + } + { // Currying a function + // auto f = make_function ( make_function( 2*x_ + y_ + 1, x_), y_); + auto f = y_ >> (x_ >> 2 * x_ + y_ + 1); + // f a function y-> x-> 2x+y+1 + // f(y) returns a function x-> 2x+y+1 + auto g = f(3); + std::cout << g(10) << std::endl; + } + { // playing with clef::function and std::function + triqs::clef::function f2, g2; + f2(x_, y_) = x_ + y_; + std::cout << f2(2, 3) << std::endl; + + std::function sf2 = f2; + std::cout << sf2(2, 3) << std::endl; + + g2(x_, y_) = x_ - y_ + f2(x_, 2 * y_); + + std::function sf = x_ >> 2 * x_ + 1; + std::cout << sf(3) << std::endl; + } +} + diff --git a/doc/reference/c++/clef/introduction.rst b/doc/reference/c++/clef/introduction.rst index 7de9a173..948b9e99 100644 --- a/doc/reference/c++/clef/introduction.rst +++ b/doc/reference/c++/clef/introduction.rst @@ -7,66 +7,4 @@ Motivation : a little tour of CLEF As usual, the best is to start with a few examples, to show the library in action. -.. compileblock:: - - #include - #include - #include - #include - int main() { - // Declaring some placeholders (i.e. dummy variables). - triqs::clef::placeholder <0> i_; - triqs::clef::placeholder <1> j_; - - // Declaring a 3x3 matrix - triqs::arrays::matrix A (3,3); - - // Automatically filling the matrix - // -> forget about the bounds, it is automatic - // -> forget about the best order to order the for loops for performance, it is also automatic - A(i_,j_) << i_ + 2*j_; - - // Cheking the result - std::cout<< A<< std::endl; - - // It also works for std container: we just have to add a call clef::make_expr function - std::vector V(10); - double pi = std::acos(-1); - - // Automatically filling the vector with the evaluation of the expression in i_ - triqs::clef::make_expr(V) [i_] << cos( 2* pi / 5.0 * i_ ); - - // -> by the way, the constant calculation is precomputed - // (expressions are partially evaluated as soon as possible) - // illustration : - // the time_consuming_function will be called only once in the loop, while cos is called 10 times - auto time_consuming_function=[](double x){std::cout<<"call time_consuming_function"<> W(3, std::vector(5)); - triqs::clef::make_expr(W)[i_] [j_] << i_ + cos( time_consuming_function(10) * j_ + i_); - - // You can also put a CLEF expression in a std::function - // a function i -> 2*i +1 - std::function f = i_ >> 2*i_ +1; - // a function (i,j) -> 2*i +j - std::function g = var(i_,j_) >> 2*i_ +j_; - // checking ... - std::cout<< "f(10) =" << f(10)<< " g(1,2) =" << g(1,2)<< std::endl; - - // You can also use a Curry form : h is a function i-> j -> 2*i+ j - auto h = i_ >> (j_ >> 2*i_ +j_); - std::cout<< "h(1)(2) = " << h(1)(2) << std::endl; - - // You an also use this to quickly write some lambda, as an alternative syntax to the C++ lambda - // with e.g. STL algorithms (with the advantage that the function is polymorphic!). - std::vector v = {0,-1,2,-3,4,5,-6}; - // replace all negative elements (i.e. those for which i -> (i<0) return true), by 0 - std::replace_if(begin(v), end(v), i_ >> (i_<0), 0); - // for non believer, it really worked ... - for (auto const & x : v) std::cout < +#include +#include +#include +int main() { + // Declaring some placeholders (i.e. dummy variables). + triqs::clef::placeholder<0> i_; + triqs::clef::placeholder<1> j_; + + // Declaring a 3x3 matrix + triqs::arrays::matrix A(3, 3); + + // Automatically filling the matrix + // -> forget about the bounds, it is automatic + // -> forget about the best order to order the for loops for performance, it is also automatic + A(i_, j_) << i_ + 2 * j_; + + // Cheking the result + std::cout << A << std::endl; + + // It also works for std container: we just have to add a call clef::make_expr function + std::vector V(10); + double pi = std::acos(-1); + + // Automatically filling the vector with the evaluation of the expression in i_ + triqs::clef::make_expr(V)[i_] << cos(2 * pi / 5.0 * i_); + + // -> by the way, the constant calculation is precomputed + // (expressions are partially evaluated as soon as possible) + // illustration : + // the time_consuming_function will be called only once in the loop, while cos is called 10 times + auto time_consuming_function = [](double x) { + std::cout << "call time_consuming_function" << std::endl; + return 2 * x; + }; + triqs::clef::make_expr(V)[i_] << cos(time_consuming_function(10) * i_); + + // If you insist using on more complex containers... + std::vector> W(3, std::vector(5)); + triqs::clef::make_expr(W)[i_][j_] << i_ + cos(time_consuming_function(10) * j_ + i_); + + // You can also put a CLEF expression in a std::function + // a function i -> 2*i +1 + std::function f = i_ >> 2 * i_ + 1; + // a function (i,j) -> 2*i +j + std::function g = var(i_, j_) >> 2 * i_ + j_; + // checking ... + std::cout << "f(10) =" << f(10) << " g(1,2) =" << g(1, 2) << std::endl; + + // You can also use a Curry form : h is a function i-> j -> 2*i+ j + auto h = i_ >> (j_ >> 2 * i_ + j_); + std::cout << "h(1)(2) = " << h(1)(2) << std::endl; + + // You an also use this to quickly write some lambda, as an alternative syntax to the C++ lambda + // with e.g. STL algorithms (with the advantage that the function is polymorphic!). + std::vector v = {0, -1, 2, -3, 4, 5, -6}; + // replace all negative elements (i.e. those for which i -> (i<0) return true), by 0 + std::replace_if(begin(v), end(v), i_ >> (i_ < 0), 0); + // for non believer, it really worked ... + for (auto const& x : v) std::cout << x << " "; + std::cout << std::endl; +} + diff --git a/doc/reference/c++/clef/overload.rst b/doc/reference/c++/clef/overload.rst index 94933c3e..8c212f6d 100644 --- a/doc/reference/c++/clef/overload.rst +++ b/doc/reference/c++/clef/overload.rst @@ -19,35 +19,7 @@ using the `TRIQS_CLEF_MAKE_FNT_LAZY` macro. For example: -.. compileblock:: - - #include - #include - - // a simple foo function - double foo(double x) { return x/2;} - int foo(int x) { return x*2;} - - // a more complex case : bar is already a template - // we have to disable it for CLEF expression to avoid ambiguity - - // C++14 clean syntax will be (using concepts) - // template - // T bar (T const & x) { return x+1;} - - // C++11 workaround - template - typename std::enable_if::value,T>::type - bar (T const & x) { return x+1;} - - namespace triqs { namespace clef { TRIQS_CLEF_MAKE_FNT_LAZY (foo) ; TRIQS_CLEF_MAKE_FNT_LAZY (bar) ; }} - - int main() { - triqs::clef::placeholder<3> x_; - std::cout << foo(2.0)<<" "< - #include - int main() { - triqs::clef::placeholder<3> x_; - std::cout << 2.0 + std::cos(2.0) << std::endl; - std::cout << eval( x_ + cos(x_), x_ = 2) << std::endl; // NB : note the absence of std:: - } - +.. triqs_example:: ./overload_1.cpp .. _callable_object: Overloading operator() and other methods @@ -79,47 +42,7 @@ It is an ordinary operator() that must : Example : -.. compileblock:: - - #include - - struct Obj { - double v; // put something in it - Obj(double v_): v(v_){} // constructor - Obj(Obj const &) = delete; // a non copyable object, to illustrate that we do NOT copy... - - // The "normal", non CLEF call operator .... - double operator() (double x) const { return 10*x;} - - // This macro implements properly an overload of the operator () - TRIQS_CLEF_IMPLEMENT_LAZY_CALL(); - - // a method - double my_method(double x) const { return 2*x;} - - // CLEF overload - // WARNING : the method MUST be const - TRIQS_CLEF_IMPLEMENT_LAZY_METHOD(Obj,my_method); - - // Just to print itself nicely in the expressions - friend std::ostream & operator<<(std::ostream & out, Obj const & x) { return out<<"Obj";} - }; - - int main() { - Obj f(7); - triqs::clef::placeholder<1> x_; triqs::clef::placeholder<2> y_; - - std::cout << "Clef expression : "<< f(y_) + 2*x_ << std::endl ; - std::cout << "Complete evaluation : "<< eval(f(x_) + 2*x_, x_=1) << std::endl ; - std::cout << "Partial evaluation : "<< eval(f(y_) + 2*x_, y_=1) << std::endl ; - std::cout << "Complete evalution : "<< eval(f(y_) + 2*x_, x_=3, y_=1) << std::endl< +#include + +// a simple foo function +double foo(double x) { return x / 2; } +int foo(int x) { return x * 2; } + +// a more complex case : bar is already a template +// we have to disable it for CLEF expression to avoid ambiguity + +// C++14 clean syntax will be (using concepts) +// template +// T bar (T const & x) { return x+1;} + +// C++11 workaround +template typename std::enable_if::value, T>::type bar(T const& x) { + return x + 1; +} + +namespace triqs { +namespace clef { + TRIQS_CLEF_MAKE_FNT_LAZY(foo); + TRIQS_CLEF_MAKE_FNT_LAZY(bar); +} +} + +int main() { + triqs::clef::placeholder<3> x_; + std::cout << foo(2.0) << " " << eval(x_ + foo(x_), x_ = 3) << " " << eval(x_ + foo(x_), x_ = 3.5) << std::endl; + std::cout << bar(2.0) << " " << eval(x_ + bar(x_), x_ = 3) << " " << eval(x_ + bar(x_), x_ = 3.5) << std::endl; +} + diff --git a/doc/reference/c++/clef/overload_1.cpp b/doc/reference/c++/clef/overload_1.cpp new file mode 100644 index 00000000..c92391f7 --- /dev/null +++ b/doc/reference/c++/clef/overload_1.cpp @@ -0,0 +1,8 @@ +#include +#include +int main() { + triqs::clef::placeholder<3> x_; + std::cout << 2.0 + std::cos(2.0) << std::endl; + std::cout << eval(x_ + cos(x_), x_ = 2) << std::endl; // NB : note the absence of std:: +} + diff --git a/doc/reference/c++/clef/overload_2.cpp b/doc/reference/c++/clef/overload_2.cpp new file mode 100644 index 00000000..8530c032 --- /dev/null +++ b/doc/reference/c++/clef/overload_2.cpp @@ -0,0 +1,40 @@ +#include + +struct Obj { + double v; // put something in it + Obj(double v_) : v(v_) {} // constructor + Obj(Obj const &) = delete; // a non copyable object, to illustrate that we do NOT copy... + + // The "normal", non CLEF call operator .... + double operator()(double x) const { return 10 * x; } + + // This macro implements properly an overload of the operator () + TRIQS_CLEF_IMPLEMENT_LAZY_CALL(); + + // a method + double my_method(double x) const { return 2 * x; } + + // CLEF overload + // WARNING : the method MUST be const + TRIQS_CLEF_IMPLEMENT_LAZY_METHOD(Obj, my_method); + + // Just to print itself nicely in the expressions + friend std::ostream &operator<<(std::ostream &out, Obj const &x) { return out << "Obj"; } +}; + +int main() { + Obj f(7); + triqs::clef::placeholder<1> x_; + triqs::clef::placeholder<2> y_; + + std::cout << "Clef expression : " << f(y_) + 2 * x_ << std::endl; + std::cout << "Complete evaluation : " << eval(f(x_) + 2 * x_, x_ = 1) << std::endl; + std::cout << "Partial evaluation : " << eval(f(y_) + 2 * x_, y_ = 1) << std::endl; + std::cout << "Complete evalution : " << eval(f(y_) + 2 * x_, x_ = 3, y_ = 1) << std::endl << std::endl; + + std::cout << "Clef expression : " << f.my_method(y_) + 2 * x_ << std::endl; + std::cout << "Complete evaluation : " << eval(f.my_method(x_) + 2 * x_, x_ = 1) << std::endl; + std::cout << "Partial evaluation : " << eval(f.my_method(y_) + 2 * x_, y_ = 1) << std::endl; + std::cout << "Complete evalution : " << eval(f.my_method(y_) + 2 * x_, x_ = 3, y_ = 1) << std::endl; +} + diff --git a/doc/reference/c++/det_manip/CMakeLists.txt b/doc/reference/c++/det_manip/CMakeLists.txt index 6909c7be..44821cb3 100644 --- a/doc/reference/c++/det_manip/CMakeLists.txt +++ b/doc/reference/c++/det_manip/CMakeLists.txt @@ -1,2 +1,5 @@ # Doxygen sources set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_SOURCE_DIR}/triqs/det_manip/det_manip.hpp) + +all_tests() + diff --git a/doc/reference/c++/det_manip/det_manip.rst b/doc/reference/c++/det_manip/det_manip.rst index f3c7fa3b..367b03d6 100644 --- a/doc/reference/c++/det_manip/det_manip.rst +++ b/doc/reference/c++/det_manip/det_manip.rst @@ -153,51 +153,4 @@ The :doxy:`full C++ documentation` is available her Example --------- -.. compileblock:: - - #include - - struct fun { - - typedef double result_type; - typedef double argument_type; - - double operator()(double x, double y) const { - const double pi = acos(-1.); - const double beta = 10.0; - const double epsi = 0.1; - double tau = x-y; - bool s = (tau>0); - tau = (s ? tau : beta + tau); - double r = epsi + tau/beta * (1-2*epsi); - return - 2*(pi/beta)/ std::sin ( pi*r); - } - }; - - int main() { - - fun f; - triqs::det_manip::det_manip D(f,100); - - /// insertions of 3 lines and 3 columns - double x=2., y=9., detratio; - std::cout << D.size() << std::endl; - detratio = D.try_insert(0, 0, x, y ); - std::cout << D.size() << std::endl; - D.complete_operation(); - std::cout << D.size() << std::endl; - detratio = D.try_insert(0, 1, 2., 3.); - D.complete_operation(); - detratio = D.try_insert(0, 0, 4., 5.); - D.complete_operation(); - - /// removal of a line (the 3rd) and a column (the 2nd) - detratio = D.try_remove(2,1); - D.complete_operation(); - } - - - - - - +.. triqs_example:: ./det_manip_0.cpp diff --git a/doc/reference/c++/det_manip/det_manip_0.cpp b/doc/reference/c++/det_manip/det_manip_0.cpp new file mode 100644 index 00000000..fbecd17a --- /dev/null +++ b/doc/reference/c++/det_manip/det_manip_0.cpp @@ -0,0 +1,41 @@ +#include + +struct fun { + + typedef double result_type; + typedef double argument_type; + + double operator()(double x, double y) const { + const double pi = acos(-1.); + const double beta = 10.0; + const double epsi = 0.1; + double tau = x - y; + bool s = (tau > 0); + tau = (s ? tau : beta + tau); + double r = epsi + tau / beta * (1 - 2 * epsi); + return -2 * (pi / beta) / std::sin(pi * r); + } +}; + +int main() { + + fun f; + triqs::det_manip::det_manip D(f, 100); + + /// insertions of 3 lines and 3 columns + double x = 2., y = 9., detratio; + std::cout << D.size() << std::endl; + detratio = D.try_insert(0, 0, x, y); + std::cout << D.size() << std::endl; + D.complete_operation(); + std::cout << D.size() << std::endl; + detratio = D.try_insert(0, 1, 2., 3.); + D.complete_operation(); + detratio = D.try_insert(0, 0, 4., 5.); + D.complete_operation(); + + /// removal of a line (the 3rd) and a column (the 2nd) + detratio = D.try_remove(2, 1); + D.complete_operation(); +} + diff --git a/doc/reference/c++/gf/CMakeLists.txt b/doc/reference/c++/gf/CMakeLists.txt index 97327f47..404a70d7 100644 --- a/doc/reference/c++/gf/CMakeLists.txt +++ b/doc/reference/c++/gf/CMakeLists.txt @@ -8,3 +8,6 @@ set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_GFS_SRC_DIR}/refreq.hpp ${TRIQS_GFS_SRC_DIR}/domains/matsubara.hpp ) + +all_tests() + diff --git a/doc/reference/c++/gf/clef.rst b/doc/reference/c++/gf/clef.rst index f71346fd..d0906be7 100644 --- a/doc/reference/c++/gf/clef.rst +++ b/doc/reference/c++/gf/clef.rst @@ -17,22 +17,7 @@ Using the CLEF library offers a quick and efficient way to fill an array with mu **Example** : -.. compileblock:: - - #include - using namespace triqs::gfs; using triqs::clef::placeholder; - int main(){ - - // Cf gf specialisation page for the constructor - double beta=10; int Nfreq =100; - auto g = gf { {beta,Fermion,Nfreq}, {1,1} }; - - // Filling the gf with something... - placeholder<0> wn_; - g(wn_) << 1/ (wn_ + 2); - g(wn_) << 1/ (wn_ + 2 + g(wn_) ); - } - +.. triqs_example:: ./clef_0.cpp .. note:: The LHS uses () and not brackets, even though it is on the mesh, because of the strange C++ limitation diff --git a/doc/reference/c++/gf/clef_0.cpp b/doc/reference/c++/gf/clef_0.cpp new file mode 100644 index 00000000..3904fd88 --- /dev/null +++ b/doc/reference/c++/gf/clef_0.cpp @@ -0,0 +1,16 @@ +#include +using namespace triqs::gfs; +using triqs::clef::placeholder; +int main() { + + // Cf gf specialisation page for the constructor + double beta = 10; + int Nfreq = 100; + auto g = gf{{beta, Fermion, Nfreq}, {1, 1}}; + + // Filling the gf with something... + placeholder<0> wn_; + g(wn_) << 1 / (wn_ + 2); + g(wn_) << 1 / (wn_ + 2 + g(wn_)); +} + diff --git a/doc/reference/c++/gf/fourier.rst b/doc/reference/c++/gf/fourier.rst index af0bd99e..1d60835a 100644 --- a/doc/reference/c++/gf/fourier.rst +++ b/doc/reference/c++/gf/fourier.rst @@ -65,27 +65,7 @@ DOC TO BE FINISHED. Example ========= -.. compileblock:: - - #include - using namespace triqs::gfs; - int main() { - double beta =1, a=1; - int N=10000; - auto gw = gf {{beta, Fermion, N}, {1,1}}; - auto gt = gf {{beta, Fermion, N}, {1,1}}; - - triqs::clef::placeholder<0> om_; - gw (om_) << 1/(om_-a); - - // fills a full *view* of gt with the contents of the FFT - // NB : the mesh of gt *must* have the same size as the mesh of gw. - gt() = inverse_fourier(gw); - - // make a new fresh gf, with the same size mesh, from the FFT of gt - auto gw2 = make_gf_from_fourier(gt); - } - +.. triqs_example:: ./fourier_0.cpp Convention =========== diff --git a/doc/reference/c++/gf/fourier_0.cpp b/doc/reference/c++/gf/fourier_0.cpp new file mode 100644 index 00000000..defa4549 --- /dev/null +++ b/doc/reference/c++/gf/fourier_0.cpp @@ -0,0 +1,19 @@ +#include +using namespace triqs::gfs; +int main() { + double beta = 1, a = 1; + int N = 10000; + auto gw = gf{{beta, Fermion, N}, {1, 1}}; + auto gt = gf{{beta, Fermion, N}, {1, 1}}; + + triqs::clef::placeholder<0> om_; + gw(om_) << 1 / (om_ - a); + + // fills a full *view* of gt with the contents of the FFT + // NB : the mesh of gt *must* have the same size as the mesh of gw. + gt() = inverse_fourier(gw); + + // make a new fresh gf, with the same size mesh, from the FFT of gt + auto gw2 = make_gf_from_fourier(gt); +} + diff --git a/doc/reference/c++/gf/gf_block.rst b/doc/reference/c++/gf/gf_block.rst index 43eaa5d5..f1a0c5f9 100644 --- a/doc/reference/c++/gf/gf_block.rst +++ b/doc/reference/c++/gf/gf_block.rst @@ -129,36 +129,4 @@ Block gf have a natural iterator, e.g. :: Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; using triqs::clef::placeholder; - int main() { - double beta =1; - - // Make a block gf of 3 gf, which are empty (default constructed). - auto Bg0 = block_gf (3); - - // make a few gf ... - auto g1 = gf ({beta, Fermion}, {2,2}); - - // ... and construct some block function out of them. - auto Bg1 = make_block_gf (3, g1); - auto Bg2 = make_block_gf ({g1,g1,g1}); - auto Bg3 = make_block_gf ({"a","b","c"}, {g1,g1,g1}); - - // do something on all blocks - for (auto const &g : Bg1) { - std::cout<< g.mesh() << std::endl; - } - - // multiply them by 1,2,3 ... - auto i = 1; - for (auto & g : Bg1) g = g * i++; - - // a little save in an hdf5 file ? - H5::H5File file("test_block_gf.h5", H5F_ACC_TRUNC ); - h5_write(file, "B3", Bg3); - } - - +.. triqs_example:: ./gf_block_0.cpp diff --git a/doc/reference/c++/gf/gf_block_0.cpp b/doc/reference/c++/gf/gf_block_0.cpp new file mode 100644 index 00000000..fba9d935 --- /dev/null +++ b/doc/reference/c++/gf/gf_block_0.cpp @@ -0,0 +1,31 @@ +#include +using namespace triqs::gfs; +using triqs::clef::placeholder; +int main() { + double beta = 1; + + // Make a block gf of 3 gf, which are empty (default constructed). + auto Bg0 = block_gf(3); + + // make a few gf ... + auto g1 = gf({beta, Fermion}, {2, 2}); + + // ... and construct some block function out of them. + auto Bg1 = make_block_gf(3, g1); + auto Bg2 = make_block_gf({g1, g1, g1}); + auto Bg3 = make_block_gf({"a", "b", "c"}, {g1, g1, g1}); + + // do something on all blocks + for (auto const &g : Bg1) { + std::cout << g.mesh() << std::endl; + } + + // multiply them by 1,2,3 ... + auto i = 1; + for (auto &g : Bg1) g = g * i++; + + // a little save in an hdf5 file ? + H5::H5File file("test_block_gf.h5", H5F_ACC_TRUNC); + h5_write(file, "B3", Bg3); +} + diff --git a/doc/reference/c++/gf/gf_constructors.rst b/doc/reference/c++/gf/gf_constructors.rst index 57dfa2f4..1b2b595c 100644 --- a/doc/reference/c++/gf/gf_constructors.rst +++ b/doc/reference/c++/gf/gf_constructors.rst @@ -40,15 +40,4 @@ Examples There are more examples for each specializations in the corresponding pages. -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - auto beta = 10.0; - gf gf { {beta, Fermion}, {1,1}}; - } - - - - +.. triqs_example:: ./gf_constructors_0.cpp diff --git a/doc/reference/c++/gf/gf_constructors_0.cpp b/doc/reference/c++/gf/gf_constructors_0.cpp new file mode 100644 index 00000000..f0b16f88 --- /dev/null +++ b/doc/reference/c++/gf/gf_constructors_0.cpp @@ -0,0 +1,7 @@ +#include +using namespace triqs::gfs; +int main() { + auto beta = 10.0; + gf gf{{beta, Fermion}, {1, 1}}; +} + diff --git a/doc/reference/c++/gf/gf_imfreq.rst b/doc/reference/c++/gf/gf_imfreq.rst index e786b5d7..f0d501f3 100644 --- a/doc/reference/c++/gf/gf_imfreq.rst +++ b/doc/reference/c++/gf/gf_imfreq.rst @@ -82,40 +82,4 @@ Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double beta=10; - int Nfreq =100; - - // --- first a matrix_valued function ------------ - - // First give information to build the mesh, second to build the target - auto g1 = gf { {beta,Fermion,Nfreq}, {1,1} }; - // or a more verbose/explicit form ... - auto g2 = gf { gf_mesh{beta,Fermion,Nfreq}, make_shape(1,1) }; - - // Filling the gf with something... - triqs::clef::placeholder<0> wn_; - g1(wn_) << 1/ (wn_ + 2); - - // evaluation at n=3 - std::cout << g1(3) << " == "<< 1/ ( 1_j * M_PI / beta * (2*3+1) + 2) << std::endl; - // the high frequency expansion was automatically computed. - //std::cout << g1.singularity() << std::endl; // a bit verbose.. - - // --- a scalar_valued function ------------ - - // same a before, but without the same of the target space ... - auto g3 = gf { {beta,Fermion,Nfreq} }; - auto g4 = gf { gf_mesh{beta,Fermion,Nfreq} }; - - g3(wn_) << 1/ (wn_ + 2); - - // evaluation at n=3. - std::cout << g3(3) << " == "<< 1/ ( 1_j * std::acos(-1) / beta * (2*3+1) + 2) << std::endl; - } - - +.. triqs_example:: ./gf_imfreq_0.cpp diff --git a/doc/reference/c++/gf/gf_imfreq_0.cpp b/doc/reference/c++/gf/gf_imfreq_0.cpp new file mode 100644 index 00000000..c87dedae --- /dev/null +++ b/doc/reference/c++/gf/gf_imfreq_0.cpp @@ -0,0 +1,34 @@ +#include +using namespace triqs::gfs; +int main() { + double beta = 10; + int Nfreq = 100; + + // --- first a matrix_valued function ------------ + + // First give information to build the mesh, second to build the target + auto g1 = gf{{beta, Fermion, Nfreq}, {1, 1}}; + // or a more verbose/explicit form ... + auto g2 = gf{gf_mesh{beta, Fermion, Nfreq}, make_shape(1, 1)}; + + // Filling the gf with something... + triqs::clef::placeholder<0> wn_; + g1(wn_) << 1 / (wn_ + 2); + + // evaluation at n=3 + std::cout << g1(3) << " == " << 1 / (1_j * M_PI / beta * (2 * 3 + 1) + 2) << std::endl; + // the high frequency expansion was automatically computed. + // std::cout << g1.singularity() << std::endl; // a bit verbose.. + + // --- a scalar_valued function ------------ + + // same a before, but without the same of the target space ... + auto g3 = gf{{beta, Fermion, Nfreq}}; + auto g4 = gf{gf_mesh{beta, Fermion, Nfreq}}; + + g3(wn_) << 1 / (wn_ + 2); + + // evaluation at n=3. + std::cout << g3(3) << " == " << 1 / (1_j * std::acos(-1) / beta * (2 * 3 + 1) + 2) << std::endl; +} + diff --git a/doc/reference/c++/gf/gf_imtime.rst b/doc/reference/c++/gf/gf_imtime.rst index ceb99123..28c88ad8 100644 --- a/doc/reference/c++/gf/gf_imtime.rst +++ b/doc/reference/c++/gf/gf_imtime.rst @@ -87,41 +87,5 @@ h5 tag : `ImTime` Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double beta=10, a = 1; - int n_times=1000; - - // --- first a matrix_valued function ------------ - - // First give information to build the mesh, second to build the target - auto g1 = gf { {beta,Fermion,n_times}, {1,1} }; - - // or a more verbose/explicit form ... - auto g2 = gf { gf_mesh{beta,Fermion,n_times}, make_shape(1,1) }; - - // Filling the gf with something... COMMENT HERE : ok only because of no_tail - triqs::clef::placeholder<0> tau_; - g1(tau_) << exp ( - a * tau_) / (1 + exp(- beta * a)); - - // evaluation at tau=3.2 - std::cout << triqs::arrays::make_matrix(g1(3.2)) << " == "<< exp ( - a * 3.2) / (1 + exp(- beta * a)) << std::endl; - - // --- a scalar_valued function ------------ - - // same a before, but without the same of the target space ... - auto g3 = gf { {beta,Fermion,n_times} }; - - g3(tau_) << exp ( - a * tau_) / (1 + exp(- beta * a)); - - // evaluation at tau=3.2 - std::cout << g3(3.2) << " == "<< exp ( - a * 3.2) / (1 + exp(- beta * a)) << std::endl; - } - - - - - +.. triqs_example:: ./gf_imtime_0.cpp + diff --git a/doc/reference/c++/gf/gf_imtime_0.cpp b/doc/reference/c++/gf/gf_imtime_0.cpp new file mode 100644 index 00000000..71c26530 --- /dev/null +++ b/doc/reference/c++/gf/gf_imtime_0.cpp @@ -0,0 +1,32 @@ +#include +using namespace triqs::gfs; +int main() { + double beta = 10, a = 1; + int n_times = 1000; + + // --- first a matrix_valued function ------------ + + // First give information to build the mesh, second to build the target + auto g1 = gf{{beta, Fermion, n_times}, {1, 1}}; + + // or a more verbose/explicit form ... + auto g2 = gf{gf_mesh{beta, Fermion, n_times}, make_shape(1, 1)}; + + // Filling the gf with something... COMMENT HERE : ok only because of no_tail + triqs::clef::placeholder<0> tau_; + g1(tau_) << exp(-a * tau_) / (1 + exp(-beta * a)); + + // evaluation at tau=3.2 + std::cout << triqs::arrays::make_matrix(g1(3.2)) << " == " << exp(-a * 3.2) / (1 + exp(-beta * a)) << std::endl; + + // --- a scalar_valued function ------------ + + // same a before, but without the same of the target space ... + auto g3 = gf{{beta, Fermion, n_times}}; + + g3(tau_) << exp(-a * tau_) / (1 + exp(-beta * a)); + + // evaluation at tau=3.2 + std::cout << g3(3.2) << " == " << exp(-a * 3.2) / (1 + exp(-beta * a)) << std::endl; +} + diff --git a/doc/reference/c++/gf/gf_legendre.rst b/doc/reference/c++/gf/gf_legendre.rst index a553ee82..b60890bf 100644 --- a/doc/reference/c++/gf/gf_legendre.rst +++ b/doc/reference/c++/gf/gf_legendre.rst @@ -53,14 +53,4 @@ h5 tag : `Legendre` Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - // We want a 2x2 matrix valued function on this mesh... - //auto g = gf { {wmin, wmax, n_freq}, {2,2} }; - }; - - +.. triqs_example:: ./gf_legendre_0.cpp diff --git a/doc/reference/c++/gf/gf_legendre_0.cpp b/doc/reference/c++/gf/gf_legendre_0.cpp new file mode 100644 index 00000000..64491a67 --- /dev/null +++ b/doc/reference/c++/gf/gf_legendre_0.cpp @@ -0,0 +1,8 @@ +#include +using namespace triqs::gfs; + +int main() { + // We want a 2x2 matrix valued function on this mesh... + // auto g = gf { {wmin, wmax, n_freq}, {2,2} }; +}; + diff --git a/doc/reference/c++/gf/gf_part_eval_curry.rst b/doc/reference/c++/gf/gf_part_eval_curry.rst index 74a2c1c1..4ebd5ec8 100644 --- a/doc/reference/c++/gf/gf_part_eval_curry.rst +++ b/doc/reference/c++/gf/gf_part_eval_curry.rst @@ -26,27 +26,7 @@ Partial evaluation Probably an example would help here ... : -.. compileblock:: - - #include - using namespace triqs::gfs; using triqs::clef::placeholder; - int main(){ - double beta =1, tmin=0, tmax=1.0; - int n_re_time=100, n_im_time=100; - - using g_t_tau_s = gf, scalar_valued>; - - // a scalar valued function - auto g= g_t_tau_s { { {tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}} }; - - // evaluation of the second variable to 3 : 3 is the **index** of the point ! - auto g_sliced = partial_eval<1>(g(), 3); - // g_sliced is now a gf_view/gf_const_view seeing the value at the index 3 - - std::cout<< g_sliced<< std::endl; - } - - +.. triqs_example:: ./gf_part_eval_curry_0.cpp Currying ------------- @@ -62,36 +42,4 @@ Currying curry(gf_view, Target, Opt, IsConst> g); -.. compileblock:: - - #include - using namespace triqs::gfs; using triqs::clef::placeholder; - int main(){ - double beta =1, wmin=0, wmax=1.0; - int n_re_freq=100, n_im_freq=100; - - using g_w_wn_s = gf, scalar_valued>; - - // a scalar valued function - auto g= g_w_wn_s{ { {wmin, wmax, n_re_freq}, {beta, Fermion, n_im_freq}} }; - - // put expression in it - triqs::clef::placeholder<0> w_; - triqs::clef::placeholder<1> wn_; - g (w_,wn_)<<1/(wn_-1)/( w_ + 3_j ); - - // Currying by selecting the first variable, i.e. t -> tau -> g(t,tau) - auto g1 = curry<0>(g); - - // Currying by selecting the second variable, i.e. tau -> t -> g(t,tau) - auto g2 = curry<1>(g); - - //std::cout << g << g1[1]<< g2 [2] << std::endl; - std::cout<< g1[1][2] << g2 [2][1] << g [{1,2}] << std::endl; - } - - - - - - +.. triqs_example:: ./gf_part_eval_curry_1.cpp diff --git a/doc/reference/c++/gf/gf_part_eval_curry_0.cpp b/doc/reference/c++/gf/gf_part_eval_curry_0.cpp new file mode 100644 index 00000000..797ce1a2 --- /dev/null +++ b/doc/reference/c++/gf/gf_part_eval_curry_0.cpp @@ -0,0 +1,19 @@ +#include +using namespace triqs::gfs; +using triqs::clef::placeholder; +int main() { + double beta = 1, tmin = 0, tmax = 1.0; + int n_re_time = 100, n_im_time = 100; + + using g_t_tau_s = gf, scalar_valued>; + + // a scalar valued function + auto g = g_t_tau_s{{{tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}}}; + + // evaluation of the second variable to 3 : 3 is the **index** of the point ! + auto g_sliced = partial_eval<1>(g(), 3); + // g_sliced is now a gf_view/gf_const_view seeing the value at the index 3 + + std::cout << g_sliced << std::endl; +} + diff --git a/doc/reference/c++/gf/gf_part_eval_curry_1.cpp b/doc/reference/c++/gf/gf_part_eval_curry_1.cpp new file mode 100644 index 00000000..67a61e47 --- /dev/null +++ b/doc/reference/c++/gf/gf_part_eval_curry_1.cpp @@ -0,0 +1,27 @@ +#include +using namespace triqs::gfs; +using triqs::clef::placeholder; +int main() { + double beta = 1, wmin = 0, wmax = 1.0; + int n_re_freq = 100, n_im_freq = 100; + + using g_w_wn_s = gf, scalar_valued>; + + // a scalar valued function + auto g = g_w_wn_s{{{wmin, wmax, n_re_freq}, {beta, Fermion, n_im_freq}}}; + + // put expression in it + triqs::clef::placeholder<0> w_; + triqs::clef::placeholder<1> wn_; + g(w_, wn_) << 1 / (wn_ - 1) / (w_ + 3_j); + + // Currying by selecting the first variable, i.e. t -> tau -> g(t,tau) + auto g1 = curry<0>(g); + + // Currying by selecting the second variable, i.e. tau -> t -> g(t,tau) + auto g2 = curry<1>(g); + + // std::cout << g << g1[1]<< g2 [2] << std::endl; + std::cout << g1[1][2] << g2[2][1] << g[{1, 2}] << std::endl; +} + diff --git a/doc/reference/c++/gf/gf_product.rst b/doc/reference/c++/gf/gf_product.rst index 1366c90b..1481802b 100644 --- a/doc/reference/c++/gf/gf_product.rst +++ b/doc/reference/c++/gf/gf_product.rst @@ -55,37 +55,4 @@ See : Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; using triqs::clef::placeholder; - int main(){ - double beta =1, tmin=0, tmax=1.0; - int n_re_time=100, n_im_time=100; - - using g_t_tau_s = gf, scalar_valued>; - using g_t_tau_m = gf, matrix_valued>; - using g_t_tau_t = gf, tensor_valued<3>>; - - // a scalar valued function - auto m1 = gf_mesh{tmin, tmax, n_re_time}; - auto m2 = gf_mesh{beta, Fermion, n_im_time}; - auto g= g_t_tau_s { {m1,m2} }; - - // a more compact notation - auto g2= g_t_tau_s { { {tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}} }; - - // a matrix_valued_version - auto gm= g_t_tau_m { { {tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}} , {2,2} }; - - // a tensor_valued_version - auto gt= g_t_tau_t { { {tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}} , {2,2,2} }; - - // a little save in an hdf5 file ? - H5::H5File file("test_product_gf.h5", H5F_ACC_TRUNC ); - h5_write(file, "g", g); - } - - - - +.. triqs_example:: ./gf_product_0.cpp diff --git a/doc/reference/c++/gf/gf_product_0.cpp b/doc/reference/c++/gf/gf_product_0.cpp new file mode 100644 index 00000000..402c6c21 --- /dev/null +++ b/doc/reference/c++/gf/gf_product_0.cpp @@ -0,0 +1,30 @@ +#include +using namespace triqs::gfs; +using triqs::clef::placeholder; +int main() { + double beta = 1, tmin = 0, tmax = 1.0; + int n_re_time = 100, n_im_time = 100; + + using g_t_tau_s = gf, scalar_valued>; + using g_t_tau_m = gf, matrix_valued>; + using g_t_tau_t = gf, tensor_valued<3>>; + + // a scalar valued function + auto m1 = gf_mesh{tmin, tmax, n_re_time}; + auto m2 = gf_mesh{beta, Fermion, n_im_time}; + auto g = g_t_tau_s{{m1, m2}}; + + // a more compact notation + auto g2 = g_t_tau_s{{{tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}}}; + + // a matrix_valued_version + auto gm = g_t_tau_m{{{tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}}, {2, 2}}; + + // a tensor_valued_version + auto gt = g_t_tau_t{{{tmin, tmax, n_re_time}, {beta, Fermion, n_im_time}}, {2, 2, 2}}; + + // a little save in an hdf5 file ? + H5::H5File file("test_product_gf.h5", H5F_ACC_TRUNC); + h5_write(file, "g", g); +} + diff --git a/doc/reference/c++/gf/gf_refreq.rst b/doc/reference/c++/gf/gf_refreq.rst index a236cb4d..a682dcd0 100644 --- a/doc/reference/c++/gf/gf_refreq.rst +++ b/doc/reference/c++/gf/gf_refreq.rst @@ -80,17 +80,4 @@ h5 tag : `ReFreq` Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double wmin=0, wmax=10; // Frequencies interval - auto n_freq=100; // Number of points - - // We want a 2x2 matrix valued function on this mesh... - auto g = gf { {wmin, wmax, n_freq}, {2,2} }; - }; - - +.. triqs_example:: ./gf_refreq_0.cpp diff --git a/doc/reference/c++/gf/gf_refreq_0.cpp b/doc/reference/c++/gf/gf_refreq_0.cpp new file mode 100644 index 00000000..e339d942 --- /dev/null +++ b/doc/reference/c++/gf/gf_refreq_0.cpp @@ -0,0 +1,11 @@ +#include +using namespace triqs::gfs; + +int main() { + double wmin = 0, wmax = 10; // Frequencies interval + auto n_freq = 100; // Number of points + + // We want a 2x2 matrix valued function on this mesh... + auto g = gf{{wmin, wmax, n_freq}, {2, 2}}; +}; + diff --git a/doc/reference/c++/gf/gf_retime.rst b/doc/reference/c++/gf/gf_retime.rst index 3819ea12..c1a8e38a 100644 --- a/doc/reference/c++/gf/gf_retime.rst +++ b/doc/reference/c++/gf/gf_retime.rst @@ -81,16 +81,4 @@ h5 tag : `ReTime` Examples --------- -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double tmin=0, tmax=10; // the time interval - auto n_times=100; // we will have 100 points - - //we want a 2x2 matrix-valued Green function - auto g=gf{ {tmin, tmax, n_times} , {2,2} }; - }; - +.. triqs_example:: ./gf_retime_0.cpp diff --git a/doc/reference/c++/gf/gf_retime_0.cpp b/doc/reference/c++/gf/gf_retime_0.cpp new file mode 100644 index 00000000..dc905453 --- /dev/null +++ b/doc/reference/c++/gf/gf_retime_0.cpp @@ -0,0 +1,11 @@ +#include +using namespace triqs::gfs; + +int main() { + double tmin = 0, tmax = 10; // the time interval + auto n_times = 100; // we will have 100 points + + // we want a 2x2 matrix-valued Green function + auto g = gf{{tmin, tmax, n_times}, {2, 2}}; +}; + diff --git a/doc/reference/c++/gf/matsubara_freq_mesh.rst b/doc/reference/c++/gf/matsubara_freq_mesh.rst index 95f32e88..f8f74fbc 100644 --- a/doc/reference/c++/gf/matsubara_freq_mesh.rst +++ b/doc/reference/c++/gf/matsubara_freq_mesh.rst @@ -62,28 +62,4 @@ Public member types Example ---------- -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double beta=1; - int n_pts=4; - matsubara_freq_mesh m(beta,Fermion, n_pts); - std::cout << "Mesh m with only positive Matsubara frequencies : " << std::endl; - for(auto & w:m) std::cout << w << std::endl; - std::cout << "m.first_index() = " << m.first_index() << std::endl; - std::cout << "m.last_index() = " << m.last_index() << std::endl; - std::cout << "m.size() = " << m.size() << std::endl; - matsubara_freq_mesh m2(beta,Fermion, n_pts, false); - std::cout << "Mesh m2 with positive and negative Matsubara frequencies : " << std::endl; - for(auto & w:m2) std::cout << w << std::endl; - std::cout << "m2.first_index() = " << m2.first_index() << std::endl; - std::cout << "m2.last_index() = " << m2.last_index() << std::endl; - std::cout << "m2.size() = " << m2.size() << std::endl; - return 0; - } - - - - +.. triqs_example:: ./matsubara_freq_mesh_0.cpp diff --git a/doc/reference/c++/gf/matsubara_freq_mesh_0.cpp b/doc/reference/c++/gf/matsubara_freq_mesh_0.cpp new file mode 100644 index 00000000..2ad1f677 --- /dev/null +++ b/doc/reference/c++/gf/matsubara_freq_mesh_0.cpp @@ -0,0 +1,20 @@ +#include +using namespace triqs::gfs; +int main() { + double beta = 1; + int n_pts = 4; + matsubara_freq_mesh m(beta, Fermion, n_pts); + std::cout << "Mesh m with only positive Matsubara frequencies : " << std::endl; + for (auto& w : m) std::cout << w << std::endl; + std::cout << "m.first_index() = " << m.first_index() << std::endl; + std::cout << "m.last_index() = " << m.last_index() << std::endl; + std::cout << "m.size() = " << m.size() << std::endl; + matsubara_freq_mesh m2(beta, Fermion, n_pts, false); + std::cout << "Mesh m2 with positive and negative Matsubara frequencies : " << std::endl; + for (auto& w : m2) std::cout << w << std::endl; + std::cout << "m2.first_index() = " << m2.first_index() << std::endl; + std::cout << "m2.last_index() = " << m2.last_index() << std::endl; + std::cout << "m2.size() = " << m2.size() << std::endl; + return 0; +} + diff --git a/doc/reference/c++/gf/set_tail_from_fit.rst b/doc/reference/c++/gf/set_tail_from_fit.rst index 992b3db2..f3d7d3df 100644 --- a/doc/reference/c++/gf/set_tail_from_fit.rst +++ b/doc/reference/c++/gf/set_tail_from_fit.rst @@ -33,33 +33,7 @@ where Example ~~~~~~~~ -.. compileblock:: - - #include - #include - using namespace triqs::gfs; - int main(){ - triqs::clef::placeholder<0> iom_; - double beta =10; - int N=100; - - auto gw = gf{{beta, Fermion, N}, {1, 1}}; - gw(iom_) << 1/(iom_-1); - - size_t n_min=50, n_max=90; - int n_moments=4; - int size=1; //means that we know one moment - int order_min=1; //means that the first moment in the final tail will be the first moment - auto known_moments = local::tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min - known_moments(1)=1.;//set the first moment - - set_tail_from_fit(gw, known_moments, n_moments, n_min, n_max, true); - - std::cout << gw.singularity() << std::endl; - } - - - +.. triqs_example:: ./set_tail_from_fit_0.cpp Implementation ~~~~~~~~~~~~~~~ diff --git a/doc/reference/c++/gf/set_tail_from_fit_0.cpp b/doc/reference/c++/gf/set_tail_from_fit_0.cpp new file mode 100644 index 00000000..8d4617a1 --- /dev/null +++ b/doc/reference/c++/gf/set_tail_from_fit_0.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace triqs::gfs; +int main() { + triqs::clef::placeholder<0> iom_; + double beta = 10; + int N = 100; + + auto gw = gf{{beta, Fermion, N}, {1, 1}}; + gw(iom_) << 1 / (iom_ - 1); + + size_t n_min = 50, n_max = 90; + int n_moments = 4; + int size = 1; // means that we know one moment + int order_min = 1; // means that the first moment in the final tail will be the first moment + auto known_moments = local::tail(make_shape(1, 1), size, order_min); // length is 0, first moment to fit is order_min + known_moments(1) = 1.; // set the first moment + + set_tail_from_fit(gw, known_moments, n_moments, n_min, n_max, true); + + std::cout << gw.singularity() << std::endl; +} + diff --git a/doc/reference/c++/gf/tail.rst b/doc/reference/c++/gf/tail.rst index 405737a6..ab969878 100644 --- a/doc/reference/c++/gf/tail.rst +++ b/doc/reference/c++/gf/tail.rst @@ -24,53 +24,14 @@ Implementation In TRIQS, the tail is implemented as an object ``tail``. Here is a simple example of use: -.. compileblock:: - - #include - #include - #include - int main(){ - int N1=1, N2=1; - triqs::gfs::local::tail t(N1,N2); - t.mask_view() = 5;//only coeffs from -1 to 5 are meaningful - std::cout << t(0) << std::endl; - t(2) = .5; - std::cout << t << std::endl; - } - - - +.. triqs_example:: ./tail_0.cpp Fitting the tail of a Green's function --------------------------------------- Given an imaginary-frequency Green's function, one can compute the moments of its high-frequency tail with the function ``set_tail_from_fit``: -.. compileblock:: - - #include - #include - using namespace triqs::gfs; - int main(){ - triqs::clef::placeholder<0> iom_; - double beta =10; - int N=100; - - auto gw = gf{{beta, Fermion, N}, {1, 1}}; - gw(iom_) << 1/(iom_-1); - - size_t n_min=50; //linear index on mesh to start the fit - size_t n_max=90; //final linear index for fit (included) - int n_moments=4; //number of moments in the final tail (including known ones) - int size=1; //means that we know one moment - int order_min=1; //means that the first moment in the final tail will be the first moment - auto known_moments = local::tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min - known_moments(1)=1.;//set the first moment - set_tail_from_fit(gw, known_moments, n_moments, n_min, n_max, true);//true replace the gf data in the fitting range by the tail values - std::cout << gw.singularity() << std::endl; - } - - +.. triqs_example:: ./tail_1.cpp The full documentation of ``set_tail_from_fit`` is :doc:`here`. API diff --git a/doc/reference/c++/gf/tail_0.cpp b/doc/reference/c++/gf/tail_0.cpp new file mode 100644 index 00000000..82b95de6 --- /dev/null +++ b/doc/reference/c++/gf/tail_0.cpp @@ -0,0 +1,12 @@ +#include +#include +#include +int main() { + int N1 = 1, N2 = 1; + triqs::gfs::local::tail t(N1, N2); + t.mask_view() = 5; // only coeffs from -1 to 5 are meaningful + std::cout << t(0) << std::endl; + t(2) = .5; + std::cout << t << std::endl; +} + diff --git a/doc/reference/c++/gf/tail_1.cpp b/doc/reference/c++/gf/tail_1.cpp new file mode 100644 index 00000000..02fd4178 --- /dev/null +++ b/doc/reference/c++/gf/tail_1.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace triqs::gfs; +int main() { + triqs::clef::placeholder<0> iom_; + double beta = 10; + int N = 100; + + auto gw = gf{{beta, Fermion, N}, {1, 1}}; + gw(iom_) << 1 / (iom_ - 1); + + size_t n_min = 50; // linear index on mesh to start the fit + size_t n_max = 90; // final linear index for fit (included) + int n_moments = 4; // number of moments in the final tail (including known ones) + int size = 1; // means that we know one moment + int order_min = 1; // means that the first moment in the final tail will be the first moment + auto known_moments = local::tail(make_shape(1, 1), size, order_min); // length is 0, first moment to fit is order_min + known_moments(1) = 1.; // set the first moment + set_tail_from_fit(gw, known_moments, n_moments, n_min, n_max, + true); // true replace the gf data in the fitting range by the tail values + std::cout << gw.singularity() << std::endl; +} + diff --git a/doc/reference/c++/mctools/CMakeLists.txt b/doc/reference/c++/mctools/CMakeLists.txt index 6b40a00a..175d59ce 100644 --- a/doc/reference/c++/mctools/CMakeLists.txt +++ b/doc/reference/c++/mctools/CMakeLists.txt @@ -1,2 +1,5 @@ # Doxygen sources set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_SOURCE_DIR}/triqs/mc_tools/mc_generic.hpp) + +all_tests() + diff --git a/doc/reference/c++/parameters/CMakeLists.txt b/doc/reference/c++/parameters/CMakeLists.txt index f9b714df..11bebf2f 100644 --- a/doc/reference/c++/parameters/CMakeLists.txt +++ b/doc/reference/c++/parameters/CMakeLists.txt @@ -1,2 +1,5 @@ # Doxygen sources set_property(GLOBAL APPEND PROPERTY DOXYGEN_SOURCES ${TRIQS_SOURCE_DIR}/triqs/parameters/parameters.hpp) + +all_tests() + diff --git a/doc/reference/c++/parameters/parameters.rst b/doc/reference/c++/parameters/parameters.rst index 6ec60035..159d4013 100644 --- a/doc/reference/c++/parameters/parameters.rst +++ b/doc/reference/c++/parameters/parameters.rst @@ -109,60 +109,11 @@ the :doxy:`parameter_defaults documentation` Parameter example ------------- -.. compileblock:: c - - #include - using triqs::utility::parameters; - #include - - int main() { - - parameters P; - - P["a"] = long(1); - P["d"] = 2.7; - P["a_string"] = std::string("-14.3"); - P["char_string"] = "-14.3"; - - triqs::arrays::array A(2,2); A()=0;A(0,0) = 1.3; A(1,1) = -8.2; - P["A"] = A; - std::cout << "A:"<< P["A"] << std::endl; - - long a = P["a"]; - double x = P["a"]; // cast to double from long - double y = P["a_string"]; // lexical cast to double from string - std::cout< - using triqs::utility::parameters; - using triqs::utility::parameter_defaults; - - int main() { - - parameters P; - P["Beta"] = 3.14; - - parameter_defaults pdef; - pdef.required("Beta", double(), "Inverse temperature") - .optional("Alpha", int(1000), "An integer") - .optional("Gamma", double(0.9), "A double"); - - std::cout< +using triqs::params::parameters; +#include + +int main() { + + parameters P; +/* + P["a"] = long(1); + P["d"] = 2.7; + P["a_string"] = std::string("-14.3"); + P["char_string"] = "-14.3"; + + triqs::arrays::array A(2, 2); + A() = 0; + A(0, 0) = 1.3; + A(1, 1) = -8.2; + P["A"] = A; + std::cout << "A:" << P["A"] << std::endl; + + long a = P["a"]; + double x = P["a"]; // cast to double from long + double y = P["a_string"]; // lexical cast to double from string + std::cout << y << std::endl; +*/ + return 0; +} + diff --git a/doc/reference/c++/parameters/parameters_1.cpp b/doc/reference/c++/parameters/parameters_1.cpp new file mode 100644 index 00000000..37f7cbef --- /dev/null +++ b/doc/reference/c++/parameters/parameters_1.cpp @@ -0,0 +1,19 @@ +#include +using triqs::params::parameters; + +int main() { +/* + parameters P; + P["Beta"] = 3.14; + + parameter_defaults pdef; + pdef.required("Beta", double(), "Inverse temperature").optional("Alpha", int(1000), "An integer").optional("Gamma", double(0.9), + "A double"); + + std::cout << pdef << std::endl; // print a comprehensive list of parameters: + std::cout << P << std::endl; + P.update(pdef); // check whether required parameters are present and update optional ones + std::cout << P << std::endl; +*/ +} + diff --git a/doc/reference/c++/statistics/CMakeLists.txt b/doc/reference/c++/statistics/CMakeLists.txt new file mode 100644 index 00000000..917a5baf --- /dev/null +++ b/doc/reference/c++/statistics/CMakeLists.txt @@ -0,0 +1,2 @@ +all_tests() + diff --git a/doc/reference/c++/statistics/binning.rst b/doc/reference/c++/statistics/binning.rst index 016f954f..87e66fd9 100644 --- a/doc/reference/c++/statistics/binning.rst +++ b/doc/reference/c++/statistics/binning.rst @@ -13,14 +13,4 @@ Synopsis Example -------- -.. compileblock:: - - #include - using namespace triqs::statistics; - int main(){ - observable A; - A<<1.;A<<1.5;A<<.2;A<<1.1; - auto A_b = make_binned_series(A,2); - std::cout << A_b << std::endl; - return 0; - } +.. triqs_example:: ./binning_0.cpp diff --git a/doc/reference/c++/statistics/binning_0.cpp b/doc/reference/c++/statistics/binning_0.cpp new file mode 100644 index 00000000..fe587d86 --- /dev/null +++ b/doc/reference/c++/statistics/binning_0.cpp @@ -0,0 +1,12 @@ +#include +using namespace triqs::statistics; +int main() { + observable A; + A << 1.; + A << 1.5; + A << .2; + A << 1.1; + auto A_b = make_binned_series(A, 2); + std::cout << A_b << std::endl; + return 0; +} diff --git a/doc/reference/c++/statistics/contents.rst b/doc/reference/c++/statistics/contents.rst index 338db340..14e81b0a 100644 --- a/doc/reference/c++/statistics/contents.rst +++ b/doc/reference/c++/statistics/contents.rst @@ -75,23 +75,7 @@ where `T` belongs to an algebra. Example -------- -.. compileblock:: - - #include - #include - using namespace triqs::statistics; - int main(){ - observable X; - X<<1.0; - X<<-1.0; - X<<.5; - X<<.0; - std::cout << average_and_error(X) << std::endl; - std::cout << average_and_error(X*X) << std::endl; - return 0; - } - - +.. triqs_example:: ./contents_0.cpp .. toctree:: binning jackknife diff --git a/doc/reference/c++/statistics/contents_0.cpp b/doc/reference/c++/statistics/contents_0.cpp new file mode 100644 index 00000000..b4636c4c --- /dev/null +++ b/doc/reference/c++/statistics/contents_0.cpp @@ -0,0 +1,14 @@ +#include +#include +using namespace triqs::statistics; +int main() { + observable X; + X << 1.0; + X << -1.0; + X << .5; + X << .0; + std::cout << average_and_error(X) << std::endl; + std::cout << average_and_error(X * X) << std::endl; + return 0; +} + diff --git a/doc/reference/c++/statistics/jackknife.rst b/doc/reference/c++/statistics/jackknife.rst index 3d099c6d..ee6d575b 100644 --- a/doc/reference/c++/statistics/jackknife.rst +++ b/doc/reference/c++/statistics/jackknife.rst @@ -19,15 +19,4 @@ Synopsis Example --------- -.. compileblock:: - - #include - using namespace triqs::statistics; - int main(){ - observable A; - A<<1.;A<<1.5;A<<.2;A<<1.1; - auto A_j = make_jackknife(A); - std::cout << A_j << std::endl; - return 0; - } - +.. triqs_example:: ./jackknife_0.cpp diff --git a/doc/reference/c++/statistics/jackknife_0.cpp b/doc/reference/c++/statistics/jackknife_0.cpp new file mode 100644 index 00000000..d3d5e9e8 --- /dev/null +++ b/doc/reference/c++/statistics/jackknife_0.cpp @@ -0,0 +1,13 @@ +#include +using namespace triqs::statistics; +int main() { + observable A; + A << 1.; + A << 1.5; + A << .2; + A << 1.1; + auto A_j = make_jackknife(A); + std::cout << A_j << std::endl; + return 0; +} + diff --git a/doc/reference/c++/using_the_lib/CMakeLists.txt b/doc/reference/c++/using_the_lib/CMakeLists.txt new file mode 100644 index 00000000..917a5baf --- /dev/null +++ b/doc/reference/c++/using_the_lib/CMakeLists.txt @@ -0,0 +1,2 @@ +all_tests() + diff --git a/doc/reference/c++/utilities/CMakeLists.txt b/doc/reference/c++/utilities/CMakeLists.txt new file mode 100644 index 00000000..917a5baf --- /dev/null +++ b/doc/reference/c++/utilities/CMakeLists.txt @@ -0,0 +1,2 @@ +all_tests() + diff --git a/doc/reference/c++/utilities/exceptions.rst b/doc/reference/c++/utilities/exceptions.rst index 8bf14a8c..82b7ba54 100644 --- a/doc/reference/c++/utilities/exceptions.rst +++ b/doc/reference/c++/utilities/exceptions.rst @@ -23,35 +23,7 @@ TRIQS defines special exceptions, with the following characteristics : Example : -.. compileblock:: - - // automatically included in e.g. arrays, gfs, any triqs library... - #include - - int main() { - if (2!=3) TRIQS_RUNTIME_ERROR <<" The condition is false because "<< 2 << "!=" << 3; - } - +.. triqs_example:: ./exceptions_0.cpp The exception can of course be caught : -.. compileblock:: - - // automatically included in e.g. arrays, gfs, any triqs library... - #include - #include - - void f() { - try { - if (2!=3) TRIQS_RUNTIME_ERROR <<" The condition is false because "<< 2 << "!=" << 3; - } - catch (triqs::runtime_error const & e) { - std::cout << "caught error "<< e.what()< + +int main() { + + try { + if (2 != 3) TRIQS_RUNTIME_ERROR << " The condition is false because " << 2 << "!=" << 3; + } + catch(...) {} + + } + diff --git a/doc/reference/c++/utilities/exceptions_1.cpp b/doc/reference/c++/utilities/exceptions_1.cpp new file mode 100644 index 00000000..2dfb6e27 --- /dev/null +++ b/doc/reference/c++/utilities/exceptions_1.cpp @@ -0,0 +1,15 @@ +// automatically included in e.g. arrays, gfs, any triqs library... +#include +#include + +void f() { + try { + if (2 != 3) TRIQS_RUNTIME_ERROR << " The condition is false because " << 2 << "!=" << 3; + } + catch (triqs::runtime_error const& e) { + std::cout << "caught error " << e.what() << std::endl; + } +} + +int main() { f(); } + diff --git a/doc/reference/c++/utilities/tupletools.rst b/doc/reference/c++/utilities/tupletools.rst index 9a6a45a7..d86a376e 100644 --- a/doc/reference/c++/utilities/tupletools.rst +++ b/doc/reference/c++/utilities/tupletools.rst @@ -29,19 +29,7 @@ apply *Solution* : -.. compileblock:: - - #include - #include - int main() { - - auto fun= [](int i, double x, double y, int k) {return 6*k + i - 1.3*x + 2*y;}; - auto t = std::make_tuple(1,2.3,4.3,8); - - auto res = triqs::tuple::apply(fun,t); - std::cout << " f(t) =" << res << std::endl ; - } - +.. triqs_example:: ./tupletools_0.cpp for_each ------------------------------------------------------------------------- @@ -58,20 +46,4 @@ for_each *Solution* : -.. compileblock:: - - #include - #include - - struct print_t { template void operator()(T x) { std::cout << x << " "; } }; - - int main() { - auto t = std::make_tuple(1,2.3,4.3,8, "hello"); - triqs::tuple::for_each(t, print_t()); - - // C++14 solution : with generic lambda, there is no need to define a print_t ... - // triqs::tuple::for_each(t, [](auto x) { std::cout< +#include +int main() { + + auto fun = [](int i, double x, double y, int k) { return 6 * k + i - 1.3 * x + 2 * y; }; + auto t = std::make_tuple(1, 2.3, 4.3, 8); + + auto res = triqs::tuple::apply(fun, t); + std::cout << " f(t) =" << res << std::endl; +} + diff --git a/doc/reference/c++/utilities/tupletools_1.cpp b/doc/reference/c++/utilities/tupletools_1.cpp new file mode 100644 index 00000000..fe3eb2bb --- /dev/null +++ b/doc/reference/c++/utilities/tupletools_1.cpp @@ -0,0 +1,15 @@ +#include +#include + +struct print_t { + template void operator()(T x) { std::cout << x << " "; } +}; + +int main() { + auto t = std::make_tuple(1, 2.3, 4.3, 8, "hello"); + triqs::tuple::for_each(t, print_t()); + + // C++14 solution : with generic lambda, there is no need to define a print_t ... + // triqs::tuple::for_each(t, [](auto x) { std::cout< - using triqs::arrays::array; - int main(){ - array A(20); - std::cout << "A = "< B; // read the file into B - h5_read (file, "A",B); - std::cout << "B = "< - using triqs::arrays::array; using triqs::arrays::array_view; using triqs::arrays::range; - int main(){ - array A(3,3); A() = 2.5; - std::cout << A < B = A(1,range()); //select the first line of the matrix - std::cout <<"B = "<< B << std::endl; - B(0) = 1; - - std::cout <<"A = "<< A << std::endl; - } - - +.. triqs_example:: ./array_tutorial_3.cpp Matrices and vectors ------------------------- Arrays must be distinguished from vectors and matrices, which have an algebra of their own. -.. compileblock:: - - #include - - using triqs::arrays::array; using triqs::arrays::matrix; using triqs::arrays::vector; - int main(){ - array A(2,2), B(2,2),C; - - A() = 3; B() = 1; C = A*B; - std::cout << "A*B = "<< C << std::endl; - - matrix D(2,2),E(2,2),F; - E() = 3; E() = 1; F = D*E; - std::cout << "C*D = "<< F << std::endl; - - vector u(2),v(2),w; - u()=1;v()=2; w = u+v; - - std::cout <<"u+v = "<< w << std::endl; - } - - - +.. triqs_example:: ./array_tutorial_4.cpp Defining through a lazy expression ----------------------------------- -.. compileblock:: - - #include - using triqs::arrays::array; namespace tql=triqs::clef; - - int main(){ - tql::placeholder<0> i_; tql::placeholder<1> j_; - array A(2,2); - A(i_,j_) << i_ + j_ ; - std::cout << "A = "< - #include - - using triqs::arrays::array; using triqs::arrays::matrix; using triqs::clef::placeholder; - int main(){ - placeholder<0> i_; - placeholder<1> j_; - matrix A(2,2); - A(i_,j_) << i_+j_; - - matrix B = inverse(A); - double C = determinant(A); - - std::cout << "A^(-1) = "<< B << std::endl; - std::cout << "det(A) = " < - #include - using triqs::arrays::array; - - double f(int i) { return i*10;} - - int main() { - auto F = triqs::arrays::map(std::function(f)); - array A(2,2); A() =2; - - array B,C; - - A() =2; - B = F(A); - C = F(2*A); // works also with expressions of course - - std::cout << "A = "< B; // read the file into B + h5_read(file, "A", B); + std::cout << "B = " << B << std::endl; +} + diff --git a/doc/tutorials/c++/array_tutorial_3.cpp b/doc/tutorials/c++/array_tutorial_3.cpp new file mode 100644 index 00000000..89bc6a9d --- /dev/null +++ b/doc/tutorials/c++/array_tutorial_3.cpp @@ -0,0 +1,16 @@ +#include +using triqs::arrays::array; +using triqs::arrays::array_view; +using triqs::arrays::range; +int main() { + array A(3, 3); + A() = 2.5; + std::cout << A << std::endl; + + array_view B = A(1, range()); // select the first line of the matrix + std::cout << "B = " << B << std::endl; + B(0) = 1; + + std::cout << "A = " << A << std::endl; +} + diff --git a/doc/tutorials/c++/array_tutorial_4.cpp b/doc/tutorials/c++/array_tutorial_4.cpp new file mode 100644 index 00000000..3ee3a356 --- /dev/null +++ b/doc/tutorials/c++/array_tutorial_4.cpp @@ -0,0 +1,27 @@ +#include + +using triqs::arrays::array; +using triqs::arrays::matrix; +using triqs::arrays::vector; +int main() { + array A(2, 2), B(2, 2), C; + + A() = 3; + B() = 1; + C = A * B; + std::cout << "A*B = " << C << std::endl; + + matrix D(2, 2), E(2, 2), F; + E() = 3; + E() = 1; + F = D * E; + std::cout << "C*D = " << F << std::endl; + + vector u(2), v(2), w; + u() = 1; + v() = 2; + w = u + v; + + std::cout << "u+v = " << w << std::endl; +} + diff --git a/doc/tutorials/c++/array_tutorial_5.cpp b/doc/tutorials/c++/array_tutorial_5.cpp new file mode 100644 index 00000000..04d92b0f --- /dev/null +++ b/doc/tutorials/c++/array_tutorial_5.cpp @@ -0,0 +1,12 @@ +#include +using triqs::arrays::array; +namespace tql = triqs::clef; + +int main() { + tql::placeholder<0> i_; + tql::placeholder<1> j_; + array A(2, 2); + A(i_, j_) << i_ + j_; + std::cout << "A = " << A << std::endl; +} + diff --git a/doc/tutorials/c++/array_tutorial_6.cpp b/doc/tutorials/c++/array_tutorial_6.cpp new file mode 100644 index 00000000..d1086720 --- /dev/null +++ b/doc/tutorials/c++/array_tutorial_6.cpp @@ -0,0 +1,19 @@ +#include +#include + +using triqs::arrays::array; +using triqs::arrays::matrix; +using triqs::clef::placeholder; +int main() { + placeholder<0> i_; + placeholder<1> j_; + matrix A(2, 2); + A(i_, j_) << i_ + j_; + + matrix B = inverse(A); + double C = determinant(A); + + std::cout << "A^(-1) = " << B << std::endl; + std::cout << "det(A) = " << C << std::endl; +} + diff --git a/doc/tutorials/c++/array_tutorial_7.cpp b/doc/tutorials/c++/array_tutorial_7.cpp new file mode 100644 index 00000000..f28747fe --- /dev/null +++ b/doc/tutorials/c++/array_tutorial_7.cpp @@ -0,0 +1,22 @@ +#include +#include +using triqs::arrays::array; + +double f(int i) { return i * 10; } + +int main() { + auto F = triqs::arrays::map(std::function(f)); + array A(2, 2); + A() = 2; + + array B, C; + + A() = 2; + B = F(A); + C = F(2 * A); // works also with expressions of course + + std::cout << "A = " << A << std::endl; + std::cout << "F(A) = " << B << std::endl; + std::cout << "F(2*A) = " << C << std::endl; +} + diff --git a/doc/tutorials/c++/det_manip_tutorial.rst b/doc/tutorials/c++/det_manip_tutorial.rst index d01b71e1..84579f3f 100644 --- a/doc/tutorials/c++/det_manip_tutorial.rst +++ b/doc/tutorials/c++/det_manip_tutorial.rst @@ -16,212 +16,31 @@ Here are a couple of simple examples showing the basic use of this class. Creation of an empty det_manip class ------------------------------------- -.. compileblock:: - - #include - - struct fun { - - typedef double result_type; - typedef double argument_type; - - //gives the coefficients of the matrix (function F of the documentation) - double operator()(double x, double y) const { - return(x-y); - } - - }; - - int main() { - - fun f; - int init_size = 100; // maximum size of the matrix before a resize - - //creation of a class det_manip - triqs::det_manip::det_manip D(f, init_size); - - //the initial matrix is empty: - std::cout< - - struct fun { - typedef double result_type; - typedef double argument_type; - double operator()(double x, double y) const { return(exp(x)-y*y); } - }; - - int main() { - triqs::det_manip::det_manip D(fun(), std::vector{1,2,2.5}, std::vector{3,4,9}); - std::cout< + +struct fun { + typedef double result_type; + typedef double argument_type; + double operator()(double x, double y) const { return (exp(x) - y * y); } +}; + +int main() { + triqs::det_manip::det_manip D(fun(), std::vector{1, 2, 2.5}, std::vector{3, 4, 9}); + std::cout << std::endl << "After construction, D.matrix()=" << D.matrix() << std::endl << std::endl; + double x0 = 2.1, y0 = 7; + int i = 2, j = 0; // number of the added line and column + std::cout << "We want to add a line and a column for i=" << i << ", j=" << j << ", x=" << x0 << ", y=" << y0 << "." << std::endl; + // (try of) insertion of a line and a column at position (3,1) in the matrix + // with x[i]=x0, y[j]=y0. + double detratio = D.try_insert(i, j, x0, y0); // the ratio between new and old determinants + // while the operation is not complete, the matrix stays unchanged + std::cout << "After try_insert, D.matrix()=" << D.matrix() << std::endl; + // here we validate the insertion: the (inverse) matrix and determinant are updated + D.complete_operation(); + std::cout << "After complete_operation, D.matrix()=" << D.matrix() << std::endl << std::endl; +} + diff --git a/doc/tutorials/c++/det_manip_tutorial_4.cpp b/doc/tutorials/c++/det_manip_tutorial_4.cpp new file mode 100644 index 00000000..74b7da7b --- /dev/null +++ b/doc/tutorials/c++/det_manip_tutorial_4.cpp @@ -0,0 +1,22 @@ +#include + +struct fun { + typedef double result_type; + typedef double argument_type; + double operator()(double x, double y) const { return (exp(x) - y * y); } +}; + +int main() { + triqs::det_manip::det_manip D(fun(), std::vector{1, 2, 2.5}, std::vector{3, 4, 9}); + std::cout << std::endl << "After construction, D.matrix()=" << D.matrix() << std::endl << std::endl; + int i = 1, j = 0; // number of the removed line and column + std::cout << "We want to remove a line and a column for i=" << i << ", j=" << j << "." << std::endl; + // (try of) removal of a line and a column at position (1,0) in the matrix. + double detratio = D.try_remove(i, j); // the ratio between new and old determinants + // while the operation is not complete, the matrix stays unchanged + std::cout << "After try_remove, D.matrix()=" << D.matrix() << std::endl; + // here we validate the removal: the (inverse) matrix and determinant are updated + D.complete_operation(); + std::cout << "After complete_operation, D.matrix()=" << D.matrix() << std::endl << std::endl; +} + diff --git a/doc/tutorials/c++/det_manip_tutorial_5.cpp b/doc/tutorials/c++/det_manip_tutorial_5.cpp new file mode 100644 index 00000000..74e0f5ce --- /dev/null +++ b/doc/tutorials/c++/det_manip_tutorial_5.cpp @@ -0,0 +1,24 @@ +#include + +struct fun { + typedef double result_type; + typedef double argument_type; + double operator()(double x, double y) const { return (exp(x) - y * y); } +}; + +int main() { + triqs::det_manip::det_manip D(fun(), std::vector{1, 2, 2.5}, std::vector{3, 4, 9}); + std::cout << std::endl << "After construction, D.matrix()=" << D.matrix() << std::endl << std::endl; + double x0 = 2.1, y0 = 7, x1 = 3.5, y1 = 5; + int i0 = 2, i1 = 1, j0 = 0, j1 = 3; // number of the added lines and columns + std::cout << "We want to add a line and a column for i0=" << i0 << ", j0=" << j0 << ", i1=" << i1 << ", j1=" << j1 + << ", x0=" << x0 << ", y0=" << y0 << ", x1=" << x1 << ", y1=" << y1 << ")." << std::endl; + // (try of) insertion of 2 lines and 2 columns in the matrix + double detratio = D.try_insert2(i0, i1, j0, j1, x0, x1, y0, y1); // the ratio between new and old determinants + // while the operation is not complete, the matrix stays unchanged + std::cout << "After try_insert2, D.matrix()=" << D.matrix() << std::endl; + // here we validate the insertion: the (inverse) matrix and determinant are updated + D.complete_operation(); + std::cout << "After complete_operation, D.matrix()=" << D.matrix() << std::endl << std::endl; +} + diff --git a/doc/tutorials/c++/det_manip_tutorial_6.cpp b/doc/tutorials/c++/det_manip_tutorial_6.cpp new file mode 100644 index 00000000..e64d1a45 --- /dev/null +++ b/doc/tutorials/c++/det_manip_tutorial_6.cpp @@ -0,0 +1,23 @@ +#include + +struct fun { + typedef double result_type; + typedef double argument_type; + double operator()(double x, double y) const { return (exp(x) - y * y); } +}; + +int main() { + triqs::det_manip::det_manip D(fun(), std::vector{1, 2, 2.5}, std::vector{3, 4, 9}); + std::cout << std::endl << "After construction, D.matrix()=" << D.matrix() << std::endl << std::endl; + int i0 = 2, i1 = 1, j0 = 0, j1 = 1; // number of the removed lines and columns + std::cout << "We want to remove 2 lines and 2 columns for i0=" << i0 << ", j0=" << j0 << ", i1=" << i1 << ", j1=" << j1 << "." + << std::endl; + // (try of) removal of a line and a column at position (1,0) in the matrix. + double detratio = D.try_remove2(i0, i1, j0, j1); // the ratio between new and old determinants + // while the operation is not complete, the matrix stays unchanged + std::cout << "After try_remove2, D.matrix()=" << D.matrix() << std::endl; + // here we validate the removal: the (inverse) matrix and determinant are updated + D.complete_operation(); + std::cout << "After complete_operation, D.matrix()=" << D.matrix() << std::endl << std::endl; +} + diff --git a/doc/tutorials/c++/gfs_tutorial.rst b/doc/tutorials/c++/gfs_tutorial.rst index 75ad703b..c0472ad7 100644 --- a/doc/tutorials/c++/gfs_tutorial.rst +++ b/doc/tutorials/c++/gfs_tutorial.rst @@ -16,114 +16,31 @@ Creation of a real time GF Here we create a GF define on the time interval from tmin to tmax. If we want the value of the GF at any time to be a scalar, we use: -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double tmin=0, tmax=10; // the time interval - int n_times=100; // we will have 100 points - auto g = gf{ {tmin, tmax, n_times}}; - } - +.. triqs_example:: ./gfs_tutorial_0.cpp If we need a matrix of size n by m, we use: -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double tmin = 0, tmax = 10; // the time interval - const int n=2, m=2, n_times = 100; // we will have 100 points - auto g = gf{ {tmin, tmax, n_times} , {n, m} }; - } - +.. triqs_example:: ./gfs_tutorial_1.cpp Or a tensor ! -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double tmin = 0, tmax = 10; // the time interval - double beta=1; - int n_times = 100; // we will have 100 pointspoints - auto g =gf, tensor_valued<3>>{ - { {tmin, tmax, n_times}, {beta, Fermion, n_times} }, {2,2,2}}; - } - - +.. triqs_example:: ./gfs_tutorial_2.cpp Creation of other simple GF's ------------------------------- -.. compileblock:: - - #include - using namespace triqs::gfs; - - int main() { - double beta=10; // the time interval - int n_times=100; // we will have 100 - auto g = gf{ {beta, Fermion, n_times}}; - } - +.. triqs_example:: ./gfs_tutorial_3.cpp Creation of a two real time GF -------------------------------- -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double tmin = 0, tmax = 1.0; - int nt = 100; - auto g = gf< cartesian_product,scalar_valued>{{{tmin,tmax,nt},{tmin,tmax,nt}}}; - } - - +.. triqs_example:: ./gfs_tutorial_4.cpp How to fill a GF with placeholders ----------------------------------- -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double tmin = 0, tmax = 1.0; - int nt = 100; - auto g = gf< cartesian_product,scalar_valued>{{{tmin,tmax,nt},{tmin,tmax,nt}}}; - triqs::clef::placeholder<0> t1_; - triqs::clef::placeholder<1> t2_; - g( t1_, t2_) << 2*t1_; - } - - +.. triqs_example:: ./gfs_tutorial_5.cpp How to interpolate the GF value at a point of the domain --------------------------------------------------------- You simply have to call the GF with the coordinates of the point: -.. compileblock:: - - #include - using namespace triqs::gfs; - int main(){ - double tmin = 0, tmax = 1.0; - int nt = 100; - auto g = gf< cartesian_product, scalar_valued >{ - { {tmin, tmax, nt}, {tmin, tmax, nt} } }; - triqs::clef::placeholder<0> t1_; - triqs::clef::placeholder<1> t2_; - g( t1_, t2_) << 2.*t1_; - std::cout << g(0.24, 0.36) << std::endl; - } - - - - +.. triqs_example:: ./gfs_tutorial_6.cpp Learn more in the full reference, see :ref:`gf` diff --git a/doc/tutorials/c++/gfs_tutorial_0.cpp b/doc/tutorials/c++/gfs_tutorial_0.cpp new file mode 100644 index 00000000..f79d1ba0 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_0.cpp @@ -0,0 +1,9 @@ +#include +using namespace triqs::gfs; + +int main() { + double tmin = 0, tmax = 10; // the time interval + int n_times = 100; // we will have 100 points + auto g = gf{{tmin, tmax, n_times}}; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_1.cpp b/doc/tutorials/c++/gfs_tutorial_1.cpp new file mode 100644 index 00000000..3bf1223c --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_1.cpp @@ -0,0 +1,9 @@ +#include +using namespace triqs::gfs; + +int main() { + double tmin = 0, tmax = 10; // the time interval + const int n = 2, m = 2, n_times = 100; // we will have 100 points + auto g = gf{{tmin, tmax, n_times}, {n, m}}; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_2.cpp b/doc/tutorials/c++/gfs_tutorial_2.cpp new file mode 100644 index 00000000..1b5da550 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_2.cpp @@ -0,0 +1,10 @@ +#include +using namespace triqs::gfs; + +int main() { + double tmin = 0, tmax = 10; // the time interval + double beta = 1; + int n_times = 100; // we will have 100 pointspoints + auto g = gf, tensor_valued<3>>{{{tmin, tmax, n_times}, {beta, Fermion, n_times}}, {2, 2, 2}}; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_3.cpp b/doc/tutorials/c++/gfs_tutorial_3.cpp new file mode 100644 index 00000000..b94cdc66 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_3.cpp @@ -0,0 +1,9 @@ +#include +using namespace triqs::gfs; + +int main() { + double beta = 10; // the time interval + int n_times = 100; // we will have 100 + auto g = gf{{beta, Fermion, n_times}}; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_4.cpp b/doc/tutorials/c++/gfs_tutorial_4.cpp new file mode 100644 index 00000000..fe0b3ee9 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_4.cpp @@ -0,0 +1,8 @@ +#include +using namespace triqs::gfs; +int main() { + double tmin = 0, tmax = 1.0; + int nt = 100; + auto g = gf, scalar_valued>{{{tmin, tmax, nt}, {tmin, tmax, nt}}}; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_5.cpp b/doc/tutorials/c++/gfs_tutorial_5.cpp new file mode 100644 index 00000000..bcc47827 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_5.cpp @@ -0,0 +1,11 @@ +#include +using namespace triqs::gfs; +int main() { + double tmin = 0, tmax = 1.0; + int nt = 100; + auto g = gf, scalar_valued>{{{tmin, tmax, nt}, {tmin, tmax, nt}}}; + triqs::clef::placeholder<0> t1_; + triqs::clef::placeholder<1> t2_; + g(t1_, t2_) << 2 * t1_; +} + diff --git a/doc/tutorials/c++/gfs_tutorial_6.cpp b/doc/tutorials/c++/gfs_tutorial_6.cpp new file mode 100644 index 00000000..71560760 --- /dev/null +++ b/doc/tutorials/c++/gfs_tutorial_6.cpp @@ -0,0 +1,12 @@ +#include +using namespace triqs::gfs; +int main() { + double tmin = 0, tmax = 1.0; + int nt = 100; + auto g = gf, scalar_valued>{{{tmin, tmax, nt}, {tmin, tmax, nt}}}; + triqs::clef::placeholder<0> t1_; + triqs::clef::placeholder<1> t2_; + g(t1_, t2_) << 2. * t1_; + std::cout << g(0.24, 0.36) << std::endl; +} + diff --git a/foreignlibs/autocompile/autocompile.py b/foreignlibs/autocompile/autocompile.py deleted file mode 100644 index 83c671f9..00000000 --- a/foreignlibs/autocompile/autocompile.py +++ /dev/null @@ -1,112 +0,0 @@ -import tempfile -# -*- coding: utf-8 -*- -# seems to be executed at the level of the conf.py -# so we need to link the lib at that place... -""" -""" -import os -from subprocess import Popen,PIPE - -from docutils import nodes -from sphinx.util.compat import Directive -from docutils.parsers.rst import directives -from sphinx.errors import SphinxError - -class CompileBlockError(SphinxError): - category = 'compileblock error' - -class AutoCompile(object): - #here = os.path.abspath(__file__) - #pycon = os.path.join(os.path.dirname(here),'pycon.py') - config = dict( - #pycon = 'python ' + pycon, - #pycon_prefix_chars = 4, - #pycon_show_source = False, - #console = 'bash', - #console_prefix_chars = 1 , - compiler = "clang++", - link = "", - include = "", - definitions = "", - ld_library_path = "", - ) - @classmethod - def builder_init(cls,app): - #cls.config.update(app.builder.config.autorun_languages) - cls.config.update(app.builder.config.autocompile_opts) - -class CompileBlock(Directive): - has_content = True - required_arguments = 0 - optional_arguments = 1 - final_argument_whitespace = False - option_spec = { - 'linenos': directives.flag, - } - - def run(self): - config = AutoCompile.config - - # Get configuration values for the language - input_encoding = 'ascii' #config.get(language+'_input_encoding','ascii') - output_encoding = 'ascii' #config.get(language+'_output_encoding','ascii') - show_source = True - - # Build the code text - code = u'\n'.join(self.content).encode(input_encoding) - - # write the temp file for compilation - fil = tempfile.NamedTemporaryFile(suffix='.cpp') - fil.write(code) - fil.flush() - - args = "%(compiler)s "%config + fil.name + " %(definitions)s %(include)s %(link)s"%config - print "Compiling ...." - #print args - import subprocess as S - error = True - try : - stdout = S.check_output(args,stderr=S.STDOUT,shell=True) - try : - resout = S.check_output(" ./a.out"%config ,stderr=S.STDOUT,shell=True) - #resout = S.check_output("LD_LIBRARY_PATH=$LD_LIBRAY_PATH:%(ld_library_path)s && ./a.out"%config ,stderr=S.STDOUT,shell=True) - if resout : - stdout +='---------- Result is -------\n' + resout - error = False - except S.CalledProcessError as E : - stdout ='---------- RunTime error -------\n' - stdout += E.output - except S.CalledProcessError as E : - stdout ='---------- Compilation error -------\n' - stdout += E.output - print "... done" - - # Process output - if stdout: - stdout = stdout.decode(output_encoding,'ignore') - out = u''.join(stdout).decode(output_encoding) - else: - out = '' #.join(stderr).decode(output_encoding) - - # Get the original code with prefixes - if show_source: - code = u'\n'.join(self.content) - else: - code = '' - code_out = u'\n'.join((code,out)) - - if error : # report on console - print " Error in processing " - print code_out - - literal = nodes.literal_block(code_out,code_out) - literal['language'] = 'c' - literal['linenos'] = 'linenos' in self.options - return [literal] - -def setup(app): - app.add_directive('compileblock', CompileBlock) - app.connect('builder-inited',AutoCompile.builder_init) - #app.add_config_value('autorun_languages', AutoRun.config, 'env') - app.add_config_value('autocompile_opts', AutoCompile.config, 'env') - diff --git a/foreignlibs/autocompile/autorun.py b/foreignlibs/autorun/autorun.py similarity index 100% rename from foreignlibs/autocompile/autorun.py rename to foreignlibs/autorun/autorun.py diff --git a/foreignlibs/autocompile/pycon.py b/foreignlibs/autorun/pycon.py similarity index 100% rename from foreignlibs/autocompile/pycon.py rename to foreignlibs/autorun/pycon.py diff --git a/foreignlibs/triqs_example/triqs_example.py b/foreignlibs/triqs_example/triqs_example.py new file mode 100644 index 00000000..0015c852 --- /dev/null +++ b/foreignlibs/triqs_example/triqs_example.py @@ -0,0 +1,121 @@ +import tempfile +# -*- coding: utf-8 -*- +# seems to be executed at the level of the conf.py +# so we need to link the lib at that place... +""" +""" +import os +import codecs +from os import path +from subprocess import Popen,PIPE +from docutils import nodes +from sphinx.util.compat import Directive +from docutils.parsers.rst import directives +from sphinx.errors import SphinxError + +class TriqsExampleError(SphinxError): + category = 'triqs_example error' + +class TriqsExampleRun(object): + #here = os.path.abspath(__file__) + #pycon = os.path.join(os.path.dirname(here),'pycon.py') + config = dict( + ) + @classmethod + def builder_init(cls,app): + #cls.config.update(app.builder.config.autorun_languages) + #cls.config.update(app.builder.config.autocompile_opts) + pass + +class TriqsExample(Directive): + has_content = True + required_arguments = 1 + optional_arguments = 0 + final_argument_whitespace = False + option_spec = { + 'linenos': directives.flag, + } + + def run(self): + document = self.state.document + filename = self.arguments[0] + if not document.settings.file_insertion_enabled: + return [document.reporter.warning('File insertion disabled', + line=self.lineno)] + env = document.settings.env + if filename.startswith('/') or filename.startswith(os.sep): + rel_fn = filename[1:] + else: + docdir = path.dirname(env.doc2path(env.docname, base=None)) + rel_fn = path.normpath(path.join(docdir, filename)) + try: + fn = path.join(env.srcdir, rel_fn) + except UnicodeDecodeError: + # the source directory is a bytestring with non-ASCII characters; + # let's try to encode the rel_fn in the file system encoding + rel_fn = rel_fn.encode(sys.getfilesystemencoding()) + fn = path.join(env.srcdir, rel_fn) + + encoding = self.options.get('encoding', env.config.source_encoding) + try: + f = codecs.open(fn, 'rU', encoding) + lines = f.readlines() + f.close() + except (IOError, OSError): + return [document.reporter.warning( + 'Include file %r not found or reading it failed' % filename, + line=self.lineno)] + except UnicodeError: + return [document.reporter.warning( + 'Encoding %r used for reading included file %r seems to ' + 'be wrong, try giving an :encoding: option' % + (encoding, filename))] + + config = TriqsExampleRun.config + + # Get configuration values for the language + input_encoding = 'ascii' #config.get(language+'_input_encoding','ascii') + output_encoding = 'ascii' #config.get(language+'_output_encoding','ascii') + show_source = True + + # Build the code text + code = u''.join(lines).strip() + filename_clean = filename.rsplit('.',1)[0] + if filename_clean.startswith('./') : filename_clean = filename_clean[2:] + #print "Running the example ....",filename_clean + + import subprocess as S + error = True + try : + stdout ='' + resout = S.check_output("./%s/doc_%s"%(docdir,filename_clean) ,stderr=S.STDOUT,shell=True) + if resout : + stdout = '---------- Result is -------\n' + resout.strip() + error = False + except S.CalledProcessError as E : + stdout ='---------- RunTime error -------\n' + stdout += E.output + + # Process output + if stdout: + stdout = stdout.decode(output_encoding,'ignore') + out = u''.join(stdout).decode(output_encoding) + else: + out = '' #.join(stderr).decode(output_encoding) + + # Get the original code with prefixes + code_out = u'\n'.join((code,out)) + + if error : # report on console + print " Error in processing " + print code_out + + literal = nodes.literal_block(code_out,code_out) + literal['language'] = 'c' + literal['linenos'] = 'linenos' in self.options + return [literal] + +def setup(app): + app.add_directive('triqs_example', TriqsExample) + app.connect('builder-inited',TriqsExampleRun.builder_init) + diff --git a/pytriqs/wrap_generator/__init__.py b/pytriqs/wrap_generator/__init__.py new file mode 100644 index 00000000..fe16459e --- /dev/null +++ b/pytriqs/wrap_generator/__init__.py @@ -0,0 +1,2 @@ +__all__ = [] +